marshroute
Описание
Marshroute is an iOS Library for making your Routers simple but extremely powerful
Языки
- Swift99,8%
- Ruby0,2%
Marshroute
Contents
- Overview
- 3d touch support
- Demo
- Requirements
- Installation
- Customization
- Licence
- Objective-c support
- Useful links
- Authors
Overview
is a library that will encourage you to locate all the navigation logic in the layer, no matter which architecture you prefer.
helps make your s syntactically compact and clear.
Key features:
- Every
-driven transition is always forwarded to the topmostRouter. This means you can askUIViewControllerto present a view controller from any point in your program and it will simply work!Marshroute - No matter how you module was presented, you can simply ask your module's
to dismiss this module via callingRouterand it will simply work! Your parent module can change presentation style in the future (e.g. present modally instead of pushing), butrouter.dismissCurrentModule()will work anyway!router.dismissCurrentModule() - No matter how your module presents subsequent modules, you can simply ask your module's
to return to this module via callingRouterand it will also simply work!router.focusOnCurrentModule() allows changing transition animations in just 1 line of code (see Tuning the transition animation for more details)Marshroutesupports 3d touch transitionsMarshroutedetects view controller retain cycles and notifies you about them via assertions API. You can override default assertions with your implementation: e.g. print assertions to the output or do some advanced analytics (see plugin-customization for more details)Marshroutefeatures a detailed demo project describing key navigation principles on both iPhone and iPadMarshroute
Details
Every -driven transition is always forwarded to the topmost
to make it super easy to support s and for example present module from any point of your application.
I prefer doing this right from my root application's .
This repo allows you to drive your transitions in a super clean, descriptive and flexible fashion.
For example pretend the following code is taken from your root application's :
This code pushes an view controller to the top 's stack.
The parameter is only used to create a for the module.
The magic here is in this line of code:
You can easily change the presentation style in favor of a modal transition by simply changing it to:
If for some reason you do not need a for your module, you may accomplish this by:
Once again, the transition will be forwarded to the top, keeping the very plain and straightforward.
So that, the keeps being responsible for only one thing: selecting the style of a transition.
Tuning the transition animation
You may add an animator to customize the way your transition looks like. For example
The key line here is
So the syntax remains clean and it is super easy to switch back to the original animation style.
3d touch support
PeekAndPopUtility
Want to add fancy peek and pop previews? Easy peasy! Just use from the and register your view controller as capable of previewing other controllers!
is used by during preview animations to take screenshots from. You can register single view controller for previewing in many source views (e.g.: in a table view and in a navigation bar).
closure will get called every time a force touch gesture occurs in a . In your method you should do the following:
-
Find a view which a user interacts with (interactable view). You should use a specified
inlocation's coordinate system.previewingContext.sourceView -
Adjust
of asourceRect. You should convert a frame of that interactable view topreviewingContext's coordinate system.previewingContext.sourceViewusesUIKitto keep it visually sharp when a user presses it, while blurring all surrounding content.sourceRect -
Invoke the transition, that will normally occur if a user simply taps at a same
. For example, it a user presses alocation, you may callUIControlto invoke thatsendActions(for: .touchUpInside)'s an action handler.UIControl
Lets pretend the above-mentioned action handler ends up with some router calling to push a new view controller.
In this case no pushing will actually occur. Instead of this, will freeze a transition and present a target view controller in a preview mode.
The transition will eventually get performed only if a user commits the preview (i.e. pops).
The above described behavior takes place only during active requests (when requests a view controller to be previewed).
In all other situations, will push immediately as expected.
Important note: if you invoke no transition within closure, or invoke an asynchronous transition, no will occur.
This behavior is a result of Api restrictions: is required to return a previewing view controller synchronously.
You can also use closure to set up your gesture recognizer failure relationships.
Peek and pop state observing
You can use from the to observe any view controller's state changes.
This may be useful for analytics purposes.
You can also use to observe your particular view controller's state changes.
This may be useful for adjusting view controller's appearance in and modes.
Here in and closures your may force a view to update its UI accordingly
Demo
Check out the demo project.
This demo is written in using architecture and shows all the capabilities which s are now full of.
Run this demo on a simulator and check out what happens if you simulate a memory warning or a device shake.
You will see several types of transitions driven by the root module's (i.e. a 's ).
The demo project targets both and and adds some minor differences to their navigation behaviors by creating distinct implementations for every supported device idiom, thus highlighting the value of moving the navigation logic from the layer in favor of a layer.
When you tap a blue timer tile, you schedule a reverse transition to the module that tile belongs to. To see this effect taking place, you should make several transitions deeper into the navigation stack.
Starting with 0.4.0 the demo project was updated to show in action: you can press on any table view cell and navigation bar button to get a preview of an underlying transition.
You can also learn how to use to adjust 's appearance in and modes: in a mode you will see only a fullscreen colored image pattern, while in a mode you will also see a similar advertisements section.
Requirements
- iOS 9.0+
- Xcode 14.0+
Note: peek and pop is supported only for iOS 9.0+
Installation
Cocoapods
To install Marshroute using CocoaPods, add the following lines to your :
Then run command. For details of the installation and usage of CocoaPods, visit its official website.
Carthage
To install Marshroute using Carthage, add the following lines to your :
Then run command. For details of the installation and usage of Carthage, visit its repo website.
Customization
You can provide custom print and assert realization using and .
This is as easy as:
MarshroutePrintManager.setUpPrintPlugin(YourPrintPlugin())
MarshrouteAssertionManager.setUpAssertionPlugin(YourAssertionPlugin())
Licence
MIT
Objective-c support
The framework is written in pure using its latest features, so if you want to use in your application you will have to write your s in .
Useful links
You can watch this video to get a closer look at the reasons and ideas which formed the basis of (in Russian).
You can also read this guide of using when implementing s support in your application.
Authors
Timur Yusipov (tyusipov@avito.ru, ykylele@gmail.com, https://twitter.com/Fizmatchel, https://stackoverflow.com/users/2982854/tim).