Latest 2.1
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"

Swift Package Manager

Once you have your Swift package set up, adding LightRoute as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .Package(url: "https://github.com/SpectralDragon/LightRoute.git", majorVersion: 2)
]

Example

About LightRoute

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

For all transition, returns TransitionNode instance, who managed current transition. You can change transition flow, how you want.

How to use

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) {

      try? 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..
  }

}

In this case, you make default transition between viewControllers and configure moduleInput how you want.
But also, you can use just viewController, example:

.forCurrentStoryboard(resterationId: viewControllerIdentifier, to: SecondViperPresenter.self)
/// and etc..

Note❗️
moduleInput – by default that property contain your output property in destination view controller. You can change that use methods selector:.
You can use next for get custom moduleInput:

  • by string: selector(_ selector: String)
  • by selector: selector(_ selector: Selector)
  • by keyPath: selector(_ selector: KeyPath)

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:


try? 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 CustomTransitionNode. This node not support default TransitionNode methods.
CustomTransitionNode 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 perform() method for activate transition.

Example:


try? transitionHandler

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

// Activate custom transition.
.customTransition()

// Custom transition case.
.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 animate your current transition.

.transition(animate: false)

Change presentation

Method to(preffered:), have responsobility for change presentation style. He work with UINavigationController, UISplitViewController and default presentation.

.to(preferred: TransitionStyle)

Configure you destination controller

Sometimes you need add additional dependency in your controller. For this case, will be add method apply(to:). That method return destination controller and you can configurate him.


try? transitionHandler
  .forSegue(identifier: "LightRouteSegue", to: SecondViperViewControllerModuleInput.self)
  .apply(to: { controller in
    // configure your controller.
  })
  .then { moduleInput in
    // configure your module
  }

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)

  try? 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 `.perform()`
}

Transition for Segue

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


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

Close current module

If you want initiate close current module, you should be use:

.closeCurrentModule(animated: Bool)

And after this you can use perform() method for initiate close method.

Custom close style

If you wanna close pop controller or use popToRoot controller, you must perform method preferred(style:).
That method have different styles for your close transition.

If you need call popToViewController(:animated) for your custom controller, you must perform method find(pop:).

try? transitionHandler
  .closeCurrentModule(animated: true)
  .find(pop: { controller -> Bool
    return controller is MyCustomController
  })
  .preferred(style: .navigationController(style: .findedPop))
  .perform()

Support UIViewControllerTransitioningDelegate

LightRoute 2.0 start support UIViewControllerTransitioningDelegate for your transition. We can work with that use next methods:

.add(transitioningDelegate: UIViewControllerTransitioningDelegate)

Note

Thanks for watching.

Latest podspec

{
    "name": "LightRoute",
    "version": "2.1",
    "summary": "LightRoute is easy transition between view controllers and support many popylar arhitectures",
    "description": "LightRoute is easy transition between view controllers and support many popylar arhitectures. This framework very flow for settings your transition and have userfriendly API.",
    "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": "2.1",
        "submodules": false
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": [
        "LightRoute/*.swift",
        "LightRoute/TransitionNodes/*.swift",
        "LightRoute/Protocols/*.swift"
    ],
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This