Navidux is easy and simple module to build your navigation without thinking about complicated routes in factories.
We create this package with router to facilitate routing duties and improve reading in complicated projects. Analyzing previous project give us idea of creating independently navigation. It's did not depend on your project and may use in different combination and variations. Of course it can uses with Storyboard, UIKit and SwiftUI screens. The goals we want to achieve:
NavigationCoordinator core consists from:
actionReducer(action:)
; Swift Package Manager
Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Xcode 11+ is required to build Navidux using Swift Package Manager. To integrate Navidux into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/RedMadRobot/navidux.git")
]
Next you have to extends 2 object and implement 1 to use Navidux at maximum. Some were in your APP module extends:
extension NaviduxScreen {
static let newScreen = NaviduxScreen(
description: "someDescription",
screenClass: YourScreenTypeInheritedFromUIViewController.self
)
}
extension Navidux.ScreenFactory {
public var someScreenFactory: (NavigationCoordinator?, ScreenConfig) -> any NavigationScreen {
{ coordinator, config
return MyViewControllerConformedNavigationScreen()
}
}
And implement Navidux.ScreenAssembler protocol.
To set Navidux as initial navigation controller. You need do installation and preparation phases. After you may initialise NavigationCoordinator like example below.
let navigationController = NavigationControllerImpl()
let screenFactory: ScreenFactory = NaviduxScreenFactory()
let alertFactory: AlertFactory = AlertFactoryImpl()
let navigationCoordinatorProxy = NavigationCoordinatorProxy()
let screenAssembler = NaviduxScreenAssembler(
screenFactory: screenFactory,
alertFactory: alertFactory,
screenCoordinator: navigationCoordinatorProxy
)
let navigationCoordinator = NavigationCoordinator(
navigationController,
screenAssembler: screenAssembler
)
navigationCoordinatorProxy.subject = navigationCoordinator
navigationCoordinator.actionReducer(
action: .push(.firstScreen, .init(navigationTitle: ""), .fullscreen)
)
window?.rootViewController = navigationController
For example in your UIViewController you may call NavigationCoordinator and ask it for action:
navigation?.actionReducer(
action: .push(.nextScreen, .init(navigationTitle: "My title"), .fullscreen)
)