2

Introduction: I have a welcome screen which basically has a button and navigates to a TabView which has all the Screens of the App.

Problem: The WelcomeScreen only loads the first time the App is opened, meaning, once the user navigates to the TabView, I want to hide the "back" button, which I think I'm achieving, BUT the navigationTitle is not appearing. Doesn't appears the "back" button and also not the navigationTitle and toolbar. and I don't understand why. I'm stuck with this 2 days already.

Code of navigation in WelcomeScreen:

.navigationDestination(isPresented: $navigateToOverviewScreen) {
                TabNavigation()
}

Code of the TabView:

struct TabNavigation: View {
var body: some View {
    TabView {
        OverviewScreen()
            .tabItem {
                Image(systemName: "list.bullet.clipboard")
                Text("overview")
            }
        SettingsScreen()
            .tabItem {
                Image(systemName: "gear")
                Text("settings")
            }
    }
    .navigationBarBackButtonHidden(true)
    .accentColor(.black)
}

}

Code of the first screen which is OverviewScreen:

struct OverviewScreen: View {

@StateObject private var viewModel: OverviewViewModel = OverviewViewModel()
@State private var navigateToAddPillScreen: Bool = false

var body: some View {
    NavigationStack {
        mainView
            .toolbar {
                ToolbarItem {
                    AddPillButton {
                        navigateToAddPillScreen.toggle()
                    }
                }
            }
            .sheet(isPresented: $navigateToAddPillScreen, content: {
                AddPillScreen {
                    viewModel.getPills()
                    self.navigateToAddPillScreen.toggle()
                }
            })
            .onAppear {
                viewModel.getPills()
            }
            .navigationTitle("overview")
           
    }
}
@ViewBuilder private var mainView: some View {
    if viewModel.viewState.isListEmpty {
        EmptyListView()
    } else {
        List {
            Section("today") {
                ForEach(viewModel.pills, id: \.id) { pill in
                    PillItem(pill: pill)
                }
            }
        }
    }
}

}

As you can see the viewModifier .navigationTitle is set.

Once I send the app to background and I open it back, then the navigationTitle appears.

Please help!

MACROSystems
  • 415
  • 3
  • 10
  • I just tried to use NavigationView instead of NavigationStack in the OverviewScreen and it works... has something to do? – MACROSystems Jun 29 '23 at 15:42

1 Answers1

0

not sure if you figured this out. I was having similar issues. In my app, I wrapped the equivalent of your 'mainView' in a Nav Stack where it was being defined, and applied the navigation title within that, it worked the way it should. i.e. I did something like...

@Viewbuilder private var mainView: some View{
 NavigationStack{ 
    Content()
      .navigationTitle("..")
  }
}