From bba8c8951ce7ea8238eee072d7b6ffd86ba744d3 Mon Sep 17 00:00:00 2001 From: "roux g. buciu" <11182210+adudenamedruby@users.noreply.github.com> Date: Fri, 29 Nov 2024 09:56:18 -0500 Subject: [PATCH] Bugfix FXIOS-10437 [Menu] Attempt fix for menu coordinator bug (#23458) * Attempt fix * swifliiiiiint (cherry picked from commit b421b9a2722ff06de0c71837b54dd6880689834d) --- .../Browser/BrowserCoordinator.swift | 11 +++++---- .../MainMenu/MainMenuCoordinator.swift | 23 ++++++++++++++++--- .../Views/MainMenuViewController.swift | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift b/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift index 8b8ae2278d64..a23d1193673d 100644 --- a/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift +++ b/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift @@ -542,13 +542,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