Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SwiftUI bug with navigation view rotation?

While testing my app to make sure it behaves properly under screen rotations, I discovered that navigation links do not work after a certain sequence of rotations.

The following is a MWE:

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink("link") {
                Text("hi")
            }
        }
    }
    // rotate ->  back -> link -> rotate -> back -> link
}

On a iPhone 13 Pro Max (iOS 15.2 (19C51)) simulator, the following leads to an error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. Run the app on the portrait mode
  2. Rotate the app to the landscape mode
  3. Touch the back button (in the navigation bar)
  4. Touch the navigation link link
  5. Rotate the app to the portrait mode
  6. Touch the back button
  7. Now touching the navigation link link does not work!

Also, the debug console prints:

Unbalanced calls to begin/end appearance transitions for <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentGS1_VVS_22_VariadicView_Children7ElementVS_24NavigationColumnModifier_GVS_18StyleContextWriterVS_19SidebarStyleContext___: 0x152f24860>.

Is this a bug in SwiftUI?
And is there a way to work around this issue?

I’m on macOS Monterey (12.2 (21D49)) + Xcode 13.2.1 (13C100).

>Solution :

Changing ColumnNavigationViewStyle to StackNavigationViewStyle will solve your problem, the sequence you mentioned is most probably a bug, hopefully apple will solve it soon.

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink("link") {
                Text("hi")
            }
        }
        .navigationViewStyle(.stack) //Style
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading