Skip to content

Commit

Permalink
update swipe tabs feedback (#2618)
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy authored Apr 4, 2024
1 parent ad2ec85 commit 8ce1531
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
3 changes: 1 addition & 2 deletions Core/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ public enum FeatureFlag: String {
case networkProtection
case networkProtectionWaitlistAccess
case networkProtectionWaitlistActive
case swipeTabs
case autoconsentOnByDefault
case history
}

extension FeatureFlag: FeatureFlagSourceProviding {
public var source: FeatureFlagSource {
switch self {
case .debugMenu, .appTrackingProtection, .swipeTabs:
case .debugMenu, .appTrackingProtection:
return .internalOnly
case .sync:
return .remoteReleasable(.subfeature(SyncSubfeature.level0ShowSync))
Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

private func showKeyboardOnLaunch() {
guard KeyboardSettings().onAppLaunch && showKeyboardIfSettingOn && shouldShowKeyboardOnLaunch() else { return }
self.mainViewController?.enterSearch()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.mainViewController?.enterSearch()
}
showKeyboardIfSettingOn = false
}

Expand Down
24 changes: 12 additions & 12 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ class MainViewController: UIViewController {

startOnboardingFlowIfNotSeenBefore()
tabsBarController?.refresh(tabsModel: tabManager.model)
swipeTabsCoordinator?.refresh(tabsModel: tabManager.model)
swipeTabsCoordinator?.refresh(tabsModel: tabManager.model, scrollToSelected: true)

_ = AppWidthObserver.shared.willResize(toWidth: view.frame.width)
applyWidth()

Expand Down Expand Up @@ -340,7 +340,7 @@ class MainViewController: UIViewController {
}
}

func updatePreviewForCurrentTab() {
func updatePreviewForCurrentTab(completion: (() -> Void)? = nil) {
assert(Thread.isMainThread)

if !viewCoordinator.logoContainer.isHidden,
Expand All @@ -349,6 +349,7 @@ class MainViewController: UIViewController {
// Home screen with logo
if let image = viewCoordinator.logoContainer.createImageSnapshot(inBounds: viewCoordinator.contentContainer.frame) {
previewsSource.update(preview: image, forTab: tab)
completion?()
}

} else if let currentTab = self.tabManager.current(), currentTab.link != nil {
Expand All @@ -357,12 +358,16 @@ class MainViewController: UIViewController {
guard let image else { return }
self.previewsSource.update(preview: image,
forTab: currentTab.tabModel)
completion?()
})
} else if let tab = self.tabManager.model.currentTab {
// Favorites, etc
if let image = viewCoordinator.contentContainer.createImageSnapshot() {
previewsSource.update(preview: image, forTab: tab)
completion?()
}
} else {
completion?()
}
}

Expand Down Expand Up @@ -1157,7 +1162,7 @@ class MainViewController: UIViewController {
viewCoordinator.toolbar.isHidden = false
viewCoordinator.omniBar.enterPhoneState()

swipeTabsCoordinator?.isEnabled = featureFlagger.isFeatureOn(.swipeTabs)
swipeTabsCoordinator?.isEnabled = true
}

@discardableResult
Expand Down Expand Up @@ -1291,7 +1296,7 @@ class MainViewController: UIViewController {
}
attachHomeScreen()
tabsBarController?.refresh(tabsModel: tabManager.model)
swipeTabsCoordinator?.refresh(tabsModel: tabManager.model)
swipeTabsCoordinator?.refresh(tabsModel: tabManager.model, scrollToSelected: true)
homeController?.openedAsNewTab(allowingKeyboard: allowingKeyboard)
}

Expand Down Expand Up @@ -2249,16 +2254,11 @@ extension MainViewController: TabSwitcherButtonDelegate {
guard let currentTab = currentTab ?? tabManager?.current(createIfNeeded: true) else {
fatalError("Unable to get current tab")
}

currentTab.preparePreview(completion: { image in
if let image = image {
self.previewsSource.update(preview: image,
forTab: currentTab.tabModel)

}
updatePreviewForCurrentTab {
ViewHighlighter.hideAll()
self.segueToTabSwitcher()
})
}
}
}

Expand Down
15 changes: 5 additions & 10 deletions DuckDuckGo/SwipeTabsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class SwipeTabsCoordinator: NSObject {
collectionView.dataSource = self
collectionView.decelerationRate = .fast
collectionView.backgroundColor = .clear
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false

updateLayout()
}
Expand All @@ -92,7 +94,6 @@ class SwipeTabsCoordinator: NSObject {

private func updateLayout() {
let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout
layout?.scrollDirection = .horizontal
layout?.itemSize = CGSize(width: coordinator.superview.frame.size.width, height: coordinator.omniBar.frame.height)
layout?.minimumLineSpacing = 0
layout?.minimumInteritemSpacing = 0
Expand All @@ -101,7 +102,6 @@ class SwipeTabsCoordinator: NSObject {

private func scrollToCurrent() {
guard isEnabled else { return }

let targetOffset = collectionView.frame.width * CGFloat(tabsModel.currentIndex)

guard targetOffset != collectionView.contentOffset.x else {
Expand All @@ -118,12 +118,6 @@ class SwipeTabsCoordinator: NSObject {
// MARK: UICollectionViewDelegate
extension SwipeTabsCoordinator: UICollectionViewDelegate {

func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
DispatchQueue.main.async {
self.scrollToCurrent()
}
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {

switch state {
Expand Down Expand Up @@ -217,7 +211,7 @@ extension SwipeTabsCoordinator: UICollectionViewDelegate {
switch state {
case .idle:
state = .starting(scrollView.contentOffset)

default: break
}
}
Expand Down Expand Up @@ -311,7 +305,8 @@ extension SwipeTabsCoordinator: UICollectionViewDataSource {

if let url = tabsModel.safeGetTabAt(indexPath.row)?.link?.url {
cell.omniBar?.startBrowsing()
cell.omniBar?.refreshText(forUrl: url)
cell.omniBar?.refreshText(forUrl: url, forceFullURL: appSettings.showFullSiteAddress)
cell.omniBar?.resetPrivacyIcon(for: url)
}

}
Expand Down
6 changes: 1 addition & 5 deletions DuckDuckGo/TabPreviewsSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ class TabPreviewsSource {

func update(preview: UIImage, forTab tab: Tab) {
cache[tab.uid] = preview

if tabSettings.isGridViewEnabled {
store(preview: preview, forTab: tab)
}

store(preview: preview, forTab: tab)
tab.didUpdatePreview()
}

Expand Down

0 comments on commit 8ce1531

Please sign in to comment.