I'm using a 100% SwiftUI app, currently on Xcode 12 Beta 4
In my ContentView, I have a simple TabView
The AgendaView and HealthView have onAppear methods. On App launch, the AgendaView is the one visible, but onAppear is called for both AgendaView and HealthView.
Why is that? Shouldn't onAppear be called only when the view actually appears on screen?
Code for HealthView and AgendaView
In my ContentView, I have a simple TabView
Code Block swift struct ContentView: View { var body: some View { TabView { AgendaView() .tabItem { Image(systemName: "list.bullet") Text("Agenda") } HealthView() .tabItem { Image(systemName: "heart") Text("Health") } } } }
The AgendaView and HealthView have onAppear methods. On App launch, the AgendaView is the one visible, but onAppear is called for both AgendaView and HealthView.
Why is that? Shouldn't onAppear be called only when the view actually appears on screen?
Code for HealthView and AgendaView
Code Block swift struct AgendaView: View { var body: some View { VStack { Text("Hello, AgendaView!") }.onAppear{ print("AgendaView.onAppear") }.onDisappear(){ print("AgendaView.onDisappear") } } } struct HealthView: View { var body: some View { VStack { Text("Hello, HealthView!") }.onAppear{ print("HealthView.onAppear") }.onDisappear(){ print("HealthView.onDisappear") } } }