.onAppear not getting called when View is nested with in TabView?

Viewed 867

The code below was working (onAppear was getting called) but as soon as I nested my two views inside a tabView (to present a UIPageViewController-like UI) the second view's onAppear function never gets called, is this a bug or something I'm doing wrong?

struct SetUpWorkoutView: View {
        
        var body: some View {
            NavigationView {
                List {
                    ForEach(sessionTypes) { sessionType  in
                    NavigationLink(destination: LiveWorkoutView(sessionType: sessionType)) {
                        SessionTypeRow(name: sessionType.stringValue)
                    }
                }
            }
        }


 struct LiveWorkoutView: View {
     var body: some View {
    VStack(alignment: .leading) { }
      }.onAppear(perform: {
                    print("on appear called in LiveWorkoutView")
      }
    }
   }
}

@main
struct SwiftUITestApp: App {

    var body: some Scene {
        WindowGroup {
            TabView {
                SetUpWorkoutView()
                WatchSettingsView()
            }
            .tabViewStyle(PageTabViewStyle())
        }
    }
}
0 Answers
Related