Giter VIP home page Giter VIP logo

magellan's Introduction

Magellan

Build Status

Nabigeta provides simple API to declare routes for navigation. Compatible with trait environments.

Why

Classic app navigation tights View Controllers together, making hard to change workflow when needed.

Magellan helps you by defining a simple routing system abstracting View Controllers usage, making it easier to introduce changes, deep linking, tagging, and so on...

Usage

1 - Declare an enum with your routes

enum AppRoutes {
  case book(Book)
  case cart(Cart)
}

2 - Declare your route handler

func route(for context: AppRoutes, _ sender: UIViewController?) -> Route? {
  switch context {
  case .book(let book):
    return Route(BookViewController())
  case .cart(let cart):
    return Route(CartViewController()).present(PresentationModal())
  }
}

3 - Create your navigation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  var navigation: Navigation! = nil

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    navigation = Navigation(router: route(for::))
  }
}

4 - Use it!

class ViewController {
  var cart: Cart!

  func onCartTapped() {
      navigate(to: .cart(cart))
  }
}

Advanced Usage

Presentation

Magellan provides some default Presentation strategies:

  • PresentationPush
  • PresentationModal
  • PresentationPopover
  • PresentationSegue

If none of them feed your needs, you can provide your own custom presentation just by creating a class/struct implementing the PresentationStrategy protocol.

Stopping navigation

Navigate back

You can cancel navigation from source controller:

  bookViewController.navigateBack() // come back to BookViewController

You can also stop navigation from destination controller:

  cartViewController.navigationTerminated(status: .canceled) // dismiss CartViewController

You can also be notified when navigations are stopped:

  viewController
    .navigate(to: .cart(self.cart))
    .onTerminate { status in
      if status == .canceled {
        print("author controller cancelled")
      }
    }

magellan's People

Contributors

natanrolnik avatar nicien avatar pjechris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.