Fix crash when trying to remove popped view controller that doesn't exist

This commit is contained in:
Shadowfacts 2023-05-10 11:04:56 -04:00
parent f13874ee01
commit 85765928b4
1 changed files with 4 additions and 2 deletions

View File

@ -141,13 +141,15 @@ class EnhancedNavigationViewController: UINavigationController {
if self.interactivePushTransition.interactive { if self.interactivePushTransition.interactive {
// when an interactive push gesture is cancelled, make sure to adding the VC that was being pushed back onto the popped stack so it doesn't disappear // when an interactive push gesture is cancelled, make sure to adding the VC that was being pushed back onto the popped stack so it doesn't disappear
self.poppedViewControllers.insert(self.interactivePushTransition.pushingViewController!, at: 0) self.poppedViewControllers.insert(self.interactivePushTransition.pushingViewController!, at: 0)
} else { } else if self.interactivePopGestureRecognizer?.state == .ended {
// when an interactive pop gesture is cancelled (i.e. the user lifts their finger before it triggers), // when an interactive pop gesture is cancelled (i.e. the user lifts their finger before it triggers),
// the popViewController(animated:) method has already been called so the VC has already been added to the popped stack // the popViewController(animated:) method has already been called so the VC has already been added to the popped stack
// so we make sure to remove it, otherwise there could be duplicate VCs on the navigation stasck // so we make sure to remove it, otherwise there could be duplicate VCs on the navigation stasck
if !self.poppedViewControllers.isEmpty {
self.poppedViewControllers.remove(at: 0) self.poppedViewControllers.remove(at: 0)
} }
} }
}
}) })
} }