### AppResolver Providing Home Dependencies Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md An example of an AppResolver class that conforms to HomeDependencies and provides the homeExternalViewProvider. ```swift // Home needs an external view from somewhere. Provide it. public class AppResolver: AppDependencies, HomeDependencies, ... { ... @MainActor public var homeExternalViewProvider: any NavigationViewProviding { NavigationViewProvider { switch $0 { case .external: SettingsDestinations.external } } } } ``` -------------------------------- ### Manual ManagedNavigationStack Wrapping Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Example of manual view wrapping that is replaced by using the .managedSheet or .managedCover navigation methods. ```swift public var body: some View { switch self { ... case .page3: ManagedNavigationStack { // not needed with .managedSheet HomePage3View() } ... } } } ``` -------------------------------- ### Install AI Skills for Navigator Source: https://github.com/hmlongco/navigator/blob/main/README.md Clone the Navigator repository and copy the AI skills to your project's .claude/skills directory. This command sets up the AI assistant with knowledge of Navigator's patterns. ```bash git clone --depth 1 https://github.com/hmlongco/Navigator /tmp/Navigator && \ mkdir -p .claude/skills && \ cp -r /tmp/Navigator/.claude/skills/swiftui-navigation-navigator .claude/skills/ && \ rm -rf /tmp/Navigator ``` -------------------------------- ### Define Shared Destinations with Placeholders Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Example of using NavigationProvidedView with a custom placeholder closure for mock views. ```swift nonisolated public enum SharedDestinations: NavigationDestination { case newOrder case orderDetails(Order) case produceDetails(Product) public var body: some View { NavigationProvidedView(for: self) { switch self { case .newOrder: MockNewOrderView() case .orderDetails(let order): MockOrderDetailsView(order) case .produceDetails(let product): MockProduceDetailsView(for: product) } } } } ``` -------------------------------- ### Accessing External View in HomeDestinationsView Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Demonstrates how HomeDestinationsView accesses the homeExternalViewProvider to get the view for the external destination. ```swift internal struct HomeDestinationsView: View { // Selected destination to display let select: HomeDestinations // Obtain home dependency resolver @Environment(\.homeDependencies) var resolver // Standard view body var body: some View { switch select { ... case .external: resolver.homeExternalViewProvider.view(for: .external) ... } } ``` -------------------------------- ### Destination View with Environment Dependencies Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Delegates view building to a dedicated SwiftUI view, accessing environment dependencies via a resolver. Use this when views require external setup. ```swift ... case pageN(Int) public var body: some View { HomeDestinationsView(destination: self) } } private struct HomeDestinationsView: View { let destination: HomeDestinations @Environment(\.homeDependencies) var resolver var body: some View { switch self { case .home: HomePageView(viewModel: HomePageViewModel(dependencies: resolver)) case .page2: HomePage2View(viewModel: HomePage2ViewModel(dependencies: resolver)) case .page3: HomePage3View(viewModel: HomePage3ViewModel(dependencies: resolver)) case .pageN(let value): HomePageNView(dependencies: resolver, number: value) case .external: resolver.externalView() } } } ``` -------------------------------- ### Passing Dependencies to View Model Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Example of how a specific destination case passes dependencies to its associated view model. This encapsulates dependency management within the destination. ```swift case .page2: HomePage2View(viewModel: HomePage2ViewModel(dependencies: resolver)) ``` -------------------------------- ### Root View with Managed Navigation Stack Source: https://github.com/hmlongco/navigator/blob/main/README.md Initiates a managed navigation stack for a specific scene, starting with a predefined destination. ```swift struct RootHomeView: View { var body: some View { ManagedNavigationStack(scene: "home") { HomeDestinations.home } } } ``` -------------------------------- ### Define NavigationDestination with missing views Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Example of a destination enum in a shared module that cannot access the required view implementations. ```swift nonisolated public enum SharedDestinations: NavigationDestination { case newOrder case orderDetails(Order) case produceDetails(Product) public var body: some View { ??? } } ``` -------------------------------- ### ManagedNavigationStack with Shortcut for Auto Receive Source: https://github.com/hmlongco/navigator/blob/main/README.md Shows a shortcut for automatically receiving HomeDestinations within a ManagedNavigationStack. This simplifies the setup for handling navigation events. ```swift struct RootHomeView: View { var body: some View { ManagedNavigationStack(scene: "home") { HomeContentView(title: "Home Navigation") .navigationAutoReceive(HomeDestinations.self) // shortcut } } } ``` -------------------------------- ### Define a Navigation Checkpoint Source: https://github.com/hmlongco/navigator/blob/main/README.md Defines a named checkpoint in the navigation stack. This example creates a 'home' checkpoint with no associated value. ```swift struct KnownCheckpoints: NavigationCheckpoints { public static var home: NavigationCheckpoint { checkpoint() } } ``` -------------------------------- ### Use ManagedNavigationStack Source: https://github.com/hmlongco/navigator/blob/main/README.md Replace SwiftUI's NavigationStack with ManagedNavigationStack to integrate Navigator's environment and management capabilities. This simplifies navigation setup. ```swift struct RootView: View { var body: some View { ManagedNavigationStack { List { NavigationLink(to: HomeDestinations.page3) { Text("Link to Page 3!") } } } } } ``` -------------------------------- ### Access Current Navigator in Child View Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/NavigationTree.md Shows how a child view like SomeView can access the current Navigator from the environment, which is the Navigator installed by the nearest ManagedNavigationStack. ```swift struct SomeView: View { @Environment(\.navigator) var navigator var body: some View { Button("Also works as expected") { navigator.navigate(to: Destinations.second) } } } ``` -------------------------------- ### Build and Test Navigator Project Source: https://github.com/hmlongco/navigator/blob/main/CLAUDE.md Commands to build the project, run all tests, filter tests, and generate documentation. ```bash swift build swift test swift test --filter NavigatorUITests/NavigatorCoreTests/testNavigatorInitialization ./docs.sh # generate DocC documentation → docs/ ``` -------------------------------- ### Passing Dependencies to View Initialization Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Demonstrates passing environment dependencies and other parameters directly to a view's initializer. Useful when the view itself needs direct access to dependencies. ```swift case .pageN(let value): HomePageNView(dependencies: resolver, number: value) struct HomePageNView: View { @StateObject private var viewModel: HomePageNViewModel init(dependencies: HomeDependencies, number: Int) { self._viewModel = .init(wrappedValue: .init(dependencies: dependencies, number: number)) } var body: some View { ... } } ``` -------------------------------- ### Create Application Root Navigator Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/NavigationTree.md Configures and returns the root Navigator for the application. Adjust executionDelay and verbosity as needed. ```swift func applicationNavigator() -> Navigator { let configuration: NavigationConfiguration = .init( restorationKey: nil, // "1.0.0", executionDelay: 0.4, // 0.3 - 5.0 verbosity: .info ) return Navigator(configuration: configuration) } ``` -------------------------------- ### Implement checkpoint return logic Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md This internal function demonstrates how to navigate back to a specific checkpoint by dismissing children and popping the navigation stack. ```swift internal func returnToCheckpoint(_ checkpoint: NavigationCheckpoint) { guard let (navigator, found) = find(checkpoint) else { return } ... _ = navigator.dismissAnyChildren() _ = navigator.pop(to: found.index) ... } ``` -------------------------------- ### Declare Home Module Dependencies Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Defines the dependency requirements for the Home module, specifically requesting a NavigationViewProviding for external views. ```swift public protocol HomeDependencies { ... @MainActor var homeExternalViewProvider: any NavigationViewProviding { get } ... } ``` -------------------------------- ### Implement NavigationProvidedDestination Body Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Standard implementation for the body property of a NavigationProvidedDestination. ```swift extension NavigationProvidedDestination { public var body: some View { NavigationProvidedView(for: self) } } ``` -------------------------------- ### Establish Checkpoint with Value Handler Source: https://github.com/hmlongco/navigator/blob/main/README.md Sets up a navigation checkpoint that expects an Int value and provides a closure to handle the returned result. The result is stored in 'returnValue'. ```swift // Establish the checkpoint and handler in our view .navigationCheckpoint(KnownCheckpoints.settings) { result in returnValue = result } ``` -------------------------------- ### Return to Checkpoint with Value Source: https://github.com/hmlongco/navigator/blob/main/README.md A button action to return to the 'settings' checkpoint, passing the integer value 5. This demonstrates sending data back to the caller. ```swift Button("Return to Settings Checkpoint Passing Value 5") { navigator.returnToCheckpoint(KnownCheckpoints.settings, value: 5) } ``` -------------------------------- ### Register an External View Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Use onNavigationProvidedView to provide the implementation for an external destination. ```swift .onNavigationProvidedView(OrdersExternalViews.self) { _ in ProfileDestinations.addressEntry // only one view, so no switch needed } ``` -------------------------------- ### Extend NavigationDestination for Navigation Methods Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Implement the NavigationDestination protocol to define specific navigation behaviors for different destinations. ```swift extension HomeDestinations: NavigationDestination { public var method: NavigationMethod { switch self { case .page2: .sheet case .page3: .managedSheet default: .push } } } ``` -------------------------------- ### Handle Checkpoint Return Values Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Checkpoints.md Attach a handler to a checkpoint to receive values when returning to that point. ```swift // Define a checkpoint with a value handler. .navigationCheckpoint(KnownCheckpoints.settings) { result in returnValue = result } ``` -------------------------------- ### Registering Provided Views in Application Root Source: https://github.com/hmlongco/navigator/blob/main/README.md Register views for destinations defined in a shared module. The application root provides the concrete implementations for these destinations, enabling modular navigation. ```swift import Shared import Orders import Products import NavigatorUI import SwiftUI struct ContentView: View { let navigator: Navigator = .init(configuration: .init()) var body: some View { RootTabView() // provide Shared views .onNavigationProvidedView(SharedDestinations.self) { switch $0 { case .newOrder: NewOrderView() case .orderDetails(let order: OrderDetailsView(order) case .produceDetails(let product): ProductDestinations.details(product) } } // setup managed navigation root .navigationRoot(navigator) } } ``` -------------------------------- ### Using NavigationDestinations within a View Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Shows how to integrate NavigationDestinations into a view hierarchy using ManagedNavigationStack. This allows for seamless navigation to defined destinations. ```swift struct RootHomeView: View { var body: some View { ManagedNavigationStack { HomeDestinations.home .navigationDestination(HomeDestinations.self) } } } ``` -------------------------------- ### Perform Imperative Programmatic Navigation Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Use the navigator environment object to push or navigate to destinations imperatively. ```swift @Environment(\.navigator) var navigator: Navigator ... Button("Button Navigate To Home Page 55") { navigator.navigate(to: HomeDestinations.pageN(55)) } Button("Button Push Home Page 55") { navigator.push(HomeDestinations.pageN(55)) } ``` -------------------------------- ### Perform Imperative Navigation Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Checkpoints.md Standard imperative navigation operations for popping or dismissing views. ```swift Button("Pop To Previous Screen") { navigator.pop() } Button("Dismiss Presented View") { navigator.dismiss() } ``` -------------------------------- ### Compare NavigationLink Usage Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Preferred usage of NavigationLink(to:label:) versus the deprecated or standard NavigationLink(value:label:) approach. ```swift // DO NavigationLink(to: HomeDestinations.page3) { Text("Link to Home Page 3!") } // DON'T DO NavigationLink(value: HomePage3View()) { Text("Link to Home Page 3!") } ``` -------------------------------- ### NavigationProvidedView Implementation Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Internal structure of NavigationProvidedView showing how it resolves destinations or falls back to placeholders. ```swift public struct NavigationProvidedView: View { @Environment(\.navigator) private var navigator ... public var body: some View { if let view = navigator.navigationProvidedView(for: destination) { AnyView(view) } else if let placeholder { placeholder } else { #if DEBUG Text("Missing Provider for \(type(of: self)).\(self)") #else EmptyView() #endif } } } ``` -------------------------------- ### NavigationDestination for Modular Applications Source: https://github.com/hmlongco/navigator/blob/main/README.md Define destinations in a shared module that will be provided by the application root. This allows feature modules to declare navigation possibilities without needing to implement the views themselves. ```swift nonisolated public enum SharedDestinations: NavigationProvidedDestination { case newOrder case orderDetails(Order) case produceDetails(Product) } ``` -------------------------------- ### Implement ManagedNavigationStack Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Replace standard NavigationStack with ManagedNavigationStack to enable automatic navigation management and environment support. ```swift struct RootView: View { var body: some View { ManagedNavigationStack { List { NavigationLink(to: HomeDestinations.page3) { Text("Link to Page 3!") } } } } } ``` -------------------------------- ### Send Navigation Event with Value Source: https://github.com/hmlongco/navigator/blob/main/README.md Initiates a navigation event by sending a RootTabs value and a HomeDestinations value. This is used for deep linking or internal navigation. ```swift Button("Send Tab Home, Page 2") { navigator.send( RootTabs.home, HomeDestinations.page2 ) } ``` -------------------------------- ### Return to a Checkpoint Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Checkpoints.md Trigger a return to a specific checkpoint and check availability using canReturnToCheckpoint. ```swift Button("Return To Checkpoint Home") { navigator.returnToCheckpoint(KnownCheckpoints.home) } .disabled(!navigator.canReturnToCheckpoint(KnownCheckpoints.home)) ``` -------------------------------- ### NavigationLink Usage Patterns Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Recommended usage of NavigationLink with Navigator compared to standard SwiftUI NavigationLink patterns. ```swift // DO NavigationLink(to: HomeDestinations.page3) { Text("Link to Home Page 3!") } // DON'T DO NavigationLink(destination: HomePage3View()) { Text("Link to Home Page 3!") } ``` -------------------------------- ### TabView with Shortcut for Navigation Receive Source: https://github.com/hmlongco/navigator/blob/main/README.md Demonstrates a shortcut for the onNavigationReceive modifier in a TabView, directly assigning received values to a binding. This achieves the same result as the full closure. ```swift struct RootTabView : View { @SceneStorage("selectedTab") var selectedTab: RootTabs = .home var body: some View { TabView(selection: $selectedTab) { ... } .onNavigationReceive(assign: $tab) // shortcut } } ``` -------------------------------- ### Pop and Dismiss Navigation Source: https://github.com/hmlongco/navigator/blob/main/README.md Imperative operations to navigate back or dismiss the current view. Use with caution as they can be fragile. ```swift Button("Pop To Previous Screen") { navigator.pop() } ``` ```swift Button("Dismiss Presented View") { navigator.dismiss() } ``` -------------------------------- ### NavigationViewProviding Protocol Definition Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Defines the NavigationViewProviding protocol, which is responsible for providing a view for a given navigation destination. ```swift public protocol NavigationViewProviding { associatedtype D: NavigationViews func view(for destination: D) -> AnyView } ``` -------------------------------- ### Provide View for Each Destination Source: https://github.com/hmlongco/navigator/blob/main/README.md Implement the body of the NavigationDestination enum to return the correct SwiftUI View for each case. Associated values can pass parameters. ```swift ... case pageN(Int) public var body: some View { switch self { case .page2: HomePage2View() case .page3: HomePage3View() case .pageN(let value): HomePageNView(number: value) } } } ``` -------------------------------- ### Define a Checkpoint with a Return Value Source: https://github.com/hmlongco/navigator/blob/main/README.md Extends KnownCheckpoints to define a 'settings' checkpoint that can return an Int value. This allows passing data back from a navigation destination. ```swift // Define a checkpoint with an Int value handler. extension KnownCheckpoints { public static var settings: NavigationCheckpoint { checkpoint() } } ``` -------------------------------- ### Return Value to a Checkpoint Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Checkpoints.md Pass a value back to a checkpoint when returning. ```swift // Return, passing a value. Button("Return to Settings Checkpoint Passing Value 5") { navigator.returnToCheckpoint(KnownCheckpoints.settings, value: 5) } ``` -------------------------------- ### Implement NavigationLink with Navigator Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Use the custom NavigationLink(to:label:) initializer within a ManagedNavigationStack to navigate without manual destination registration. ```swift import NavigatorUI struct SettingsTabView: View { var body: some View { ManagedNavigationStack { List { NavigationLink(to: ProfileDestinations.main) { Text("User Profile") } NavigationLink(to: SettingsDestinations.main) { Text("Settings") } NavigationLink(to: AboutDestinations.main) { Text("About Navigator") } } .navigationTitle("Settings") } } } ``` -------------------------------- ### Basic NavigationDestination Body Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Defines a basic NavigationDestination with a switch statement to return the correct view for each case. Suitable for simple destinations. ```swift ... case pageN(Int) public var body: some View { switch self { case .page2: HomePage2View() case .page3: HomePage3View() ... } } } ``` -------------------------------- ### Consume Modular Views Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Displays a modular view directly within a parent view using the enum case, abstracting away the underlying view construction. ```swift struct CustomView: View { @Environment(\.navigator) var navigator @State var order: Order var body: some View { VStack { ... OrderDestinations.orderSummaryCard(order) ... } } } ``` -------------------------------- ### Dismiss Any Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Returns to the root Navigator and dismisses any ManagedNavigationStack or ManagedPresentationView presented anywhere in the navigation tree. Useful for deep linking. ```APIDOC ## Dismiss Any ### Description Returns to the root Navigator and dismisses *any* `ManagedNavigationStack` or `ManagedPresentationView` presented anywhere in the navigation tree. This functionality is used extensively in deep linking and cross-module navigation in order to clear any presented views prior to taking the user elsewhere in the application. ### Method `dismissAny()` ### Endpoint N/A (Instance method) ### Request Example ```swift try? navigator.dismissAny() ``` ### Response - **Bool** - Returns true if a dismissal occurred, false otherwise. ### Error Handling This call can throw and fail if navigation is locked. ``` -------------------------------- ### SwiftUI View for Advanced Destinations Source: https://github.com/hmlongco/navigator/blob/main/README.md Use a SwiftUI View to construct destinations that require external dependencies or environment access. The resolver is obtained from the environment to construct views and view models. ```swift nonisolated public enum HomeDestinations: NavigationDestination { case home case page2 case page3 case pageN(value: Int) public var body: some View { HomeDestinationsView(destination: self) } } private struct HomeDestinationsView: View { let destination: HomeDestinations @Environment(\.homeDependencies) var resolver var body: some View { switch self { case .home: HomePageView(viewModel: HomePageViewModel(dependencies: resolver)) case .page2: HomePage2View(viewModel: HomePage2ViewModel(dependencies: resolver)) case .page3: HomePage3View(viewModel: HomePage3ViewModel(dependencies: resolver)) case .pageN(let value): HomePageNView(viewModel: HomePageNViewModel(dependencies: resolver), number: value) } } } ``` -------------------------------- ### Define Destination Views Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Implement the body property within the destination enum to return the appropriate view for each case. ```swift ... case pageN(Int) public var body: some View { switch self { case .page2: HomePage2View() case .page3: HomePage3View() case .pageN(let value): HomePageNView(number: value) } } } ``` -------------------------------- ### Establish a Checkpoint on a View Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Checkpoints.md Attach a defined checkpoint to a view within a ManagedNavigationStack. ```swift struct RootHomeView: View { var body: some View { ManagedNavigationStack(scene: "home") { HomeContentView(title: "Home Navigation") .navigationCheckpoint(KnownCheckpoints.home) .navigationDestination(HomeDestinations.self) } } } ``` -------------------------------- ### Define NavigationProvidedDestination Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Implementation of a destination enum using NavigationProvidedDestination to defer view resolution. ```swift nonisolated public enum SharedDestinations: NavigationProvidedDestination { case newOrder case orderDetails(Order) case produceDetails(Product) } ``` -------------------------------- ### Define a Navigation Checkpoint Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Checkpoints.md Define a checkpoint by conforming to NavigationCheckpoint and specifying the return type. ```swift struct KnownCheckpoints: NavigationCheckpoint { public static var home: NavigationCheckpoint { checkpoint() } } ``` -------------------------------- ### Define an External Destination Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Create an enum conforming to NavigationProvidedDestination to declare external view dependencies. ```swift nonisolated public enum OrdersExternalViews: NavigationProvidedDestination { case homeAddressEntryScreen } ``` -------------------------------- ### Navigate Using Correct Navigator in ContentView Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/NavigationTree.md Illustrates how to correctly navigate within a ManagedNavigationStack. The first button fails as it uses the parent Navigator, while the second uses the Navigator provided to the closure, which is the correct one for the current stack. ```swift struct ContentView: View { @Environment(\.navigator) var parentNavigator var body: some View { ManagedNavigationStack { navigator in VStack { Button("Doesn't work as expected") { parentNavigator.navigate(to: Destinations.second) } Button("Works as expected") { navigator.navigate(to: Destinations.second) } SomeView() } .navigationDestination(Destinations.self) } } } ``` -------------------------------- ### Define a Checkpoint with Return Value Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Checkpoints.md Define a checkpoint that expects a specific return value type. ```swift struct KnownCheckpoints: NavigationCheckpoint { public static var settings: NavigationCheckpoint { checkpoint() } } ``` -------------------------------- ### Return to a Navigation Checkpoint Source: https://github.com/hmlongco/navigator/blob/main/README.md A button action to return to a previously defined checkpoint. The button is disabled if the checkpoint is not reachable. ```swift Button("Return To Checkpoint Home") { navigator.returnToCheckpoint(KnownCheckpoints.home) } .disabled(!navigator.canReturnToCheckpoint(KnownCheckpoints.home)) ``` -------------------------------- ### Inject Single External Views Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Using NavigationProvidedView to inject a single view within a larger navigation destination switch. ```swift nonisolated public enum HomeDestinations: NavigationDestination { ... case pageN(Int) case external var body: some View { switch select { ... case .pageN(let n): HomePageNView(number: n) case .external: NavigationProvidedView(for: HomeDestinations.external) } } } ``` ```swift .onNavigationProvidedView(HomeDestinations.self) { destination in switch destination { case .external: SomeExternalView() default: EmptyView() } } ``` -------------------------------- ### Register provided views with onNavigationProvidedView Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Application-level registration of views for NavigationProvidedDestination using the onNavigationProvidedView modifier. ```swift import Shared import Orders import Products import NavigatorUI import SwiftUI struct ContentView: View { let navigator: Navigator = .init(configuration: .init()) var body: some View { RootTabView() // provide Shared views .onNavigationProvidedView(SharedDestinations.self) { switch $0 { case .newOrder: NewOrderView() case .orderDetails(let order: OrderDetailsView(order) case .produceDetails(let product): ProductDestinations.details(product) } } // setup managed navigation root .navigationRoot(navigator) } } ``` -------------------------------- ### Perform Declarative Programmatic Navigation Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Navigate using state-bound modifiers for optional destinations or boolean triggers. ```swift // Sample using optional destination @State var page: SettingsDestinations? ... Button("Modifier Navigate to Page 3!") { page = .page3 } .navigate(to: $page) // Sample using trigger value @State var triggerPage3: Bool = false ... Button("Modifier Trigger Page 3!") { triggerPage3.toggle() } .navigate(trigger: $triggerPage3, destination: SettingsDestinations.page3) ``` -------------------------------- ### HomeExternalViews NavigationViews Conformance Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md An enumeration conforming to NavigationViews, representing external navigation destinations for the Home module. ```swift nonisolated public enum HomeExternalViews: NavigationViews { case external } ``` -------------------------------- ### Define NavigationDestination with body Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/ProvidedDestinations.md Standard implementation of a NavigationDestination enum where the destination views are directly accessible. ```swift nonisolated public enum SharedDestinations: NavigationDestination { case newOrder case orderDetails(Order) case produceDetails(Product) public var body: some View { switch self { case .newOrder: NewOrderView() case .orderDetails(let order): OrderDetailsView(order) case .produceDetails(let product): ProduceDetailsView(for: product) } } } ``` -------------------------------- ### Use NavigationLink(to:label) to Avoid Registrations Source: https://github.com/hmlongco/navigator/blob/main/README.md Use this initializer with your NavigationDestination enums to avoid explicit SwiftUI navigation destination registrations. This works with ManagedNavigationStack. ```swift import NavigatorUI struct SettingsTabView: View { var body: some View { ManagedNavigationStack { List { NavigationLink(to: ProfileDestinations.main) { Text("User Profile") } NavigationLink(to: SettingsDestinations.main) { Text("Settings") } NavigationLink(to: AboutDestinations.main) { Text("About Navigator") } } .navigationTitle("Settings") } } } ``` -------------------------------- ### Establish a Checkpoint in a View Source: https://github.com/hmlongco/navigator/blob/main/README.md Applies a navigation checkpoint to a view within a ManagedNavigationStack. This makes the 'home' checkpoint available for navigation. ```swift struct RootHomeView: View { var body: some View { ManagedNavigationStack(scene: "home") { HomeContentView(title: "Home Navigation") .navigationCheckpoint(KnownCheckpoints.home) } } } ``` -------------------------------- ### Wrap content in ManagedPresentationView Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/NavigationTree.md Wraps a sheet's destination in a ManagedPresentationView to ensure the view receives its own Navigator instance. ```swift func body(content: Content) -> some View { content .sheet(item: $state.sheet) { destination in ManagedPresentationView { destination } } } ``` -------------------------------- ### Define Custom Navigation Method for Destinations Source: https://github.com/hmlongco/navigator/blob/main/README.md Extend your NavigationDestination enum to specify a custom NavigationMethod (e.g., .sheet, .push) for each case. This determines how navigator.navigate(to:) behaves. ```swift extension HomeDestinations { public var method: NavigationMethod { switch self { case .page3: .sheet default: .push } } } ``` -------------------------------- ### Define Modular Navigation Destinations Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Encapsulates feature views within an enum conforming to NavigationDestination to hide implementation details from consuming modules. ```swift public enum OrderDestinations: NavigationDestination { case orderSummaryCard(Order) case order(Item) case listPastOrders public var body: some View { OrderDestinationsView(destination: self) } } ``` -------------------------------- ### Access Parent Navigator in ManagedNavigationStack Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/NavigationTree.md Demonstrates accessing the parent Navigator from the environment within a ManagedNavigationStack. This Navigator is typically the root Navigator. ```swift public struct ManagedPresentationView: View { @Environment(\.navigator) private var parent: Navigator @Environment(\.isPresented) private var isPresented ... ``` -------------------------------- ### Dismiss Any View in Navigation Tree Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Returns to the root Navigator and dismisses any presented view anywhere in the navigation tree. This operation can throw an error if navigation is locked. Useful for deep linking and cross-module navigation. ```swift Button("Dismiss Any") { try? navigator.dismissAny() } ``` -------------------------------- ### Wrap external sheets with ManagedPresentationView or modifier Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/NavigationTree.md Ensures external sheets are recognized by Navigator using either the wrapper or the modifier shortcut. ```swift // wrap using ManagedPresentationView func body(content: Content) -> some View { ... .sheet(isPresenting: $showSheet) { ManagedPresentationView { MyView() } } } // or use the modifier shortcut which does the same thing func body(content: Content) -> some View { ... .sheet(isPresenting: $showSheet) { MyView() .managedPresentationView() } } ``` -------------------------------- ### Dismiss Presented Views by Parent Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md A parent view uses this to dismiss any sheets or fullScreenCover views it presented using `navigator.navigate(to:)`. This is the inverse of the `dismiss()` operation. ```swift Button("Dismiss Presented Views") { navigator.dismissPresentedViews() } ``` -------------------------------- ### Resolve Cross-Module View Dependencies Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Uses a dependency resolver to inject views across module boundaries, allowing features to remain decoupled from the specific implementation of external views. ```swift private struct HomeDestinationsView: View { let destination: HomeDestinations @Environment(\.homeDependencies) var resolver var body: some View { switch self { ... case .external: resolver.externalView() } } } ``` ```swift typealias AppDependencies = CoreDependencies & HomeDependencies & SettingsDependencies class AppResolver: AppDependencies { ... @MainActor func externalView() -> AnyView { // reach out to the settings module to provide the view needed SettingsDestinations.external.asAnyView() } ... } ``` -------------------------------- ### Dismiss Currently Presented View Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Use this to dismiss the view that is currently presented from within itself. This operation is specific to the current presented view and does not affect the navigation path. ```swift Button("Dismiss") { navigator.dismiss() } ``` -------------------------------- ### Programmatic Navigation with Modifier (Optional Destination) Source: https://github.com/hmlongco/navigator/blob/main/README.md Navigate to a destination using a state-managed optional enum. The .navigate modifier handles the transition when the state changes. ```swift // Sample using optional destination @State var page: SettingsDestinations? ... Button("Modifier Navigate to Page 3!") { page = .page3 } .navigate(to: $page) ``` -------------------------------- ### Define Navigation Destinations Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Define a set of navigation routes using an enum that conforms to the NavigationDestination protocol. ```swift nonisolated public enum HomeDestinations { case page2 case page3 case pageN(Int) } ``` -------------------------------- ### Root Tab View with Navigation Receiver Source: https://github.com/hmlongco/navigator/blob/main/README.md A TabView that uses @SceneStorage for the selected tab and listens for RootTabs values using onNavigationReceive. It updates the selected tab when a new RootTabs value is received. ```swift struct RootTabView : View { @SceneStorage("selectedTab") var selectedTab: RootTabs = .home var body: some View { TabView(selection: $selectedTab) { RootHomeView() .tabItem { Label("Home", systemImage: "house") } .tag(RootTabs.home) RootSettingsView() .tabItem { Label("Settings", systemImage: "gear") } .tag(RootTabs.settings) } .onNavigationReceive { (tab: RootTabs) in if tab == selectedTab { return .immediately } selectedTab = tab return .auto } } } ``` -------------------------------- ### Dismiss Current View Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Dismisses the currently presented view. This is called from within the presented view itself. ```APIDOC ## Dismiss ### Description Dismisses the currently presented ManagedNavigationStack. Unlike Apple's dismiss environment variable, Navigator's dismiss function doesn't "pop" the current view on the navigation path. It exists solely to dismiss the currently presented view from within the currently presented view. ### Method `dismiss()` ### Endpoint N/A (Instance method) ### Request Example ```swift Button("Dismiss") { navigator.dismiss() } ``` ### Response N/A ``` -------------------------------- ### Use ManagedNavigationStack for sheet navigation Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/NavigationTree.md Utilizes ManagedNavigationStack when navigation functionality is required within a presented sheet. ```swift func body(content: Content) -> some View { ... .sheet(isPresenting: $showSheet) { ManagedNavigationStack { MyView() } } } ``` -------------------------------- ### Programmatic Navigation with Modifier (Trigger Value) Source: https://github.com/hmlongco/navigator/blob/main/README.md Trigger navigation to a specific destination by toggling a boolean state variable. The .navigate modifier listens to the trigger and performs the navigation. ```swift // Sample using trigger value @State var triggerPage3: Bool = false ... Button("Modifier Trigger Page 3!") { triggerPage3.toggle() } .navigate(trigger: $triggerPage3, destination: SettingsDestinations.page3) ``` -------------------------------- ### Override Navigation Method with navigate(to:method:) Source: https://github.com/hmlongco/navigator/blob/main/README.md Explicitly specify the navigation method (e.g., .sheet) when calling navigator.navigate(to:). This overrides the default method defined in the NavigationDestination extension. ```swift Button("Present Home Page 55 Via Sheet") { navigator.navigate(to: HomeDestinations.pageN(55), method: .sheet) } ``` -------------------------------- ### Override Navigation Method Programmatically Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Destinations.md Use the navigate function to explicitly override the default navigation method for a specific destination. ```swift Button("Present Home Page 55 Via Sheet") { navigator.navigate(to: HomeDestinations.page3, method: .sheet) } ``` -------------------------------- ### Dismiss Presented Views Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Dismisses any sheet or fullScreenCover views presented by this Navigator. This is typically called from a parent view to dismiss its children. ```APIDOC ## Dismiss Presented Views ### Description Dismisses any presented sheet or fullScreenCover views presented by this Navigator using `navigator.navigate(to:)`. This is used in the parent view to dismiss its children, effectively the opposite of `dismiss()`. ### Method `dismissPresentedViews()` ### Endpoint N/A (Instance method) ### Request Example ```swift Button("Dismiss Presented Views") { navigator.dismissPresentedViews() } ``` ### Response N/A ``` -------------------------------- ### Present Custom Sheets with NavigationDestination Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Advanced/AdvancedDestinations.md Uses a destination variable to trigger sheet presentation with specific detents and drag indicators. The .navigationDismissible() modifier is required to register the sheet with the Navigator system. ```swift struct CustomSheetView: View { @State private var showSettings: SettingsDestinations? var body: some View { List { Button("Present Page 2 via Sheet") { showSettings = .page2 } Button("Present Page 3 via Sheet") { showSettings = .page3 } .sheet(item: $showSettings) { destination in destination // obtain view .presentationDetents([.medium, .large]) .presentationDragIndicator(.visible) .navigationDismissible() } } } } ``` -------------------------------- ### Lock Navigation Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Prevents global dismiss actions (like dismissAny) from occurring on a specific view. ```APIDOC ## Locking Navigation ### Description Prevents dismissal from happening globally. If a view has the `navigationLocked` modifier, the global `dismissAny` action will fail and throw an error. The view itself or its parent can still dismiss it. When the view containing the navigation lock is dismissed, the global lock is cleared automatically. ### Method `.navigationLocked()` modifier ### Endpoint N/A (View modifier) ### Request Example ```swift MyTransactionView() .navigationLocked() ``` ### Response N/A ``` -------------------------------- ### Dismiss Any Children Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Dismisses any ManagedNavigationStack or ManagedPresentationView presented by this Navigator or any of its children in the current navigation tree. Called from a parent view. ```APIDOC ## Dismiss Any Children ### Description Dismisses *any* `ManagedNavigationStack` or `ManagedPresentationView` presented by this Navigator or by any child of this Navigator in the current navigation tree. Returns true if a dismissal occurred, false otherwise. This is used in the parent view to dismiss its children, effectively the opposite of `dismiss()`. ### Method `dismissAnyChildren()` ### Endpoint N/A (Instance method) ### Request Example ```swift Button("Dismiss Any Children") { navigator.dismissAnyChildren() } ``` ### Response - **Bool** - Returns true if a dismissal occurred, false otherwise. ``` -------------------------------- ### Dismiss Any Children Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Dismisses any `ManagedNavigationStack` or `ManagedPresentationView` presented by this Navigator or any of its children. Returns true if a dismissal occurred. ```swift Button("Dismiss Any Children") { navigator.dismissAnyChildren() } ``` -------------------------------- ### Navigation Receiver for Destinations Source: https://github.com/hmlongco/navigator/blob/main/README.md A modifier that listens for HomeDestinations values and uses the navigator to navigate to the specified destination. It returns .auto to indicate normal navigation flow. ```swift .onNavigationReceive { (destination: HomeDestinations, navigator) in navigator.navigate(to: destination) return .auto } ``` -------------------------------- ### Apply state-driven dismissal modifiers Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Use these modifiers to trigger view dismissal by toggling a bound boolean value. The bound value is automatically reset to false after the dismissal is triggered. ```swift // dismiss .navigationDismiss(trigger: $dismiss1) // dismiss presented views .NavigationDismissPresentedViews(trigger: $dismiss2) // dismiss any children .navigationDismissAnyChildren(trigger: $dismiss3) // dismiss any .navigationDismissAny(trigger: $dismiss4) ``` -------------------------------- ### Lock Navigation Source: https://github.com/hmlongco/navigator/blob/main/Sources/NavigatorUI/Documentation.docc/Basics/Dismissible.md Apply this modifier to a presented view to prevent global dismiss actions (like `dismissAny`) from interrupting its flow. The lock is automatically cleared when the view is dismissed. ```swift MyTransactionView() .navigationLocked() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.