0

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")
                }
        }
    }
}
Charlie Page
  • 541
  • 2
  • 17
  • could you show the code of LoadingScreen. You pass an ".environmentObject(seasonGoalsVM)", instead of just using "LoadingScreen(seasonGoalsVM: seasonGoalsVM)", is there a reason for this? – workingdog support Ukraine Jun 21 '21 at 01:21
  • @RajaKrishan Yes - I just tried this, and that worked properly, thank you! – Charlie Page Jun 21 '21 at 12:32
  • @workingdog I changed that to an ObservedObject and passed it in that way - I think this makes more sense than having it be an EnvironmentObject. That didn't change the behavior though. – Charlie Page Jun 21 '21 at 12:33

0 Answers0