Skip to content

Commit

Permalink
Add FXIOS-9751 [Bookmarks evolution] Update bookmarks panel title wit…
Browse files Browse the repository at this point in the history
…h folder title (#23914)

* Update bookmarks panel title with folder title

* Remove unnecessary refactor flag
  • Loading branch information
lmarceau authored Dec 23, 2024
1 parent 04eb2ec commit 4bd067d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions BrowserKit/Sources/Shared/NotificationConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ extension Notification.Name {

public static let LibraryPanelStateDidChange = Notification.Name("LibraryPanelStateDidChange")

public static let LibraryPanelBookmarkTitleChanged = Notification.Name("LibraryPanelBookmarkTitleChanged")

public static let SearchSettingsChanged = Notification.Name("SearchSettingsChanged")

public static let SponsoredAndNonSponsoredSuggestionsChanged = Notification.Name("SponsoredAndNonSponsoredSuggestions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class BookmarksViewController: SiteTableViewController,
}

deinit {
NotificationCenter.default.removeObserver(self)
notificationCenter.removeObserver(self)
}

// MARK: - Lifecycle
Expand Down Expand Up @@ -149,10 +149,26 @@ class BookmarksViewController: SiteTableViewController,
self?.flashRow()
}
self?.updateEmptyState()
self?.updateParentViewControllerTitle()
}
}
}

private func updateParentViewControllerTitle() {
if !viewModel.isRootNode, let folderTitle = viewModel.bookmarkFolder?.title {
notificationCenter.post(name: .LibraryPanelBookmarkTitleChanged,
withObject: nil,
withUserInfo: ["title": folderTitle])
} else {
// This will set the title to the default one
notificationCenter.post(name: .LibraryPanelBookmarkTitleChanged,
withObject: nil,
withUserInfo: nil)
}
}

// MARK: - Actions

private func centerVisibleRow() -> Int {
let visibleCells = tableView.visibleCells
if let middleCell = visibleCells[safe: visibleCells.count / 2],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,17 @@ class LibraryViewController: UIViewController, Themeable, BookmarksRefactorFeatu
fatalError("init(coder:) has not been implemented")
}

deinit {
notificationCenter.removeObserver(self)
}

// MARK: - View setup & lifecycle
override func viewDidLoad() {
super.viewDidLoad()
viewSetup()
listenForThemeChange(view)
setupNotifications(forObserver: self, observing: [.LibraryPanelStateDidChange])
setupNotifications(forObserver: self,
observing: [.LibraryPanelStateDidChange, .LibraryPanelBookmarkTitleChanged])
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -135,8 +140,13 @@ class LibraryViewController: UIViewController, Themeable, BookmarksRefactorFeatu
updateSegmentControl()
}

fileprivate func updateTitle() {
if let newTitle = viewModel.selectedPanel?.title {
/// The Library title can be updated from some subpanels navigation actions
/// - Parameter subpanelTitle: The title coming from a subpanel, optional as by default we set the title to be
/// the selectedPanel.title
private func updateTitle(subpanelTitle: String? = nil) {
if let subpanelTitle {
navigationItem.title = subpanelTitle
} else if let newTitle = viewModel.selectedPanel?.title {
navigationItem.title = newTitle
}
}
Expand Down Expand Up @@ -380,6 +390,8 @@ extension LibraryViewController: Notifiable {
case .LibraryPanelStateDidChange:
setupButtons()
updateSegmentControl()
case .LibraryPanelBookmarkTitleChanged:
updateTitle(subpanelTitle: notification.userInfo?["title"] as? String)
default: break
}
}
Expand Down

0 comments on commit 4bd067d

Please sign in to comment.