From 85765928b4591bc1853c426f3ee4dd01f87bc1c0 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 10 May 2023 11:04:56 -0400 Subject: [PATCH] Fix crash when trying to remove popped view controller that doesn't exist --- .../Utilities/EnhancedNavigationViewController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tusker/Screens/Utilities/EnhancedNavigationViewController.swift b/Tusker/Screens/Utilities/EnhancedNavigationViewController.swift index 4de68a3f..bfe74313 100644 --- a/Tusker/Screens/Utilities/EnhancedNavigationViewController.swift +++ b/Tusker/Screens/Utilities/EnhancedNavigationViewController.swift @@ -141,11 +141,13 @@ class EnhancedNavigationViewController: UINavigationController { 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 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), // 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 - self.poppedViewControllers.remove(at: 0) + if !self.poppedViewControllers.isEmpty { + self.poppedViewControllers.remove(at: 0) + } } } })