Skip to content

Commit

Permalink
handle new tab / home screen transition
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Jan 31, 2024
1 parent 804e6dc commit cc424da
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions DuckDuckGo/SwipeTabsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,17 @@ extension SwipeTabsCoordinator: UICollectionViewDelegate {
let modifier = (offset > 0 ? -1 : 1)
let nextIndex = tabsModel.currentIndex + modifier
print("***", #function, "nextIndex", nextIndex)
guard tabsModel.tabs.indices.contains(nextIndex) else {
print("***", #function, "invalid index", nextIndex)
return
}

let targetFrame = CGRect(origin: .zero, size: coordinator.contentContainer.frame.size)

let tab = tabsModel.get(tabAt: nextIndex)
if let image = tabPreviewsSource.preview(for: tab) {
let tab = tabsModel.safeGetTabAt(nextIndex)
if let tab, let image = tabPreviewsSource.preview(for: tab) {
print("***", #function, "image preview")
createPreviewFromImage(image)
} else if tab.link == nil {
print("***", #function, "home screen preview")
} else if tab?.link == nil {
// either the tab or link is nil - either way transition to the home screen
// TODO handle favorites
print("***", #function, "new tab home screen preview")
createPreviewFromLogoContainerWithSize(targetFrame.size)
} else {
print("***", #function, "no preview found")
Expand Down Expand Up @@ -389,3 +387,12 @@ class OmniBarCell: UICollectionViewCell {
}

}

extension TabsModel {

func safeGetTabAt(_ index: Int) -> Tab? {
guard tabs.indices.contains(index) else { return nil }
return tabs[index]
}

}

0 comments on commit cc424da

Please sign in to comment.