Skip to content

Commit

Permalink
be more explicit about the disabling the swipe coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Jan 29, 2024
1 parent c08d73d commit c570744
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
64 changes: 45 additions & 19 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ class MainViewController: UIViewController {
viewCoordinator.toolbarForwardButton.action = #selector(onForwardPressed)
viewCoordinator.toolbarFireButton.action = #selector(onFirePressed)

// configureSwipeTabsIfEnabled()
disableSwipeTabs()

installSwipeTabs()

loadSuggestionTray()
loadTabsBarIfNeeded()
loadFindInPage()
Expand Down Expand Up @@ -303,10 +302,31 @@ class MainViewController: UIViewController {
super.performSegue(withIdentifier: identifier, sender: sender)
}

private func installSwipeTabs() {
guard swipeTabsCoordinator == nil else { return }

swipeTabsCoordinator = SwipeTabsCoordinator(coordinator: viewCoordinator,
tabPreviewsSource: previewsSource,
appSettings: appSettings) { [weak self] in
self?.select(tabAt: $0)
} onSwipeStarted: { [weak self] in
guard let self, let currentTab = self.tabManager.current() else { return }
hideKeyboard()
currentTab.preparePreview(completion: { image in
guard let image else { return }
self.previewsSource.update(preview: image,
forTab: currentTab.tabModel)
})
}

viewCoordinator.navigationBarContainer.dataSource = swipeTabsCoordinator
viewCoordinator.navigationBarContainer.delegate = swipeTabsCoordinator
}

private func enableSwipeTabs() {
// This guard can be removed once the feature is enabled permanently.
guard featureFlagger.isFeatureOn(.swipeTabs) else {
disableSwipeTabs()
// disableSwipeTabs()
return
}

Expand All @@ -330,22 +350,25 @@ class MainViewController: UIViewController {

viewCoordinator.navigationBarContainer.dataSource = swipeTabsCoordinator
viewCoordinator.navigationBarContainer.delegate = swipeTabsCoordinator
swipeTabsCoordinator?.refresh(tabsModel: self.tabManager.model, scrollToSelected: true)
}

private func disableSwipeTabs() {
swipeTabsCoordinator = nil

viewCoordinator.omniBar.removeFromSuperview()
viewCoordinator.omniBar.translatesAutoresizingMaskIntoConstraints = true
viewCoordinator.omniBar.frame = CGRect(origin: .zero, size: viewCoordinator.navigationBarContainer.frame.size)
viewCoordinator.navigationBarContainer.addSubview(viewCoordinator.omniBar)

if !self.appSettings.currentAddressBarPosition.isBottom {
viewCoordinator.omniBar.showSeparator()
viewCoordinator.omniBar.moveSeparatorToBottom()
if let model = self.tabManager?.model {
swipeTabsCoordinator?.refresh(tabsModel: model, scrollToSelected: true)
}
}

// private func disableSwipeTabs() {
// swipeTabsCoordinator = nil
//
// viewCoordinator.omniBar.removeFromSuperview()
// viewCoordinator.omniBar.translatesAutoresizingMaskIntoConstraints = true
// viewCoordinator.omniBar.frame = CGRect(origin: .zero, size: viewCoordinator.navigationBarContainer.frame.size)
// viewCoordinator.navigationBarContainer.addSubview(viewCoordinator.omniBar)
//
// if !self.appSettings.currentAddressBarPosition.isBottom {
// viewCoordinator.omniBar.showSeparator()
// viewCoordinator.omniBar.moveSeparatorToBottom()
// }
// }

func loadSuggestionTray() {
let storyboard = UIStoryboard(name: "SuggestionTray", bundle: nil)
Expand Down Expand Up @@ -1101,15 +1124,18 @@ class MainViewController: UIViewController {
viewCoordinator.toolbar.isHidden = true
viewCoordinator.omniBar.enterPadState()

disableSwipeTabs()
swipeTabsCoordinator?.isEnabled = false
// disableSwipeTabs()
}

private func applySmallWidth() {
viewCoordinator.tabBarContainer.isHidden = true
viewCoordinator.toolbar.isHidden = false
viewCoordinator.omniBar.enterPhoneState()

enableSwipeTabs()
swipeTabsCoordinator?.isEnabled = featureFlagger.isFeatureOn(.swipeTabs)

// enableSwipeTabs()
}

@discardableResult
Expand Down
12 changes: 10 additions & 2 deletions DuckDuckGo/SwipeTabsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class SwipeTabsCoordinator: NSObject {
let selectTab: (Int) -> Void
let onSwipeStarted: () -> Void

var isEnabled = false {
didSet {
coordinator.navigationBarContainer.reloadData()
}
}

init(coordinator: MainViewCoordinator,
tabPreviewsSource: TabPreviewsSource,
appSettings: AppSettings,
Expand Down Expand Up @@ -85,6 +91,8 @@ class SwipeTabsCoordinator: NSObject {
}

private func scrollToCurrent(animated: Bool = false) {
guard isEnabled else { return }

print("***", #function, animated)
DispatchQueue.main.async {
let indexPath = IndexPath(row: self.tabsModel.currentIndex, section: 0)
Expand Down Expand Up @@ -216,15 +224,15 @@ extension SwipeTabsCoordinator {
extension SwipeTabsCoordinator: UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return tabsModel?.count ?? 0
return isEnabled ? tabsModel?.count ?? 0 : 1
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "omnibar", for: indexPath) as? OmniBarCell else {
fatalError("Not \(OmniBarCell.self)")
}

if tabsModel.currentIndex == indexPath.row {
if !isEnabled || tabsModel.currentIndex == indexPath.row {
cell.omniBar = coordinator.omniBar
} else {
cell.insetsLayoutMarginsFromSafeArea = true
Expand Down
6 changes: 6 additions & 0 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1453,17 +1453,23 @@ extension TabViewController: WKNavigationDelegate {
|| !ContentBlocking.shared.privacyConfigurationManager.privacyConfig.isEnabled(featureKey: .contentBlocking) {

rulesCompilationMonitor.reportNavigationDidNotWaitForRules()

Swift.print("***", #function, "returning false")
return false
}

Task {
Swift.print("***", #function, "Task started")
rulesCompilationMonitor.tabWillWaitForRulesCompilation(tabModel.uid)
showProgressIndicator()
await userContentController.awaitContentBlockingAssetsInstalled()
rulesCompilationMonitor.reportTabFinishedWaitingForRules(tabModel.uid)

await MainActor.run(body: completion)
Swift.print("***", #function, "Task finished")
}

Swift.print("***", #function, "returning true")
return true
}

Expand Down

0 comments on commit c570744

Please sign in to comment.