[iOS, SwiftUI] onAppear called twice on a NavigationView in a TabView

less than 1 minute read

iOS 14.x

  • onAppear called twice on a NavigationView in a TabView
TabView {
    NavigationView {
        Color.red
            .onAppear {
                print("appear : red")
            }
            .onDisappear {
                print("disappear : red")
            }
    }
}
appear : red
disappear : red
appear : red

iOS 15.0

  • onAppear called twice on a NavigationView in a TabView issue is resolved on iOS15, but onAppear of a ZStack in a NavigationView in a TabView is called twice
TabView {
    NavigationView {
        ZStack {
            Color.red
                .onAppear {
                    print("appear : red")
                }
                .onDisappear {
                    print("disappear : red")
                }
        }
    }
}
appear : red
disappear : red
appear : red

Reference

Leave a comment