Post

Replies

Boosts

Views

Activity

SwiftUI Navigation Issue: Handling Navigation Across Multiple Tabs with Separate Navigation Stacks
I'm working on a SwiftUI application that uses programmatic navigation with enums in a NavigationStack. My app is structured around a TabView with different tabs, each having its own navigation stack. I need to navigate to the same view from different tabs, but each tab has a separate navigation stack with custom paths. Here's a simplified version of my setup: class AppState: ObservableObject { @Published var selectedTab: Tab = .feeds @Published var tabANavigation: [TabANavDestination] = [] @Published var tabBNavigation: [TabBNavDestination] = [] } enum TabANavDestination: Hashable { case itemList() case itemDetails(String) } enum TabBNavDestination: Hashable { case storeList() case itemList() case itemDetails(String) } For example: TabA: ItemsListScreen -> DetailsScreen. TabB: StoreList -> ItemsListScreen -> DetailsScreen I want to navigate from ItemsListScreen to DetailsScreen, but I can't use the same method to append the navigation state in both tabs: appState.tabANavigation.append(.itemDetails(id)) How can I manage navigation across these different tabs, ensuring that the same screen (e.g., DetailsScreen) is accessible from different paths and tabs with their own navigation stacks? What’s the best approach to handle this scenario in a complex navigation setup?
2
0
592
Aug ’24