If we use VStack or other Stack View in NavigationView in TabView, onAppear
will be called twice.
struct SampleView: View {
var body: some View {
TabView {
NavigationView {
VStack {
Text("...")
.onAppear {
// called twice
}
}
}
}
}
}
However, if we change the VStack to another View, such as Group, onAppear
is called only once, as expected.
struct SampleView: View {
var body: some View {
TabView {
NavigationView {
Group {
Text("...")
.onAppear {
// called only once
}
}
}
}
}
}