Skip to content

Commit

Permalink
properly dismiss and remove child coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
MattLichtenstein committed Dec 20, 2024
1 parent 78b6213 commit f4e62f9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
12 changes: 7 additions & 5 deletions firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down

0 comments on commit f4e62f9

Please sign in to comment.