Skip to content

Commit

Permalink
Refactor FXIOS-6922 [v120] Create a tab display view to share with re…
Browse files Browse the repository at this point in the history
…gular and private tabs screens (#16646)
  • Loading branch information
yoanarios authored Oct 2, 2023
1 parent 540bc34 commit 685c65d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 40 deletions.
12 changes: 8 additions & 4 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@
2137786529832C8900D01309 /* OverlayModeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2137786429832C8900D01309 /* OverlayModeManager.swift */; };
213B67A627CE682B000542F5 /* StartAtHomeHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B67A527CE682B000542F5 /* StartAtHomeHelper.swift */; };
213B67A827CE721E000542F5 /* StartAtHomeHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B67A727CE721E000542F5 /* StartAtHomeHelperTests.swift */; };
213BF7532AC21D1B00C53A64 /* TabCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213BF7522AC21D1B00C53A64 /* TabCollectionViewController.swift */; };
213BF7532AC21D1B00C53A64 /* TabDisplayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213BF7522AC21D1B00C53A64 /* TabDisplayViewController.swift */; };
21420EF72ABA338D00B28550 /* TabTrayCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21420EF62ABA338D00B28550 /* TabTrayCoordinator.swift */; };
21420EF92ABC75A400B28550 /* TabTrayCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21420EF82ABC75A400B28550 /* TabTrayCoordinatorTests.swift */; };
214EF4152AC5D5D0005BCCDA /* TabDisplayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 214EF4142AC5D5D0005BCCDA /* TabDisplayView.swift */; };
21534904288201E300FADB4D /* GleanPlumbMessageManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 215349022881FA3C00FADB4D /* GleanPlumbMessageManagerTests.swift */; };
215349062886007900FADB4D /* GleanPlumbMessageStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 215349052886007900FADB4D /* GleanPlumbMessageStoreTests.swift */; };
215B457F27D7FD4B00E5E800 /* LegacyTabGroupData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 215B457E27D7FD4B00E5E800 /* LegacyTabGroupData.swift */; };
Expand Down Expand Up @@ -2121,9 +2122,10 @@
2137786429832C8900D01309 /* OverlayModeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverlayModeManager.swift; sourceTree = "<group>"; };
213B67A527CE682B000542F5 /* StartAtHomeHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartAtHomeHelper.swift; sourceTree = "<group>"; };
213B67A727CE721E000542F5 /* StartAtHomeHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartAtHomeHelperTests.swift; sourceTree = "<group>"; };
213BF7522AC21D1B00C53A64 /* TabCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabCollectionViewController.swift; sourceTree = "<group>"; };
213BF7522AC21D1B00C53A64 /* TabDisplayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabDisplayViewController.swift; sourceTree = "<group>"; };
21420EF62ABA338D00B28550 /* TabTrayCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabTrayCoordinator.swift; sourceTree = "<group>"; };
21420EF82ABC75A400B28550 /* TabTrayCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabTrayCoordinatorTests.swift; sourceTree = "<group>"; };
214EF4142AC5D5D0005BCCDA /* TabDisplayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabDisplayView.swift; sourceTree = "<group>"; };
215349022881FA3C00FADB4D /* GleanPlumbMessageManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GleanPlumbMessageManagerTests.swift; sourceTree = "<group>"; };
215349052886007900FADB4D /* GleanPlumbMessageStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GleanPlumbMessageStoreTests.swift; sourceTree = "<group>"; };
215B457E27D7FD4B00E5E800 /* LegacyTabGroupData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyTabGroupData.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7342,7 +7344,8 @@
21E77E4D2AA8BA5200FABA10 /* TabTrayViewController.swift */,
21E77E4F2AA8BAEC00FABA10 /* TabTrayModel.swift */,
21E77E512AA8BE5C00FABA10 /* TabTrayFlagManager.swift */,
213BF7522AC21D1B00C53A64 /* TabCollectionViewController.swift */,
213BF7522AC21D1B00C53A64 /* TabDisplayViewController.swift */,
214EF4142AC5D5D0005BCCDA /* TabDisplayView.swift */,
);
path = Tabs;
sourceTree = "<group>";
Expand Down Expand Up @@ -12789,9 +12792,10 @@
E18F44072A951C330056160F /* FakespotHighlightGroup.swift in Sources */,
D5D0532E2645B3A700759F85 /* ExperimentsTableView.swift in Sources */,
8A832A9029DC96C50025D5DD /* LaunchScreenView.swift in Sources */,
214EF4152AC5D5D0005BCCDA /* TabDisplayView.swift in Sources */,
2165B2C22860C2F4004C0786 /* AdjustTelemetryHelper.swift in Sources */,
8A2D593E27DC0AA100713EC9 /* TopSite.swift in Sources */,
213BF7532AC21D1B00C53A64 /* TabCollectionViewController.swift in Sources */,
213BF7532AC21D1B00C53A64 /* TabDisplayViewController.swift in Sources */,
434E733725EED32E006D3BDE /* BrowserViewController+URLBarDelegate.swift in Sources */,
C88E7A5B2A0553510072E638 /* OnboardingLinkInfoModel.swift in Sources */,
2137785F297F3B1B00D01309 /* DownloadsPanelViewModel.swift in Sources */,
Expand Down
78 changes: 78 additions & 0 deletions Client/Frontend/Browser/Tabs/TabDisplayView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Common
import UIKit

class TabDisplayView: UIView,
ThemeApplicable,
UICollectionViewDataSource,
UICollectionViewDelegate,
UICollectionViewDragDelegate,
UICollectionViewDropDelegate {
enum UX {}

lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: .zero,
collectionViewLayout: UICollectionViewFlowLayout())
collectionView.register(cellType: LegacyTabCell.self)

collectionView.alwaysBounceVertical = true
collectionView.keyboardDismissMode = .onDrag
collectionView.dragInteractionEnabled = true
// TODO: FXIOS-6926 Create TabDisplayManager and update delegates
collectionView.dragDelegate = self
collectionView.dropDelegate = self
collectionView.dataSource = self
collectionView.delegate = self
return collectionView
}()

override init(frame: CGRect) {
super.init(frame: frame)
setupLayout()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupLayout() {
addSubview(collectionView)

NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: topAnchor),
collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
collectionView.bottomAnchor.constraint(equalTo: bottomAnchor),
collectionView.trailingAnchor.constraint(equalTo: trailingAnchor)
])
}

func applyTheme(theme: Theme) {
collectionView.backgroundColor = theme.colors.layer3
}

// MARK: UICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LegacyTabCell.cellIdentifier, for: indexPath)

return cell
}

// MARK: UICollectionViewDragDelegate
func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let itemProvider = NSItemProvider()

let dragItem = UIDragItem(itemProvider: itemProvider)
return [dragItem]
}

// MARK: UICollectionViewDropDelegate
func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Common
import UIKit

class TabCollectionViewController: UIViewController,
class TabDisplayViewController: UIViewController,
Themeable {
struct UX {}

Expand All @@ -15,7 +15,7 @@ class TabCollectionViewController: UIViewController,

// MARK: UI elements
private var backgroundPrivacyOverlay: UIView = .build { _ in }
private var collectionView: UICollectionView!
private var tabDisplayView: TabDisplayView = .build { _ in }

// Redux state
var isPrivateMode: Bool
Expand All @@ -42,52 +42,26 @@ class TabCollectionViewController: UIViewController,
}

private func setupView() {
setupCollectionView()
view.addSubview(collectionView)
view.addSubview(tabDisplayView)
view.addSubview(backgroundPrivacyOverlay)

NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tabDisplayView.topAnchor.constraint(equalTo: view.topAnchor),
tabDisplayView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tabDisplayView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
tabDisplayView.trailingAnchor.constraint(equalTo: view.trailingAnchor),

backgroundPrivacyOverlay.topAnchor.constraint(equalTo: view.topAnchor),
backgroundPrivacyOverlay.leadingAnchor.constraint(equalTo: view.leadingAnchor),
backgroundPrivacyOverlay.bottomAnchor.constraint(equalTo: view.bottomAnchor),
backgroundPrivacyOverlay.trailingAnchor.constraint(equalTo: view.trailingAnchor),
backgroundPrivacyOverlay.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])

backgroundPrivacyOverlay.isHidden = !isPrivateMode
// TODO: Empty private tabs view FXIOS-6925
}

private func setupCollectionView() {
collectionView = UICollectionView(frame: .zero,
collectionViewLayout: UICollectionViewFlowLayout())
collectionView.register(cellType: LegacyTabCell.self)

// TODO: FXIOS-6926 Create TabDisplayManager and update delegates
collectionView.dataSource = self
collectionView.delegate = self
}

func applyTheme() {
backgroundPrivacyOverlay.backgroundColor = themeManager.currentTheme.colors.layerScrim
collectionView.backgroundColor = themeManager.currentTheme.colors.layer3
}
}

// TODO: Remove once FXIOS-6926 is done
extension TabCollectionViewController: UICollectionViewDataSource,
UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LegacyTabCell.cellIdentifier, for: indexPath)

return cell
}
}
4 changes: 2 additions & 2 deletions Client/Frontend/Browser/Tabs/TabTrayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ class TabTrayViewController: UIViewController,
private func getChildViewController() -> UIViewController {
switch selectedSegment {
case .tabs:
return TabCollectionViewController(isPrivateMode: false)
return TabDisplayViewController(isPrivateMode: false)
case .privateTabs:
return TabCollectionViewController(isPrivateMode: true)
return TabDisplayViewController(isPrivateMode: true)
// TODO: FXIOS-6921 Integrate synctab View Controller
default: return UIViewController()
}
Expand Down

0 comments on commit 685c65d

Please sign in to comment.