Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FXIOS-9751 [Bookmarks evolution] Update bookmarks panel title with folder title #23914

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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