Latest 1.0.6
Homepage https://github.com/SpectralDragon/LightRoute
License MIT
Platforms ios 8.0
Authors

Pod version
Platform
License
Swift

Description

LightRoute is easy transition between VIPER modules, who implemented on pure Swift.
We can transition between your modules very easy from couple lines of codes.

Install

CocoaPods

Add to your podfile:

pod "LightRoute"

Example

For example, we will make the transition between the two VIPER modules:

import LightRoute

// MARK: - The module initiating the transition.

protocol FirstViperRouterInput: class {
  func openModule(userIdentifier: String)
}

final class FirstViperRouter: FirstViperRouterInput {

  // This property contain protocol protected view controller for transition.
  weak var transitionHandler: TransitionHandler!

  // View controller identifier for current storyboard.
  let viewControllerIdentifier = "SecondViperViewController"

  func openModule(userIdentifier: String) {

      transitionHandler

      // Initiates the opening of a new view controller.
      .forCurrentStoryboard(resterationId: viewControllerIdentifier, to: SecondViperViewControllerModuleInput.self)

      // Set animate for transition.
      .transition(animate: false)

      // Set transition case.
      .to(preffered: TransitionStyle.navigationController(prefferedStyle: .push))

      // View controller init block. 
      .then { moduleInput in 
        moduleInput.configure(with: userIdentifier)
      }
  }
} 

// MARK: - The module at which the jump occurs.

// Module input protocol for initialize
protocol SecondViperViewControllerModuleInput: class {
  func configure(with userIdentifier: String)
}

final class SecondViperPresenter: SecondViperViewControllerModuleInput, ... {

  // Implementation protocol
  func configure(with userIdentifier: String) {
        print("User identifier", userIdentifier) // Print it!
    // Initialize code..
  }

}

About this

LightRoute can work with Segue, UINavigationController and default view controller presenting.

For all transition, returns main TransitionPromise class, who managed current transition. You can change transition flow, how you want.

Transition case

For example we analyze this code, then contain two case for work with transition:

First case:

This default case, with default LightRoute implementation. If you want just present new module, then use that:


transitionHandler

// Initiates the opening of a new view controller.
.forCurrentStoryboard(resterationId: viewControllerIdentifier, to: SecondViperViewControllerModuleInput.self)

// Setup module input.
.then { moduleInput in 
  moduleInput.configure(with: "Hello!")
}

Second case:

But first way can’t be flexible, for that has customTransition() method. This method returns CustomTransitionPromise, who can’t be changed with TransitionPromise ways.
CustomTransitionPromise is class, who return method flexible settings your transition, but for this transition flow, you should be implement your transition logic, and call them(_:) or push() method for activate transition.

Example:


transitionHandler

// Initiates the opening of a new view controller.
.forCurrentStoryboard(resterationId: viewControllerIdentifier, to: SecondViperViewControllerModuleInput.self)

// Activate custom transition.
.customTransition()

// Custom transition case.
// REMEBER, that flow is protected and can't be changed :)
.transition { source, destination in 
  // Implement here your transition logic, like that:
    // source.present(destination, animated: true, completion: nil)
}

// Setup module input.
.then { moduleInput in 
  moduleInput.configure(with: "Hello custom transition!")
}

Customize transition

For customize your transition you can change transition presentation and set animation.

Animate transition

This methods can animete your current transition, if transition flow not protected.

transition(animate: false)

Change presentation

For this there is method to(preffered:), who can change presentation style. He work with UINavigationController and default presentation.

to(preferred: TransitionStyle)

Transition on new storyboard

Also LightRoute can transition on new storyboard instance like this:


// We remeber this class :)
func openModule(userIdentifier: String) {

  let storyboard = UIStoryboard(name: "NewStoryboard", bundle: Bundle.main)
  let factory = StoryboardFactory(storyboard: storyboard)

  transitionHandler

  // Initiates the opening of a new view controller from custom `UIStoryboard`.
  .forStoryboard(factory: factory, to: SecondViperViewControllerModuleInput.self)

    // Set animate for transition.
  .transition(animate: false)

  // View controller init block. 
  .then { moduleInput in 
    moduleInput.configure(with: userIdentifier)
  } // If you don't want initialize view controller, we should be use `.push()`
}

Transition for Segue

And finish, you can initiate transition from UIStoryboardSegue like this:


func openModule(userIdentifier: String) {
  transitionHandler
     // Performs transition from segue and cast to need type
    .forSegue(identifier: "LightRouteSegue", to: SecondViperViewControllerModuleInput.self) { moduleInput in 
      moduleInput.setup(text: "Segue transition!") 
    }
}

But, for this case, you can’t change transition flow.

Note

  • Mastermind: ViperMcFlurry
  • License: MIT
  • Author: Vladislav Prusakov / [email protected]

Thanks for watching.

Latest podspec

{
    "name": "LightRoute",
    "version": "1.0.6",
    "summary": "LightRoute is easy transition between VIPER modules and not only. Written in Swift 3",
    "description": "LightRoute is easy transition between VIPER modules and not only. Written in Swift 3.",
    "homepage": "https://github.com/SpectralDragon/LightRoute",
    "documentation_url": "https://github.com/SpectralDragon/LightRoute",
    "license": "MIT",
    "authors": {
        "Vladislav Prusakov": "[email protected]"
    },
    "source": {
        "git": "https://github.com/SpectralDragon/LightRoute.git",
        "tag": "1.0.6",
        "submodules": false
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "LightRoute/*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This