NavigationBarHidden & swipe back

To enable swipe back in a view with the navigation bar hidden, we set the navigationController's interactivePopGestureRecognizer delegate. When returning to the main screen by swiping back and then entering detailView again, the screen freezes. This phenomenon occurs only in iOS 17. It works normally in iOS16. I am curious as to why this phenomenon occurs in iOS 17 and how to resolve it.

this is the sample code that we used.

struct ContentView: View {
	var body: some View {
		NavigationStack {
			NavigationLink(destination: DetailView()) {
				Text("Go to Detail")
			}
			.navigationTitle("Main")
		}
	}
}

struct DetailView: View {
	var body: some View {
		Text("Detail View")
			.toolbar(.hidden, for: .navigationBar)
	}
}

extension UINavigationController: UIGestureRecognizerDelegate {
	open override func viewDidLoad() {
		super.viewDidLoad()
		interactivePopGestureRecognizer?.delegate = self
	}
}

You may be getting the navigation controller’s gesture handling into some state that it’s not intended to handle. I had a similar (or perhaps the same) issue where when swiping back on the root screen (which doesn’t do anything obviously, but nevertheless is possible and as it turns out I do often while trying to scroll vertically), the controller will mess up the transition of the next navigation operation, appearing to 'freeze' until moved to the background and brought back. I solved this by implementing the gesture begin delegate method, and rejecting the gesture when on the root screen. Maybe worth trying for your case?

You can see an example of doing this here: https://github.com/siteline/swiftui-introspect/blob/main/Tests/UITestsHostApp/StatusBarStyle/NavigationView.swift#L42.

func gestureRecognizerShouldBegin(_: UIGestureRecognizer) -> Bool {
    viewControllers.count > 1
}

This (or similar bug we were facing) seem to be fixed in 17.4.1 at least

NavigationBarHidden & swipe back
 
 
Q