All Projects → SpectralDragon → Literoute

SpectralDragon / Literoute

Licence: mit
LiteRoute is easy transition for your app. Written on Swift 4

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Literoute

Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (+210%)
Mutual labels:  easy-to-use, router, routing
Url Mapper
Take a URL and map to functions, parsing params
Stars: ✭ 39 (-56.67%)
Mutual labels:  router, routing
React Router Component
Declarative router component for React.
Stars: ✭ 879 (+876.67%)
Mutual labels:  router, routing
Dragon
⚡A powerful HTTP router and URL matcher for building Deno web servers.
Stars: ✭ 56 (-37.78%)
Mutual labels:  framework, router
Taniwhatextfield
My first cocoapod framework
Stars: ✭ 26 (-71.11%)
Mutual labels:  framework, swift-framework
Bidi
Bidirectional URI routing
Stars: ✭ 941 (+945.56%)
Mutual labels:  router, routing
Pnet
High level Java network library
Stars: ✭ 49 (-45.56%)
Mutual labels:  framework, easy-to-use
Micro Router
🚉 A tiny and functional router for Zeit's Micro
Stars: ✭ 621 (+590%)
Mutual labels:  router, routing
Keyboardhidemanager
Codeless manager to hide keyboard by tapping on views for iOS written in Swift
Stars: ✭ 57 (-36.67%)
Mutual labels:  framework, swift-framework
Easygameframeworkopen
基于Typescript的渐进式通用游戏前端开发框架
Stars: ✭ 65 (-27.78%)
Mutual labels:  framework, easy-to-use
Corenavigation
📱📲 Navigate between view controllers with ease. 💫 🔜 More stable version (written in Swift 5) coming soon.
Stars: ✭ 69 (-23.33%)
Mutual labels:  router, routing
Storeon Async Router
Asynchronous router for Storeon. It provides possibility for prefetch the data, lazy load, navigation cancellation, and routes modification on the fly.
Stars: ✭ 22 (-75.56%)
Mutual labels:  router, routing
One
一个极简高性能php框架,支持[swoole | php-fpm ]环境
Stars: ✭ 789 (+776.67%)
Mutual labels:  framework, router
Routing
The Routing component maps an HTTP request to a set of configuration variables.
Stars: ✭ 7,080 (+7766.67%)
Mutual labels:  router, routing
Awesome Nextjs
📔 📚 A curated list of awesome resources : books, videos, articles about using Next.js (A minimalistic framework for universal server-rendered React applications)
Stars: ✭ 6,812 (+7468.89%)
Mutual labels:  framework, routing
Restify Router
A router interface for restify that lets you aggregate route definitions and apply to a restify server
Stars: ✭ 45 (-50%)
Mutual labels:  router, routing
Python Lambdarest
Flask like web framework for AWS Lambda
Stars: ✭ 84 (-6.67%)
Mutual labels:  framework, routing
Gearbox
Gearbox ⚙️ is a web framework written in Go with a focus on high performance
Stars: ✭ 455 (+405.56%)
Mutual labels:  framework, router
Gear
A lightweight, composable and high performance web service framework for Go.
Stars: ✭ 544 (+504.44%)
Mutual labels:  framework, router
Apprun
AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.
Stars: ✭ 1,087 (+1107.78%)
Mutual labels:  framework, router

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].