Giter Site home page Giter Site logo

lepaya-coordinator's Introduction

Lepaya-Coordinator

Useful pod to implement the Coordinator design pattern with ease. If your app is a tabbed one, you can start with this few lines:

    self.window = UIWindow(frame: UIScreen.main.bounds)
        
    let appCoordinator = TabCoordinator(window: self.window!)
    appCoordinator.setup(tabNames: ["first", "second"],
                            tabImages: ["tab_image_01", "tab_image_02"]) { () -> ([NCCoordinator]) in
                            
                            let firstTab = NCCoordinator(rootController: RedController())
                            
                            let secondTab = NCCoordinator(rootController: GreenController())
                            
                            return [firstTab, secondTab]
                            
    }
    appCoordinator.firstTabToLoad = 1 // select which tab will be visible at launch
    appCoordinator.start()

If you prefer simple navigation:

    let appCoordinator = NCCoordinator(rootController: RedController())
    appCoordinator.start(window: self.window!)

To push a new Controller:

    guard let navigation = self.navigationController else { return } 
    let green = GreenController()
    let coordinator = VCCoordinator(push: green, presenter: navigation)
    green.coordinator = coordinator
    coordinator.start()

To present a new one modally from a controller:

    guard let navigation = self.navigationController else { return }
    let green = GreenController()
    green.loadButtonBack()
    let coordinator = VCCoordinator(presentModally: green, navigation: navigation, presenter: self)
    green.coordinator = coordinator
    coordinator.start()
 

Stop wondering if you have to dismiss or pop a controller to go back, use the extension method of EUIViewController:

self.goBack()

NOTE: CoordinatorPackage uses a subclass of UIViewController named ExtendedViewController that expands the class with some basic functionality:

  • isModal to immediately know if the controller you are working on is presented modally or not.
  • coordinator the VCCoordinator, used to go back to the previous controller.
  • setTabBarControllerDelegate() to set the controller as UITabBarControllerDelegate to be able to load and re-load (only if it is visible) the rootViewcontroller of each tab.

The whole app will be managed by CoordinatorSession.shared, that holds a reference to TabCoordinator or NCCoordinator. To perform custom action on tab selection you can use TabCoordinatorDelegate:

CoordinatorSession.shared.tabCoordinator?.delegate = self

and then implement the method:

func reloadRootController(_ controller: EUIViewController, atIndex index: Int)

To install using cocoapods:

pod 'Lepaya-Coordinator'

Or just download/clone the repo and drag to your project the content of the 'Sources' folder.

lepaya-coordinator's People

Contributors

tokta avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.