Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pjechris/magellan
Routing dead simple
https://github.com/pjechris/magellan
navigation route router routing swift viewcontroller
Last synced: 2 months ago
JSON representation
Routing dead simple
- Host: GitHub
- URL: https://github.com/pjechris/magellan
- Owner: pjechris
- License: mit
- Created: 2014-12-30T14:52:00.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-12-18T15:48:30.000Z (about 6 years ago)
- Last Synced: 2024-10-05T14:04:24.549Z (3 months ago)
- Topics: navigation, route, router, routing, swift, viewcontroller
- Language: Swift
- Homepage:
- Size: 140 KB
- Stars: 15
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Magellan
[![Build Status](https://travis-ci.org/akane/Gaikan.svg?branch=travis)](https://travis-ci.org/akane/Nabigeta)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
```swift
enum AppRoutes {
case book(Book)
case cart(Cart)
}
```### 2 - Declare your route handler
```swift
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
```swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var navigation: Navigation! = nilfunc application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
navigation = Navigation(router: route(for::))
}
}
```### 4 - Use it!
```swift
class ViewController {
var cart: Cart!func onCartTapped() {
navigate(to: .cart(cart))
}
}
```# Advanced Usage
## PresentationMagellan provides some default Presentation strategies:
- PresentationPush
- PresentationModal
- PresentationPopover
- PresentationSegueIf 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 backYou can cancel navigation from source controller:
```swift
bookViewController.navigateBack() // come back to BookViewController
```
You can also stop navigation from destination controller:```swift
cartViewController.navigationTerminated(status: .canceled) // dismiss CartViewController
```You can also be notified when navigations are stopped:
```swift
viewController
.navigate(to: .cart(self.cart))
.onTerminate { status in
if status == .canceled {
print("author controller cancelled")
}
}
```