Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Created July 24, 2020 12:53
Show Gist options
  • Save mbrandonw/2b1eefef3d939074fa040a7a0c7ab377 to your computer and use it in GitHub Desktop.
Save mbrandonw/2b1eefef3d939074fa040a7a0c7ab377 to your computer and use it in GitHub Desktop.

FB8130464

I have found an erroneous invocation of onDisappear in a particular view hierarchy. If you have a NavigationView wrapping a Form, which has a NavigationLink that drills down to a Form, then the inner most Form will have its onDisappear invoked when the view appears.

Here is a code sample that reproduces it:

struct ContentView: View {
  var body: some View {
    NavigationView {
      Form {
        NavigationLink(
          "Tap",
          destination: Form {
            Section(header: Text("Section")) {
              Text("Label")
            }
          }
          .onDisappear {
            print("🛑 This should not be called")
          }
        )
      }
    }
  }
}

When you tap the root navigation link you will see that it causes the onDisappear to be invoked when it should not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment