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!