Reputation: 73
When starting my app for the first time, a little setup is required. After this setup, the user should then come to the MainView.
Now I want it to be so that the user cannot jump back to the last setup step as soon as he reaches the MainView.
All the solutions I can find is to simply remove the back button. But this is not enough for me, I'm currently working with tvOS, there is a back Button on his remote. If he then presses this, he should ideally just come back to the tvOS home screen.
Is there any possibility to delete the complete navigation stack or something similar with the same result?
Upvotes: 0
Views: 644
Reputation: 52312
You can replace your entire view hierarchy at the parent level (above your NavigationView
if a given condition is true:
var body : some View {
if setup {
//parent component of views for once setup is done
MainView()
} else {
//parent component of the setup views (including a NavigationView)
SetupScreens()
}
}
So, on the final setup screen, set setup
to true
(this should probably be stored in an ObservableObject
that each view can access [possible via an .environmentObject
]) and the NavigationView
will be destroyed and the hierarchy will be replaced with MainView
.
Upvotes: 1