ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - SpectralDragon/LiteRoute: LiteRoute is easy transition for your app. Written on Swift 4
LiteRoute is easy transition for your app. Written on Swift 4 - SpectralDragon/LiteRoute
Visit Site

GitHub - SpectralDragon/LiteRoute: LiteRoute is easy transition for your app. Written on Swift 4

GitHub - SpectralDragon/LiteRoute: LiteRoute is easy transition for your app. Written on Swift 4

LiteRoute

Build Status Pod version Carthage compatible Platform License Twitter Swift

Description

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

What's happend with LightRoute?

Because CocoaPods Dev Team doesn't respond me about return right to my lib, I will move LightRoute to other name LiteRoute. Code and all rights saved.

Installation

CocoaPods

Add to your podfile:

pod "LiteRoute"

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate LiteRoute into your Xcode project using Carthage, specify it in your Cartfile:

github "SpectralDragon/LiteRoute" ~> 2.1

Run carthage update to build the framework and drag the built LiteRoute.framework into your Xcode project.

Swift Package Manager

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

Swift 4

dependencies: [
    .package(url: "https://github.com/SpectralDragon/LiteRoute.git", from: "2.1")
]

Example

About LiteRoute

LiteRoute 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 LiteRoute

// 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.navigation(style: .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 LiteRoute 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, ModalPresentation and default presentation.

.to(preferred: TransitionStyle)

📌Supported styles:

  • Navigation style (push, pop, present)
    .to(preferred: .navigation(style: NavigationStyle))
    
  • Split style (detail, default)
    .to(preferred: .split(style: SplitStyle))
    
  • Modal style (UIModalTransitionStyle, UIModalPresentationStyle - standart UIKit's presentations styles.)
    .to(preferred: .modal(style: style: (transition: UIModalTransitionStyle, presentation: UIModalPresentationStyle)))
    

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: "LiteRouteSegue", to: SecondViperViewControllerModuleInput.self)
  .apply(to: { controller in
    // configure your controller.
  })
  .then { moduleInput in
    // configure your module
  }
  

Transition on new storyboard

Also LiteRoute 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

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: "LiteRouteSegue", to: SecondViperViewControllerModuleInput.self)
       .then { moduleInput in
        moduleInput.setup(text: "Segue transition!")
      }
}

If you want to use EmbedSegue, need to add segue in storyboard, set class EmbedSegue and source view controller must conform protocol ViewContainerForEmbedSegue like this:


extension SourceViewController: ViewContainerForEmbedSegue {
    func containerViewForSegue(_ identifier: String) -> UIView {
        return embedView
    }
}

And you can initiate EmbedSegue transition like this:


func addEmbedModule() {
  try? transitionHandler
       .forSegue(identifier: "LiteRouteEmbedSegue", to: EmbedModuleInput.self)
       .perform()
}

Close current module

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

.closeCurrentModule()

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

Animate close transition

This methods can animate your current transition.

.transition(animate: false)

Note: Default true

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()
  .find(pop: { controller -> Bool
    return controller is MyCustomController
  })
  .preferred(style: .navigation(style: .findedPop))
  .perform()

Support UIViewControllerTransitioningDelegate

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

.add(transitioningDelegate: UIViewControllerTransitioningDelegate)

Note

Thanks for watching.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory