Skip to content

Commit

Permalink
Refactor FXIOS-9085 Remove cell code (#22847)
Browse files Browse the repository at this point in the history
Remove cell code
  • Loading branch information
OrlaM authored Nov 1, 2024
1 parent 2febccb commit 34addeb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 442 deletions.
10 changes: 1 addition & 9 deletions firefox-ios/Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@
43B627762C3C001E00A188E8 /* ScanQRCode.strings in Resources */ = {isa = PBXBuildFile; fileRef = 43B627742C3C001E00A188E8 /* ScanQRCode.strings */; };
43B658D929CE251C00C9EF08 /* CreditCardInputViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43B658D829CE251C00C9EF08 /* CreditCardInputViewModelTests.swift */; };
43B966AF2BE8F11D007448EA /* Microsurvey.strings in Resources */ = {isa = PBXBuildFile; fileRef = 43B966AD2BE8F11D007448EA /* Microsurvey.strings */; };
43BDBBFE2752FA8600254DE4 /* LegacyTabCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43BDBBFD2752FA8600254DE4 /* LegacyTabCell.swift */; };
43BE5809278BA9D700491291 /* RustMozillaAppServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43BE578A278BA4D900491291 /* RustMozillaAppServices.framework */; };
43BE580E278BABCF00491291 /* RustMozillaAppServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43BE578A278BA4D900491291 /* RustMozillaAppServices.framework */; };
43BE5816278BE53E00491291 /* RustMozillaAppServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43BE578A278BA4D900491291 /* RustMozillaAppServices.framework */; };
Expand Down Expand Up @@ -813,7 +812,6 @@
8A6A796D27F773550022D6C6 /* HomepageContextMenuHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A6A796C27F773550022D6C6 /* HomepageContextMenuHelper.swift */; };
8A6B77CC2811C468001110D2 /* URLProtocolStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A6B77CB2811C468001110D2 /* URLProtocolStub.swift */; };
8A6E13982A71BA4E00A88FA8 /* TabWebViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A6E13972A71BA4E00A88FA8 /* TabWebViewTests.swift */; };
8A6E139C2A71BB5700A88FA8 /* LegacyTabCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A6E139B2A71BB5700A88FA8 /* LegacyTabCellTests.swift */; };
8A6E8DEB2B275BA9000C4301 /* PrivateHomepageViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A6E8DE92B275B49000C4301 /* PrivateHomepageViewControllerTests.swift */; };
8A720C5E2A4C85DA0003018A /* AccountSettingsDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A720C5D2A4C85DA0003018A /* AccountSettingsDelegate.swift */; };
8A720C602A4C8B700003018A /* SharedSettingsDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A720C5F2A4C8B700003018A /* SharedSettingsDelegate.swift */; };
Expand Down Expand Up @@ -5386,7 +5384,6 @@
43BDB3382991174F009C4BFF /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/JumpBackIn.strings; sourceTree = "<group>"; };
43BDB3392991174F009C4BFF /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/TabsTray.strings; sourceTree = "<group>"; };
43BDB33A2991174F009C4BFF /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/ToolbarLocation.strings; sourceTree = "<group>"; };
43BDBBFD2752FA8600254DE4 /* LegacyTabCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyTabCell.swift; sourceTree = "<group>"; };
43BDEEBE2947458800C2FD7E /* th */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = th; path = th.lproj/Alerts.strings; sourceTree = "<group>"; };
43BDEEBF2947458800C2FD7E /* th */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = th; path = th.lproj/TabsTray.strings; sourceTree = "<group>"; };
43BDEEC02947458800C2FD7E /* th */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = th; path = th.lproj/ToolbarLocation.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7076,7 +7073,6 @@
8A6A796C27F773550022D6C6 /* HomepageContextMenuHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomepageContextMenuHelper.swift; sourceTree = "<group>"; };
8A6B77CB2811C468001110D2 /* URLProtocolStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLProtocolStub.swift; sourceTree = "<group>"; };
8A6E13972A71BA4E00A88FA8 /* TabWebViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabWebViewTests.swift; sourceTree = "<group>"; };
8A6E139B2A71BB5700A88FA8 /* LegacyTabCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyTabCellTests.swift; sourceTree = "<group>"; };
8A6E8DE92B275B49000C4301 /* PrivateHomepageViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateHomepageViewControllerTests.swift; sourceTree = "<group>"; };
8A720C5D2A4C85DA0003018A /* AccountSettingsDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSettingsDelegate.swift; sourceTree = "<group>"; };
8A720C5F2A4C8B700003018A /* SharedSettingsDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedSettingsDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9626,8 +9622,6 @@
children = (
21DB34352B2103F0008CCB8E /* RemoteTabs */,
216E9A3829D2119300ABE69B /* LegacyInactiveTabs */,
43BDBBFD2752FA8600254DE4 /* LegacyTabCell.swift */,
968BD7EA27DFF0F8003148B3 /* ASGroup.swift */,
);
path = Legacy;
sourceTree = "<group>";
Expand Down Expand Up @@ -9879,6 +9873,7 @@
21C5B3592AF2A73F0093F366 /* State */,
21C5B3582AF2A7130093F366 /* Views */,
21B548942B1E5F1400DC1DF8 /* InactiveTabsManager.swift */,
968BD7EA27DFF0F8003148B3 /* ASGroup.swift */,
);
path = Tabs;
sourceTree = "<group>";
Expand Down Expand Up @@ -13743,7 +13738,6 @@
C889D7D32858CD4500121E1D /* HistoryHighlights */,
8A2825342760399B00395E66 /* KeyboardPressesHandlerTests.swift */,
8A5C3BC4282ABF8E003A8CCF /* LegacyRemoteTabsPanelTests.swift */,
8A6E139B2A71BB5700A88FA8 /* LegacyTabCellTests.swift */,
8AED868128CA3A1F00351A50 /* Library */,
C8445AD026443C7F00B83F53 /* LibraryPanelViewStateTests.swift */,
81DAB2EF2C88EFEE00F4BE98 /* MainMenu */,
Expand Down Expand Up @@ -15888,7 +15882,6 @@
8CE1E43A2B8C76C80026530B /* LoginListView.swift in Sources */,
8A832A9429DC99BA0025D5DD /* LaunchScreenViewController.swift in Sources */,
21E77E4E2AA8BA5200FABA10 /* TabTrayViewController.swift in Sources */,
43BDBBFE2752FA8600254DE4 /* LegacyTabCell.swift in Sources */,
E60D03181D511398002FE3F6 /* SyncDisplayState.swift in Sources */,
C4E3983D1D21F1E7004E89BA /* TopTabCell.swift in Sources */,
814B60F52C90C0A0000997BE /* MainMenuConfigurationUtility.swift in Sources */,
Expand Down Expand Up @@ -16751,7 +16744,6 @@
D815A3A824A53F3200AAB221 /* TabToolbarHelperTests.swift in Sources */,
967EDABF29D769A10089208D /* CreditCardInputFieldTests.swift in Sources */,
C8445AD126443C7F00B83F53 /* LibraryPanelViewStateTests.swift in Sources */,
8A6E139C2A71BB5700A88FA8 /* LegacyTabCellTests.swift in Sources */,
21F2A2D42B0D194A00626AEC /* TabsPanelStateTests.swift in Sources */,
8CFD56892AAF06D3003157A6 /* ShoppingProductTests.swift in Sources */,
8ACA8F7629198D6400D3075D /* ThrottlerTests.swift in Sources */,
Expand Down
106 changes: 0 additions & 106 deletions firefox-ios/Client/Frontend/Browser/TabDisplayManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,32 +324,6 @@ class LegacyTabDisplayManager: NSObject, FeatureFlaggable {
userInfo: tabManager.windowUUID.userInfo)
}

/// Find the previously selected cell, which is still displayed as selected
/// - Parameters:
/// - currentlySelected: The currently selected tab
/// - inSection: In which section should this tab be searched
/// - Returns: The index path of the found previously selected tab
private func indexOfCellDrawnAsPreviouslySelectedTab(currentlySelected: Tab?, inSection: Int) -> IndexPath? {
guard let currentlySelected = currentlySelected else { return nil }

for index in 0..<collectionView.numberOfItems(inSection: inSection) {
guard let cell = collectionView.cellForItem(
at: IndexPath(
row: index,
section: inSection
)
) as? LegacyTabTrayCell,
cell.isSelectedTab,
let tab = dataStore.at(index),
tab != currentlySelected
else { continue }

return IndexPath(row: index, section: inSection)
}

return nil
}

func refreshStore(evenIfHidden: Bool = false,
shouldAnimate: Bool = false,
completion: (() -> Void)? = nil) {
Expand Down Expand Up @@ -425,15 +399,6 @@ class LegacyTabDisplayManager: NSObject, FeatureFlaggable {
}
}

func undoCloseTab(tab: Tab, index: Int?) {
tabManager.undoCloseTab()
_ = profile.recentlyClosedTabs.popFirstTab()

refreshStore { [weak self] in
self?.updateCellFor(tab: tab, selectedTabChanged: true)
}
}

// When using 'Close All', hide all the tabs so they don't animate their deletion individually
func hideDisplayedTabs( completion: @escaping () -> Void) {
let cells = collectionView.visibleCells
Expand Down Expand Up @@ -860,69 +825,13 @@ extension LegacyTabDisplayManager: UICollectionViewDropDelegate {
extension LegacyTabDisplayManager: TabEventHandler {
var tabEventWindowResponseType: TabEventHandlerWindowResponseType { return .singleWindow(windowUUID) }

func tabDidSetScreenshot(_ tab: Tab, hasHomeScreenshot: Bool) {
guard let indexPath = getIndexPath(tab: tab) else { return }
refreshCell(atIndexPath: indexPath)
}

func tab(_ tab: Tab, didChangeURL url: URL) {
guard let indexPath = getIndexPath(tab: tab) else { return }
refreshCell(atIndexPath: indexPath)
}

private func getIndexPath(tab: Tab) -> IndexPath? {
guard let index = dataStore.index(of: tab) else { return nil }
let section = tabDisplayType == .TopTabTray ? 0 : TabDisplaySection.regularTabs.rawValue

return IndexPath(row: index, section: section)
}

private func updateCellFor(tab: Tab, selectedTabChanged: Bool) {
let selectedTab = tabManager.selectedTab

updateWith(animationType: .updateTab) { [weak self] in
guard let index = self?.dataStore.index(of: tab) else { return }
let section = self?.tabDisplayType == .TopTabTray ? 0 : TabDisplaySection.regularTabs.rawValue

var indexPaths = [IndexPath(row: index, section: section)]

if selectedTabChanged {
self?.tabDisplayerDelegate?.focusSelectedTab()

// Append the previously selected tab to refresh it's state. Useful when the selected tab has change.
// This method avoids relying on the state of the "previous" selected tab,
// instead it iterates the displayed tabs to see which appears selected.
if let previousSelectedIndexPath = self?.indexOfCellDrawnAsPreviouslySelectedTab(
currentlySelected: selectedTab,
inSection: section
) {
indexPaths.append(previousSelectedIndexPath)
}
}

for indexPath in indexPaths {
self?.refreshCell(atIndexPath: indexPath)

// Due to https://github.com/mozilla-mobile/firefox-ios/issues/9526 - Refresh next cell to avoid two selected cells
let nextTabIndex = IndexPath(row: indexPath.row + 1, section: indexPath.section)
self?.refreshCell(atIndexPath: nextTabIndex, forceUpdate: false)
}
}
}

private func refreshCell(atIndexPath indexPath: IndexPath, forceUpdate: Bool = true) {
guard let cell = collectionView.cellForItem(at: indexPath) as? LegacyTabTrayCell,
let tab = dataStore.at(indexPath.row) else { return }

// Only update from nextTabIndex if needed
guard forceUpdate || cell.isSelectedTab else { return }

let isSelected = tab == tabManager.selectedTab
cell.configureLegacyCellWith(tab: tab,
isSelected: isSelected,
theme: theme)
}

func removeAllTabsFromView() {
operations.removeAll()
dataStore.removeAll()
Expand All @@ -932,21 +841,6 @@ extension LegacyTabDisplayManager: TabEventHandler {

// MARK: - TabManagerDelegate
extension LegacyTabDisplayManager: TabManagerDelegate {
func tabManager(_ tabManager: TabManager, didSelectedTabChange selectedTab: Tab, previousTab: Tab?, isRestoring: Bool) {
cancelDragAndGestures()

// A tab can be re-selected during deletion
let changedTab = selectedTab != previousTab
updateCellFor(tab: selectedTab, selectedTabChanged: changedTab)

// Rather than using 'previous' Tab to deselect, just check if the selected tab
// is different, and update the required cells. The refreshStore() cancels
// pending operations are reloads data, so we don't want functions that rely on
// any assumption of previous state of the view. Passing a previous tab (and
// relying on that to redraw the previous tab as unselected) would be making
// this assumption about the state of the view.
}

func tabManager(
_ tabManager: TabManager,
didAddTab tab: Tab,
Expand Down
Loading

0 comments on commit 34addeb

Please sign in to comment.