Skip to content

Commit

Permalink
fix(privacy): Fix shred button visibility (uplift to 1.71.x) (#26091)
Browse files Browse the repository at this point in the history
Uplift of #26049 (squashed) to release
  • Loading branch information
brave-builds authored Oct 21, 2024
1 parent 17adfc0 commit 3fbf2fe
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ class TabTrayController: AuthenticationController {
tabTrayView.isHidden = tabTrayMode == .sync
tabSyncView.isHidden = tabTrayMode == .local

updateShredButtonVisibility()

searchBarView?.searchBar.placeholder =
tabTrayMode == .local
? Strings.tabTraySearchBarTitle : Strings.OpenTabs.tabTrayOpenTabSearchBarTitle
Expand Down Expand Up @@ -510,8 +512,6 @@ class TabTrayController: AuthenticationController {
}

shredButton.tintColor = browserColors.textPrimary
shredButton.isHidden = tabManager.selectedTab == nil && tabTrayMode == .local
shredButton.isEnabled = tabManager.selectedTab != nil || tabTrayMode == .local

// Need to force a relayout for the nav controller for the appearance to take affect
navigationController?.view.setNeedsLayout()
Expand Down Expand Up @@ -690,6 +690,11 @@ class TabTrayController: AuthenticationController {
}
}

private func updateShredButtonVisibility() {
let totalItems = dataSource.snapshot().numberOfItems
shredButton.isHidden = tabTrayMode == .sync || (privateMode && totalItems == 0)
}

// MARK: - Actions

@objc func doneAction() {
Expand Down Expand Up @@ -785,6 +790,8 @@ class TabTrayController: AuthenticationController {
tabManager.willSwitchTabMode(leavingPBM: privateMode)
privateMode.toggle()

updateShredButtonVisibility()

// When we switch from Private => Regular make sure we reset _selectedIndex, fix for bug #888
tabManager.resetSelectedIndex()
if privateMode {
Expand All @@ -795,6 +802,7 @@ class TabTrayController: AuthenticationController {
|| tabManager.tabsForCurrentMode.isEmpty
{
tabTrayView.showPrivateModeInfo()
updateShredButtonVisibility()
// New private tab is created immediately to reflect changes on NTP.
// If user drags the modal down or dismisses it, a new private tab will be ready.
tabManager.addTabAndSelect(isPrivate: true)
Expand All @@ -813,6 +821,7 @@ class TabTrayController: AuthenticationController {
}

tabTrayView.hidePrivateModeInfo()
updateShredButtonVisibility()
tabTrayView.collectionView.reloadData()

// When you go back from normal mode, current tab should be selected
Expand Down Expand Up @@ -950,6 +959,7 @@ extension TabTrayController: PresentingModalViewControllerDelegate {

extension TabTrayController: TabManagerDelegate {
func tabManager(_ tabManager: TabManager, didAddTab tab: Tab) {
updateShredButtonVisibility()
applySnapshot()

// This check is mainly for entering private mode.
Expand Down

0 comments on commit 3fbf2fe

Please sign in to comment.