Skip to content

Commit

Permalink
Remove old datasource and use the new one
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Amin authored and Sophie Amin committed Sep 18, 2024
1 parent 8bf098c commit c98f8c9
Showing 1 changed file with 2 additions and 104 deletions.
106 changes: 2 additions & 104 deletions firefox-ios/Client/Frontend/Browser/Tabs/Views/TabDisplayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import UIKit

class TabDisplayView: UIView,
ThemeApplicable,
UICollectionViewDataSource,
UICollectionViewDelegate,
UICollectionViewDelegateFlowLayout,
TabCellDelegate,
Expand Down Expand Up @@ -82,7 +81,6 @@ class TabDisplayView: UIView,
collectionView.alwaysBounceVertical = true
collectionView.keyboardDismissMode = .onDrag
collectionView.dragInteractionEnabled = true
collectionView.dataSource = self
collectionView.delegate = self
collectionView.dragDelegate = self
collectionView.dropDelegate = self
Expand Down Expand Up @@ -192,6 +190,7 @@ class TabDisplayView: UIView,
super.init(frame: .zero)
self.inactiveTabsSectionManager.delegate = self
setupLayout()
configureDataSource()
}

required init?(coder: NSCoder) {
Expand All @@ -201,7 +200,7 @@ class TabDisplayView: UIView,
func newState(state: TabsPanelState) {
tabsState = state

collectionView.reloadData()
updateCollectionView(state: tabsState)

if let index = state.scrollToIndex {
scrollToTab(index)
Expand Down Expand Up @@ -310,107 +309,6 @@ class TabDisplayView: UIView,
store.dispatch(action)
}

// MARK: UICollectionViewDataSource
func numberOfSections(in collectionView: UICollectionView) -> Int {
guard !tabsState.isPrivateTabsEmpty else { return 0 }

guard !shouldHideInactiveTabs else { return 1 }

return TabDisplaySection.allCases.count
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch getTabDisplay(for: section) {
case .inactiveTabs:
return tabsState.isInactiveTabsExpanded ? tabsState.inactiveTabs.count : 0
case .tabs:
guard !tabsState.tabs.isEmpty else { return 0 }

return tabsState.tabs.count
}
}

// SOPHIE - remove when diffable datasource is implemented
func collectionView(_ collectionView: UICollectionView,
viewForSupplementaryElementOfKind kind: String,
at indexPath: IndexPath)
-> UICollectionReusableView {
let reusableView = UICollectionReusableView()
switch getTabDisplay(for: indexPath.section) {
case .inactiveTabs:
if kind == UICollectionView.elementKindSectionHeader,
let view = collectionView.dequeueReusableSupplementaryView(
ofKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: InactiveTabsHeaderView.cellIdentifier,
for: indexPath) as? InactiveTabsHeaderView {
view.state = tabsState.isInactiveTabsExpanded ? .down : .trailing
if let theme = theme {
view.applyTheme(theme: theme)
}
view.moreButton.isHidden = false
view.moreButton.addTarget(self,
action: #selector(toggleInactiveTab),
for: .touchUpInside)
view.accessibilityLabel = tabsState.isInactiveTabsExpanded ?
.TabsTray.InactiveTabs.TabsTrayInactiveTabsSectionOpenedAccessibilityTitle :
.TabsTray.InactiveTabs.TabsTrayInactiveTabsSectionClosedAccessibilityTitle
let tapGestureRecognizer = UITapGestureRecognizer(target: self,
action: #selector(toggleInactiveTab))
view.addGestureRecognizer(tapGestureRecognizer)
return view
} else if kind == UICollectionView.elementKindSectionFooter,
tabsState.isInactiveTabsExpanded,
let footerView = collectionView.dequeueReusableSupplementaryView(
ofKind: UICollectionView.elementKindSectionFooter,
withReuseIdentifier: InactiveTabsFooterView.cellIdentifier,
for: indexPath) as? InactiveTabsFooterView {
if let theme = theme {
footerView.applyTheme(theme: theme)
}
footerView.buttonClosure = {
let action = TabPanelViewAction(panelType: self.panelType,
windowUUID: self.windowUUID,
actionType: TabPanelViewActionType.closeAllInactiveTabs)
store.dispatch(action)
}
return footerView
}

default: return reusableView
}
return reusableView
}

// Comment out when diffable datasource is completed
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath)
-> UICollectionViewCell {
switch getTabDisplay(for: indexPath.section) {
case .inactiveTabs:
guard let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: InactiveTabsCell.cellIdentifier,
for: indexPath
) as? InactiveTabsCell
else { return UICollectionViewCell() }

cell.configure(with: tabsState.inactiveTabs[indexPath.row])
if let theme = theme {
cell.applyTheme(theme: theme)
}
return cell
case .tabs:
guard let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: TabCell.cellIdentifier,
for: indexPath
) as? TabCell
else { return UICollectionViewCell() }

let tabState = tabsState.tabs[indexPath.row]
cell.configure(with: tabState, theme: theme, delegate: self)
return cell
}
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
switch getTabDisplay(for: indexPath.section) {
case .inactiveTabs:
Expand Down

0 comments on commit c98f8c9

Please sign in to comment.