Skip to content

Instantly share code, notes, and snippets.

@kalupas226
Last active August 17, 2022 09:13
Show Gist options
  • Save kalupas226/9ca0b1d073af4207c904328b54870a00 to your computer and use it in GitHub Desktop.
Save kalupas226/9ca0b1d073af4207c904328b54870a00 to your computer and use it in GitHub Desktop.

FB11288574: VStack or other Stack View in NavigationView in TabView bug

Environment: Xcode 13.4.1, iOS 15

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
            }
        }
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment