I have a view within a tab view (it's the second tab on the list) that shows one of three conditional views dependent on a couple variables in the ViewModel for this view.
The first view is a user selection (ChooseSeasonLength()
), and when that gets selected, it's supposed to show a loading screen (LoadingScreen()
) until a featuredSeason gets set, at which point it is supposed to show the main view (SeasonPage()
):
struct SeasonView: View {
@EnvironmentObject var currentUser: CurrentUserProfile
@ObservedObject var seasonGoalsVM: SeasonGoalsViewModel
var body: some View {
if seasonGoalsVM.featuredSeason != nil {
SeasonPage()
.environmentObject(seasonGoalsVM)
} else if seasonGoalsVM.seasonLength == nil {
ChooseSeasonLength()
.environmentObject(seasonGoalsVM)
} else {
LoadingScreen()
.environmentObject(seasonGoalsVM)
}
}
}
But the issue I'm having is that this SeasonView()
is the second item in the TabView list, and whenever I click the user selection, instead of showing the loading screen, it pops me back to the first tab - the HomePage()
.
When I click back on the SeasonView in the tab list, it takes me to the right screen, but I don't know why the initial user selection on SeasonView takes me back to the HomePage instead of taking me through the correct flow of views within the SeasonView.
I've read that TabView might have some issues, but haven't seen anything about this. Does anyone know if this is possibly an issue with TabView?
Here is my initial view, with the tabs specified in it:
struct HomeView: View {
@StateObject var actionListVM = ActionListViewModel()
@StateObject var seasonGoalsVM = SeasonGoalsViewModel()
var body: some View {
TabView {
HomePage(actionListVM: actionListVM)
.tabItem {
Label("Home", systemImage: "house.fill")
}
SeasonView(seasonGoalsVM: seasonGoalsVM)
.tabItem {
Label("Season", systemImage: "scribble.variable")
}
GroupsPage()
.tabItem {
Label("Groups", systemImage: "person.2.fill")
}
FriendsPage()
.tabItem {
Label("Friends", systemImage: "person.crop.circle.badge.plus")
}
}
}
}