A lightweight, type-safe navigation library for SwiftUI that makes complex navigation flows simple and maintainable.
import SwiftUI
import Pilot
@main
struct YourApp: App {
var body: some Scene {
WindowGroup {
CoordinatorView(root: .login)
}
}
}
struct LoginView: View {
@EnvironmentObject private var coordinator: Coordinator
var body: some View {
VStack {
Text("Welcome to Pilot!")
Button("Next") {
coordinator.push(.dashboard)
}
}
}
}
- Type-Safe Navigation: Define destinations with the
Destination
protocol - Centralized Control: Manage navigation from a single
Coordinator
- Flexible Presentation: Support for sheets, full-screen modals, and navigation stacks
- Clean API: Simple methods for push, pop, present, and dismiss
- Add Pilot to your project:
.package(url: "https://github.com/vetrek/pilot", from: "1.0.7")
- Define a Destination:
struct LoginRoute: Destination {
let id = UUID()
@MainActor
func makeView() -> some View {
LoginView()
}
}
- Navigate:
// Push a new screen
coordinator.push(.dashboard)
// Present a sheet
coordinator.present(.settings, presentConfiguration: .sheet())
// Pop back
coordinator.pop(.back)
// Dismiss modals
coordinator.dismiss()
// Pop to root
coordinator.pop(.root)
// Pop to specific screen
coordinator.pop(.destination(LoginRoute.self))
// Present with custom configuration
coordinator.present(
.profile,
presentConfiguration: .sheet(allowsNavigation: true, detents: [.medium])
)
struct DashboardView: View {
@EnvironmentObject private var coordinator: Coordinator
var body: some View {
NavigationStack {
List {
Button("Settings") {
coordinator.present(.settings)
}
Button("Profile") {
coordinator.push(.profile)
}
}
}
}
}
- iOS 15.0+
- macOS 12.0+
- watchOS 8.0+
- tvOS 15.0+
dependencies: [
.package(url: "https://github.com/vetrek/pilot", from: "1.0.7")
]
Contributions are welcome! Please feel free to submit a Pull Request.
Pilot is available under the MIT license. See the LICENSE file for more info.