Skip to content

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.

Notifications You must be signed in to change notification settings

francescoleoni98/FLNavigation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FLNavigation Logo

FLNavigation

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.

SPM Compatible iOS 16+ macOS 13+ visionOS 1+ watchOS 9+ tvOS 16+

Apps Using FLNavigation

Are you using FLNavigation in your app? Tell me!

Installation

FLNavigation is distributed using the Swift Package Manager (SPM).

Using Xcode

  1. Go to your project’s settings.
  2. Select the Package Dependencies tab.
  3. Click the + button.
  4. Enter the URL of the FLNavigation repository: https://github.com/francescoleoni98/FLNavigation.git
  5. Choose the latest version and add the package to your project.

Using Package.swift

dependencies: [
  .package(url: "https://github.com/francescoleoni98/FLNavigation.git", from: "1.0.0")
]

Then add "FLNavigation" to the dependencies of your target.

Supported actions

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)

Usage

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

import FLNavigation

Declare your screens

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()
    
    // [...]
  }
}

Navigate

struct ContentView: View {

  @Environment(\.navigation) var navigation

  var body: some View {
    Button("Push") {
      navigation(.push(AppScreen.home(tab: 1)
    }
  }
}

Using NavigationPush component

struct ContentView: View {

  var body: some View {
    NavigationPush(AppScreen.home(tab: 1)) {
      Text("Push")
    }
  }
}

Check which screen has been presented

struct ContentView: View {

  @Environment(\.screen) var screen

}

Author

Francesco Leoni
iOS Developer & SwiftUI Enthusiast

If you find this package helpful, feel free to ⭐️ the repo and share feedback!

About

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.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages