Thank you for visiting Navi’s documentation page! Here, you will find detailed information about the Navi library and how to integrate it into your project. Navi is a powerful navigation library for iOS that simplifies the navigation flow in your app.
Navi Documentation
- Installation
- Getting Started
- Navigation Stack
- Routing
- Transitions
- Deep Linking
- Integration with Existing Projects
- Customization
- Advanced Topics
Installation
To install Navi, you can use CocoaPods. Simply add the following line to your Podfile:
pod 'navi'
Getting Started
Before you can start using Navi, you need to understand the basic concepts and how to set it up in your project.
- First, add the import statement to the file where you want to use Navi:
import Navi
- Create an instance of Navi’s
NavigationManager
and set it as the root navigation manager of your app in theAppDelegate
:Navi.shared.setNavigationManager(NavigationManager())
- Start defining your app’s navigation stack and routes. This can be done by subclassing
NavigationMap
and providing the necessary implementations:class AppNavigationMap: NavigationMap { override func initialize() { // Define your navigation stack and routes here } }
- Initialize your app’s navigation map in the
application:didFinishLaunchingWithOptions:
method of yourAppDelegate
:let navigationMap = AppNavigationMap() Navi.shared.setNavigationMap(navigationMap)
Navigation Stack
The navigation stack represents the hierarchy of screens or views in your app. Navi provides a stack-based navigation system that makes it easy to transition between different screens. The navigation stack can be manipulated using the push
, pop
, and present
methods.
To push a new screen onto the stack:
Navi.shared.push(screen: MyScreen())
Routing
Navi’s routing feature allows you to define routes using URL-like patterns. This enables deep linking and allows you to navigate to specific screens in your app using a URL.
To define a route, override the registerRoutes
method in your navigation map:
override func registerRoutes() {
register(route: "/screen/:id", to: MyScreen.self)
}
You can then navigate to the route using:
Navi.shared.goto(route: "/screen/123")
Transitions
Navi supports various transition animations when navigating between screens. You can specify the transition animation using the Transition
enum, for example:
Navi.shared.push(screen: MyScreen(), withTransition: .slide)
Available transition options include .push
, .present
, .slide
, .fade
, and more.
Deep Linking
Navi provides deep linking capabilities, allowing you to handle incoming URLs and navigate to the appropriate screen in your app. To handle deep links, implement the UIApplicationDelegate
method:
func application(_ application: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return Navi.shared.handleDeepLink(url)
}
Integration with Existing Projects
If you have an existing project, integrating Navi is straightforward. Simply follow the installation steps and then adapt your project’s navigation flow to use Navi’s stack-based navigation system.
Customization
Navi allows you to customize various aspects of the navigation stack and transitions. For example, you can customize the transition animations, navigation bar appearance, and more. Please refer to the Navi documentation for the full list of available customization options.
Advanced Topics
Screen Handling
You can customize the behavior of screens in Navi by implementing the Screen
protocol methods. This allows you to, for example, handle on-screen events or perform actions when a screen is pushed or popped.
Passing Data
Navi provides a convenient way to pass data between screens. In the Screen
subclass, you can define properties to hold the necessary data, and then pass it when navigating:
class MyScreen: Screen {
var myData: String?
}
let screen = MyScreen()
screen.myData = "Hello, Navi!"
Navi.shared.push(screen: screen)
Resolving Routes
If you need to resolve routes dynamically at runtime, you can implement the RouteResolvable
protocol in your navigation map. This allows you to determine the appropriate screen class based on the route being accessed.
Congratulations! You have reached the end of the Navi documentation. We hope this guide has provided you with all the necessary information to get started with Navi and take full advantage of its powerful navigation features. Should you have any further questions or need additional assistance, please feel free to reach out to our support team. Happy navigating!