
FLNavigation is a lightweight and modern Swift package that simplifies navigation management in SwiftUI applications. Built with clarity and flexibility in mind, FLNavigation enables clean and scalable routing.
Are you using FLNavigation in your app? Tell me!
FLNavigation is distributed using the Swift Package Manager (SPM).
- Go to your project’s settings.
- Select the
Package Dependencies
tab. - Click the
+
button. - Enter the URL of the FLNavigation repository: https://github.com/francescoleoni98/FLNavigation.git
- Choose the latest version and add the package to your project.
dependencies: [
.package(url: "https://github.com/francescoleoni98/FLNavigation.git", from: "1.0.0")
]
Then add "FLNavigation" to the dependencies of your target.
Action | Description | Example |
---|---|---|
present(_:) |
Presents a new screen | navigation(.present(AppScreen.onboarding)) |
push(_:) |
Pushes a new screen onto the navigation stack | navigation(.push(AppScreen.detail(id: 1))) |
pop |
Pops the top screen off the navigation stack | navigation(.pop) |
popToRoot |
Pops all screens and returns to the root | navigation(.popToRoot) |
setScreens(_:) |
Replaces the entire navigation stack | navigation(.setScreens([AppScreen.onboarding]) |
dismiss |
Dismisses the current screen | navigation(.dismiss) |
Note: FLNavigation manages the creation of NavigationStack
, so to ensure it works correctly, you must remove any instances of NavigationView
or NavigationStack
from the Views
you declare as ModalScreen
.
import FLNavigation
enum AppScreen: ModalScreen {
case onboarding
case home(tab: Int)
var style: ModalStyle {
switch self {
case .onboarding:
return .modal
default:
return .fullScreen
}
}
}
Then in your MainApp
:
@main
struct MainApp: App {
var screen: some View {
ContentView()
.showScreen { screen in
switch screen {
case let appScreen as AppScreen:
buildAppScreen(appScreen)
default:
EmptyView()
}
}
}
@ViewBuilder
func buildAppScreen(_ screen: AppScreen) -> some View {
switch screen {
case .onboarding:
Onboarding()
// [...]
}
}
struct ContentView: View {
@Environment(\.navigation) var navigation
var body: some View {
Button("Push") {
navigation(.push(AppScreen.home(tab: 1)
}
}
}
struct ContentView: View {
var body: some View {
NavigationPush(AppScreen.home(tab: 1)) {
Text("Push")
}
}
}
struct ContentView: View {
@Environment(\.screen) var screen
}
Francesco Leoni
iOS Developer & SwiftUI Enthusiast
If you find this package helpful, feel free to ⭐️ the repo and share feedback!