Skip to content

Declarative URL- and state-based router written in Swift.

License

Notifications You must be signed in to change notification settings

nikans/MonarchRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MonarchRouter

CI Status Version License Platform

Monarch Router

A lightweight yet powerful state-based router written in Swift.

Monarch Router is a declarative routing handler that decouples ViewControllers from each other via Coordinator and Presenters. Monarch Router fits right in with Redux style State Flow and Reactive frameworks.

The Coordinator is constructed by declaring a route hierarchy mapped with a URL structure. Presenters abstract UI creation and modification.

Monarch butterflies weight less than 1 gram but cover thousands of miles during their migration. It's considered an iconic pollinator and one of the most beautiful butterfly species.

Features

  • Navigating complex ViewControlles hierarchy and unwinding on path change.
  • Switching top-level app sections via setting the window's rootViewController.
  • Navigating forks (tab bar like presenters).
  • Navigating stacks (i.e. navigation controller).
  • Opening and dismissing modals.
  • Passing and parsing route parameters to endpoints.
  • Handling navigation in universal apps. (PRs welcome!)
  • Properly abstracting Router layer to handle navigation in macOS apps.

Installation

MonarchRouter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MonarchRouter'

You may find the last release version here.

Requirements

Currently only iOS/iPhone 8.0+ is properly supported, but theoretically it's easyly extended to support Universal apps. MacOS support requires a new layer of abstraction with generics and stuff, and I think that it's clearer to use as it is for now. But you are very welcome to contribute!

  • iOS/iPhone
  • iOS/Universal
  • macOS

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

How to use

TODO

See Example App, it's pretty well documented.

Glossary

TODO

Principle concepts

UI is a representation of State

As the State changes over time, so will the UI projection of that State.

Given any State value the UI must be predictable and repeatable.

Device dependent state should be separate from the Application State.

Displaying the same State on a phone and tablet for example, can result in different UIs. The device dependent state should remain on that device. An OS X and iOS app can use the same State and logic classes and interchange Routers for representing the State.

Not fully implemented yet. PRs welcome!

UI can generate actions to update Path values in the State

The user tapping a back button is easy to capture and generate and action that updates the State Path which causes the UI change. But a user 'swiping' back a view is harder to capture. It should instead generate an action on completion to update the State Path. Then, if the current UI already matches the new State no UI changes are necessary.

Not fully implemented yet. PRs welcome!

Author

Eliah Snakin: [email protected]

Monarch Router emerged from crysalis of Featherweight Router.

License

MonarchRouter is available under the MIT license. See the LICENSE file for more info.