SwiftUI is great. But navigation isn't.
FlowKit is the ideal navigation library for SwiftUI.
Platform | Minimum Swift Version | Installation |
---|---|---|
iOS 13.0+ | 5.5 | Swift Package Manager |
File
->Add Packages...
And paste the repository URL.- Or add it to the
dependencies
value of yourPackage.swift
.
dependencies: [
.package(url: "https://github.com/Mercen-Lee/FlowKit.git", .branch("main"))
]
- Push View
flow.push(NextView())
// or
flow.push(NextView(), animated: false)
- Pop View
flow.pop()
flow.pop(3) // 3 Views
- Pop View to Root
flow.popToRoot()
- Replace Views
flow.replace([FirstView(), SecondView()])
- Reload View
flow.reload()
- Present Sheet
flow.sheet(SheetView())
- Present Alert
let alert = Alert(title: "Error",
message: "Not Found",
dismissButton: .default("Ok"))
flow.alert(alert)
import SwiftUI
import FlowKit
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
FlowPresenter(rootView: ContentView())
}
}
}
struct ContentView: View {
@Flow var flow
var body: some View {
Button {
flow.push(NextView())
} label: {
Text("Push")
}
}
}
struct NextView: View {
@Flow var flow
var body: some View {
Button {
flow.pop()
} label: {
Text("Pop")
}
}
}
TCA Example
struct FlowDependency: DependencyKey {
static var liveValue: FlowProvider {
FlowProvider(rootView: ContentView())
}
}
extension DependencyValues {
var flow: FlowProvider {
get { self[FlowDependency.self] }
set { self[FlowDependency.self] = newValue }
}
}
struct Content: Reducer {
@Dependency(\.flow) var flow
...
}