From f4e62f95b1a1ab393686fc6fc8071f679a5867cb Mon Sep 17 00:00:00 2001 From: mattlichtenstein Date: Fri, 20 Dec 2024 14:20:28 -0500 Subject: [PATCH] properly dismiss and remove child coordinator --- .../Coordinators/Browser/BrowserCoordinator.swift | 12 +++++++----- .../Coordinators/Library/BookmarksCoordinator.swift | 2 +- .../Coordinators/Library/LibraryCoordinator.swift | 2 +- .../Views/BrowserViewController.swift | 4 +--- .../Edit Bookmark/EditBookmarkViewController.swift | 9 ++++----- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift b/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift index 3207a8dadfa07..3fbfd48bf4903 100644 --- a/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift +++ b/firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift @@ -176,7 +176,7 @@ class BrowserCoordinator: BaseCoordinator, modalStyle: .overFullScreen) let sheet = PhotonActionSheet(viewModel: viewModel, windowUUID: windowUUID) sheet.modalTransitionStyle = .crossDissolve - present(sheet, animated: true) + present(sheet) } func showEditBookmark(parentFolder: FxBookmarkNode, bookmark: FxBookmarkNode) { @@ -192,6 +192,10 @@ class BrowserCoordinator: BaseCoordinator, ) add(child: bookmarksCoordinator) bookmarksCoordinator.start(parentFolder: parentFolder, bookmark: bookmark) + navigationController.onViewDismissed = { [weak self] in + // Remove coordinator when user drags down to dismiss modal + self?.didFinish(from: bookmarksCoordinator) + } present(navigationController) } @@ -515,7 +519,7 @@ class BrowserCoordinator: BaseCoordinator, return windowUUID } - func didFinishLibrary(from coordinator: LibraryCoordinator) { + func didFinishLibrary(from coordinator: Coordinator) { router.dismiss(animated: true, completion: nil) remove(child: coordinator) } @@ -1010,9 +1014,7 @@ class BrowserCoordinator: BaseCoordinator, controller.sheetPresentationController?.selectedDetentIdentifier = .large } - private func present(_ viewController: UIViewController, - animated: Bool = true, - completion: (() -> Void)? = nil) { + private func present(_ viewController: UIViewController) { browserViewController.willNavigateAway() router.present(viewController) } diff --git a/firefox-ios/Client/Coordinators/Library/BookmarksCoordinator.swift b/firefox-ios/Client/Coordinators/Library/BookmarksCoordinator.swift index 0629f55c4a6f2..b2b8e9b7a8eb3 100644 --- a/firefox-ios/Client/Coordinators/Library/BookmarksCoordinator.swift +++ b/firefox-ios/Client/Coordinators/Library/BookmarksCoordinator.swift @@ -148,7 +148,7 @@ class BookmarksCoordinator: BaseCoordinator, } func didFinish() { - (libraryCoordinator as? BrowserCoordinator)?.didFinish(from: self) + libraryCoordinator?.didFinishLibrary(from: self) } func shareLibraryItem(url: URL, sourceView: UIView) { diff --git a/firefox-ios/Client/Coordinators/Library/LibraryCoordinator.swift b/firefox-ios/Client/Coordinators/Library/LibraryCoordinator.swift index abdbe3ad1a6da..c767df64b2154 100644 --- a/firefox-ios/Client/Coordinators/Library/LibraryCoordinator.swift +++ b/firefox-ios/Client/Coordinators/Library/LibraryCoordinator.swift @@ -10,7 +10,7 @@ import Storage import enum MozillaAppServices.VisitType protocol LibraryCoordinatorDelegate: AnyObject, LibraryPanelDelegate, RecentlyClosedPanelDelegate { - func didFinishLibrary(from coordinator: LibraryCoordinator) + func didFinishLibrary(from coordinator: Coordinator) } protocol LibraryNavigationHandler: AnyObject { diff --git a/firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift b/firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift index 5f9acee2ae153..66b10a819d58d 100644 --- a/firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift +++ b/firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift @@ -1689,9 +1689,7 @@ class BrowserViewController: UIViewController, } } - /// This function will open a view separate from the bookmark edit panel found in the - /// Library Panel - Bookmarks section. - /// Library Panel - Bookmarks section. + /// This function opens a standalone bookmark edit view separate from library -> bookmarks panel -> edit bookmark. internal func openBookmarkEditPanel() { guard !profile.isShutdown else { return } diff --git a/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Bookmark/EditBookmarkViewController.swift b/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Bookmark/EditBookmarkViewController.swift index bc577ed37def1..dbcc53a9a8ab8 100644 --- a/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Bookmark/EditBookmarkViewController.swift +++ b/firefox-ios/Client/Frontend/Library/Bookmarks/Edit Bookmark/EditBookmarkViewController.swift @@ -108,12 +108,11 @@ class EditBookmarkViewController: UIViewController, if let isDragging = transitionCoordinator?.isInteractive, !isDragging { navigationController?.setNavigationBarHidden(true, animated: true) } - // Save when popping the view off the navigation stack + // Save when popping the view off the navigation stack (when in library) if isMovingFromParent { viewModel.saveBookmark() } onViewWillDisappear?() - viewModel.didFinish() } // MARK: - Setup @@ -132,12 +131,12 @@ class EditBookmarkViewController: UIViewController, @objc func saveButtonAction() { - // Check if this is the root view controller so we can save before dismissing + // If we are in the standalone version of edit bookmark, we should save before dismissing if navigationController?.viewControllers.first == self { viewModel.saveBookmark() - self.dismiss(animated: true) + viewModel.didFinish() } else { - // Save will happen in viewWillDisappear + // If we are in the library, save will happen in viewWillDisappear navigationController?.popViewController(animated: true) } }