Mijick / NavigationView

Navigation made simple (SwiftUI)
MIT License
238 stars 9 forks source link

Nested Navigation with Navigattie #11

Closed stodevCoding closed 12 months ago

stodevCoding commented 1 year ago

Hello,

I have a situation that I would like to discuss with you regarding the different 'userflows' in my application.

In my current situation, I have a TabView as the entry point of my application, which serves as the base for four distinct and independent 'userflows'. Each 'userflow' has several nested views. My concern is that, with the current implementation of Navigattie, the level 0 (Root) seems to be defined at the entry point of the application rather than for each 'userflow'. So, if I call popToRoot, I return to the first screen of the application rather than the beginning of the specific 'userflow'.

For instance, I have a code that looks like this for the FirstFlow:

import SwiftUI
import Combine
import Navigattie

struct FirstFlowScreen: NavigatableView {

    @Environment(SharedVariables.self) var shared

    @StateObject var navState = NavigationStateManager()

    var titleView: String
    var sharedFlowVM = BigFlowViewModel()

    var body: some View {

        NavigationStack(path: $navState.inventorySelectionPath) {
            ScrollView(showsIndicators: false){

                //Content
            }
            .navigationDestination(for: NavigationState.self) { state in
                switch state {
                    case .goToView1: View1()
                        .environment(sharedFlowVM)
                        .environment(shared)
                        .environmentObject(navState)
                    case .goToView2: View2()
                        .environment(sharedFlowVM)
                        .environment(shared)
                        .environmentObject(navState)
                    case .goToView3: View3()
                        .environment(sharedFlowVM)
                        .environment(shared)
                        .environmentObject(navState)
                    case .goToView4: View4()
                        .environment(sharedFlowVM)
                        .environment(shared)
                        .environmentObject(navState)
                    case .goToView5: View5()
                        .environment(sharedFlowVM)
                        .environment(shared)
                        .environmentObject(navState)
                }
            }
        }
    }
}

With Navigattie, if I do a popToRoot, I return to the first screen of my application, which could be the beginning of my FirstFlow. However, if I have a SecondFlow, the same action would always take me back to the beginning of my FirstFlow. In other words, currently popToRoot does not consider the beginning of each 'userflow' as a "level zero".

Do you have any suggestion on how to handle this situation with Navigattie? Thank you in advance for your help and looking forward to your response.

gorbat-o commented 4 months ago

Hey, did you try using a NavigationStateManager() for each individual flow? If not, how did you solve the issue?