SwiftUI NavigationView on Apple Watch triggers multiple callings of onAppear in children views

341 views Asked by At

Using Xcode Beta 12.3, the below code will call onAppear twice and print twice. When I comment out the NavigationView wrapping the ContentView, onAppear is only called once. Is this expected behavior? It seems that ANY NavigationView will trigger multiple callings of onAppear which is not what I would expect...I would expect the same behavior as ViewWillAppear in UIKit.

@main
struct anotherTestWatchAppApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationView {
                ContentView()
            }
        }
    }
}

struct ContentView: View {
    var body: some View {
        Text("Hello, World!")
        .padding()
            .onAppear(perform: {
                print("test")
            })
    
    }
}
0

There are 0 answers