Cancel back gesture bug with NavigationView

I'm not sure how to fix this or if it is even fixable. When I hold the back swipe gesture in my SwiftUI app it completely bugs out and the navigation gets screwed up. It works fine if I do a complete back swipe, but if I pause at any time while swiping this bug occurs.


See this example gif:


https://imgur.com/WqOqUlG


Is there solution for this at all? I'm using a standard `NavigationView` with a `NavigationLink`.

I suspect this may be related to a bug I filed with Apple a few days ago, FB7433665.


There's a `presentationMode` value in the Environment that defines whether an item is presented by another, and provides a way for it to be dismissed. I noticed that the mode's `isPresented` property changes to `false` immediately on the start of the swipe gesture, and it doesn't ever get reset to `true`. This may ultimately be causing the problems with the navigation bar update.


I'd recommend filing a bug with Apple, and referencing FB7433665 in your description.

Are there any workarounds? Like modifying the `isPresented` property of the subview in the `onAppear` of the parent view?

None that I'm aware of, unfortunately. The `PresentationMode` struct is essentially a small helper that ties into a larger, more private piece of SwiftUI. The `isPresented` property is read-only. Really all I can suggest is to pile on the bug reports. They've fixed several of my own gripes so far, so they're not unresponsive. They just need multiple people reporting the same bugs—more duplicates == higher priority.

Any updates on this? I am having the same issue here. Xcode 11.4 and iOS 13.3.


It's only happening in some of my navigation views, so I'm suspecting a developer error.


Edit: It looks like the problem occurs when I add a trailing button to the navigation view.

same here, Xcode 11.4.1 and iOS 13.4

This happens if i declare the environment variable .presentationMode and set .navigationBarItems(trailing…
Code Block
struct MasterView: View {
    var body: some View {
        NavigationView {
            NavigationLink("Go", destination: DetailView())
                .navigationBarTitle("Master")
        }
    }
}
struct DetailView: View {
    @Environment(\.presentationMode) var presentation
    var body: some View {
        Text("Detail view")
            .navigationBarTitle("Detail")
            .navigationBarItems(trailing: Button("Close") { })
    }
}

If comment out line 11 or 16, navigation works fine.
Edit:
If comment out line 11 or 16, navigation works fine.
I'm seeing this exact same behavior, with both a trailing button and the presentation mode this happens every time. With one or the other it never happens.
Still seeing this bug in iOS14. :( Submitted request through Feedback Assistant.
I also see this bug. Have Xcode Version 11.6 (11E708). Have people had luck in fixing it by canceling the swipe back feature?
I'm also having this problem. If the title displayMode is set to .large, the app even freezes and CPU runs 100%.
And also how do you make the the navigationBar with red color?

Edit: add .navigationViewStyle(StackNavigationViewStyle()) to the NavigationView seems to fix it for me.
Any progress on this? Still occurring for me. Hopefully a fix at WWDC 21

Edit: As stated above by @hongduongdang a fix is adding the following:

add .navigationViewStyle(StackNavigationViewStyle()) to the NavigationView seems to fix it for me.

It is worth noting this is still a bug and may not be the solution everyone wants as it could interfere with iPad style navigation within navigationView.
Cancel back gesture bug with NavigationView
 
 
Q