diff --git a/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift b/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift index c8498a3c341e..4d98b98a6f3d 100644 --- a/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift +++ b/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift @@ -569,13 +569,16 @@ class BrowserCoordinator: BaseCoordinator, } private func makeMenuNavViewController() -> DismissableNavigationViewController? { - guard !childCoordinators.contains(where: { $0 is MainMenuCoordinator }) else { + if let mainMenuCoordinator = childCoordinators.first(where: { $0 is MainMenuCoordinator }) as? MainMenuCoordinator { logger.log( - "MainMenuCoordinator already exists when it technically shouldn't", + "MainMenuCoordinator already exists when it shouldn't. Removing and recreating it to access menu", level: .fatal, - category: .mainMenu + category: .mainMenu, + extra: ["existing mainMenuCoordinator UUID": "\(mainMenuCoordinator.windowUUID)", + "BrowserCoordinator windowUUID": "\(windowUUID)"] ) - return nil + + mainMenuCoordinator.dismissMenuModal(animated: false) } let navigationController = DismissableNavigationViewController() diff --git a/firefox-ios/Client/Frontend/Browser/MainMenu/MainMenuCoordinator.swift b/firefox-ios/Client/Frontend/Browser/MainMenu/MainMenuCoordinator.swift index c858427d48c1..f37f76a56352 100644 --- a/firefox-ios/Client/Frontend/Browser/MainMenu/MainMenuCoordinator.swift +++ b/firefox-ios/Client/Frontend/Browser/MainMenu/MainMenuCoordinator.swift @@ -23,7 +23,7 @@ class MainMenuCoordinator: BaseCoordinator, FeatureFlaggable { weak var parentCoordinator: ParentCoordinatorDelegate? weak var navigationHandler: MainMenuCoordinatorDelegate? - private let windowUUID: WindowUUID + let windowUUID: WindowUUID private let profile: Profile init( @@ -36,6 +36,14 @@ class MainMenuCoordinator: BaseCoordinator, FeatureFlaggable { super.init(router: router) } + deinit { + logger.log( + "MainMenuCoordinator - deinitialized", + level: .info, + category: .mainMenu + ) + } + func start() { logger.log( "MainMenuCoordinator - started", @@ -69,6 +77,15 @@ class MainMenuCoordinator: BaseCoordinator, FeatureFlaggable { router.popViewController(animated: true) } + func removeCoordinatorFromParent() { + logger.log( + "MainMenuCoordinator - removing coordinator from parent", + level: .info, + category: .mainMenu + ) + parentCoordinator?.didFinish(from: self) + } + func dismissMenuModal(animated: Bool) { logger.log( "MainMenuCoordinator - dismissing main menu", @@ -76,7 +93,7 @@ class MainMenuCoordinator: BaseCoordinator, FeatureFlaggable { category: .mainMenu ) router.dismiss(animated: animated, completion: nil) - parentCoordinator?.didFinish(from: self) + removeCoordinatorFromParent() } func navigateTo(_ destination: MenuNavigationDestination, animated: Bool) { @@ -119,7 +136,7 @@ class MainMenuCoordinator: BaseCoordinator, FeatureFlaggable { self.navigationHandler?.updateZoomPageBarVisibility() } - self.parentCoordinator?.didFinish(from: self) + removeCoordinatorFromParent() }) } diff --git a/firefox-ios/Client/Frontend/Browser/MainMenu/Views/MainMenuViewController.swift b/firefox-ios/Client/Frontend/Browser/MainMenu/Views/MainMenuViewController.swift index 605f7bed74cd..03458f853814 100644 --- a/firefox-ios/Client/Frontend/Browser/MainMenu/Views/MainMenuViewController.swift +++ b/firefox-ios/Client/Frontend/Browser/MainMenu/Views/MainMenuViewController.swift @@ -403,7 +403,7 @@ class MainMenuViewController: UIViewController, currentTabInfo: menuState.currentTabInfo ) ) - coordinator?.dismissMenuModal(animated: true) + coordinator?.removeCoordinatorFromParent() } // MARK: - UISheetPresentationControllerDelegate