Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use New Tab Page implementation without customization features #3453

Merged
merged 15 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
560E990F2BEE2CB800507CE0 /* SyncErrorMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560E990E2BEE2CB800507CE0 /* SyncErrorMessage.swift */; };
564DE4532C3ED1B700D23241 /* NewTabDaxDialogFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4522C3ED1B700D23241 /* NewTabDaxDialogFactory.swift */; };
564DE4552C3EDEF200D23241 /* ContextualOnboardingNewTabDialogFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4542C3EDEF200D23241 /* ContextualOnboardingNewTabDialogFactoryTests.swift */; };
564DE4572C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4562C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift */; };
564DE4572C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4562C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift */; };
564DE45A2C450BE600D23241 /* DaxDialogsNewTabTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4592C450BE600D23241 /* DaxDialogsNewTabTests.swift */; };
564DE45E2C45218500D23241 /* OnboardingNavigationDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE45D2C45218500D23241 /* OnboardingNavigationDelegateTests.swift */; };
564DE4602C4544CA00D23241 /* HomePageDependencies.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE45F2C4544CA00D23241 /* HomePageDependencies.swift */; };
Expand Down Expand Up @@ -301,7 +301,9 @@
6F3537A42C4AC140009F8717 /* NewTabPageDaxLogoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F3537A32C4AC140009F8717 /* NewTabPageDaxLogoView.swift */; };
6F40D15B2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F40D15A2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift */; };
6F40D15E2C34436500BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F40D15C2C34436200BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift */; };
6F5041C92CC11A5100989E48 /* SimpleNewTabPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5041C82CC11A5100989E48 /* SimpleNewTabPageView.swift */; };
6F5345AF2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5345AE2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift */; };
6F5AA3EF2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5AA3EE2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift */; };
6F5CC0812C2AFFE400AFC840 /* ToggleExpandButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5CC0802C2AFFE400AFC840 /* ToggleExpandButtonStyle.swift */; };
6F64AA532C47E92600CF4489 /* FavoritesFaviconLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F64AA522C47E92600CF4489 /* FavoritesFaviconLoader.swift */; };
6F64AA592C4818D700CF4489 /* NewTabPageShortcut.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F64AA582C4818D700CF4489 /* NewTabPageShortcut.swift */; };
Expand Down Expand Up @@ -356,7 +358,7 @@
6FE127462C2054A900EB5724 /* NewTabPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE127452C2054A900EB5724 /* NewTabPageViewController.swift */; };
6FE1274B2C20943500EB5724 /* ShortcutItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE1274A2C20943500EB5724 /* ShortcutItemView.swift */; };
6FEC0B852C999352006B4F6E /* FavoriteItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FEC0B842C999352006B4F6E /* FavoriteItem.swift */; };
6FEC0B882C999961006B4F6E /* FavoriteDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FEC0B872C999961006B4F6E /* FavoriteDataSource.swift */; };
6FEC0B882C999961006B4F6E /* FavoritesListInteractingAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FEC0B872C999961006B4F6E /* FavoritesListInteractingAdapter.swift */; };
6FF915822B88E07A0042AC87 /* AdAttributionFetcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FF915802B88E0750042AC87 /* AdAttributionFetcherTests.swift */; };
7BC571202BDBB877003B0CCE /* VPNActivationDateStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */; };
7BC571212BDBB977003B0CCE /* VPNActivationDateStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */; };
Expand Down Expand Up @@ -1543,7 +1545,7 @@
560E990E2BEE2CB800507CE0 /* SyncErrorMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncErrorMessage.swift; sourceTree = "<group>"; };
564DE4522C3ED1B700D23241 /* NewTabDaxDialogFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabDaxDialogFactory.swift; sourceTree = "<group>"; };
564DE4542C3EDEF200D23241 /* ContextualOnboardingNewTabDialogFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextualOnboardingNewTabDialogFactoryTests.swift; sourceTree = "<group>"; };
564DE4562C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewControllerDaxDialogTests.swift; sourceTree = "<group>"; };
564DE4562C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageControllerDaxDialogTests.swift; sourceTree = "<group>"; };
564DE4592C450BE600D23241 /* DaxDialogsNewTabTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaxDialogsNewTabTests.swift; sourceTree = "<group>"; };
564DE45D2C45218500D23241 /* OnboardingNavigationDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingNavigationDelegateTests.swift; sourceTree = "<group>"; };
564DE45F2C4544CA00D23241 /* HomePageDependencies.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDependencies.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1581,7 +1583,9 @@
6F3537A32C4AC140009F8717 /* NewTabPageDaxLogoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageDaxLogoView.swift; sourceTree = "<group>"; };
6F40D15A2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDisplayDailyPixelBucket.swift; sourceTree = "<group>"; };
6F40D15C2C34436200BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDisplayDailyPixelBucketTests.swift; sourceTree = "<group>"; };
6F5041C82CC11A5100989E48 /* SimpleNewTabPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleNewTabPageView.swift; sourceTree = "<group>"; };
6F5345AE2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsPersistentStorage.swift; sourceTree = "<group>"; };
6F5AA3EE2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesListInteractingAdapterTests.swift; sourceTree = "<group>"; };
6F5CC0802C2AFFE400AFC840 /* ToggleExpandButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleExpandButtonStyle.swift; sourceTree = "<group>"; };
6F64AA522C47E92600CF4489 /* FavoritesFaviconLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesFaviconLoader.swift; sourceTree = "<group>"; };
6F64AA582C4818D700CF4489 /* NewTabPageShortcut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageShortcut.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1637,7 +1641,7 @@
6FE127452C2054A900EB5724 /* NewTabPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageViewController.swift; sourceTree = "<group>"; };
6FE1274A2C20943500EB5724 /* ShortcutItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutItemView.swift; sourceTree = "<group>"; };
6FEC0B842C999352006B4F6E /* FavoriteItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteItem.swift; sourceTree = "<group>"; };
6FEC0B872C999961006B4F6E /* FavoriteDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteDataSource.swift; sourceTree = "<group>"; };
6FEC0B872C999961006B4F6E /* FavoritesListInteractingAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesListInteractingAdapter.swift; sourceTree = "<group>"; };
6FF915802B88E0750042AC87 /* AdAttributionFetcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdAttributionFetcherTests.swift; sourceTree = "<group>"; };
7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPNActivationDateStore.swift; sourceTree = "<group>"; };
83004E7F2193BB8200DA013C /* WKNavigationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKNavigationExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3846,8 +3850,9 @@
6F7FB8DF2C660B1A00867DA7 /* NewTabPageFavoritesModelTests.swift */,
6F7FB8E42C66158D00867DA7 /* NewTabPageShortcutsSettingsModelTests.swift */,
6F7FB8E62C66197E00867DA7 /* NewTabPageSectionsSettingsModelTests.swift */,
564DE4562C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift */,
564DE4562C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift */,
6FABAA682C6116FD003762EC /* NewTabPageShortcutsSettingsStorageTests.swift */,
6F5AA3EE2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift */,
);
name = NewTabPage;
sourceTree = "<group>";
Expand Down Expand Up @@ -3901,7 +3906,7 @@
6FD3F8122C3EFDA200DA5797 /* FavoritesPreviewDataSource.swift */,
6FA3438E2C3D3BC300470677 /* Favorite.swift */,
6FEC0B842C999352006B4F6E /* FavoriteItem.swift */,
6FEC0B872C999961006B4F6E /* FavoriteDataSource.swift */,
6FEC0B872C999961006B4F6E /* FavoritesListInteractingAdapter.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -3952,6 +3957,7 @@
6F03CAF82C32C3AA004179A8 /* Messages */,
6FE127372C20492500EB5724 /* NewTabPage.swift */,
6FD8E51F2C5BA23200345670 /* NewTabPageViewModel.swift */,
6F5041C82CC11A5100989E48 /* SimpleNewTabPageView.swift */,
6FE127392C204BD000EB5724 /* NewTabPageView.swift */,
6FE127452C2054A900EB5724 /* NewTabPageViewController.swift */,
6FD3F8182C41252900DA5797 /* NewTabPageControllerDelegate.swift */,
Expand Down Expand Up @@ -7453,6 +7459,7 @@
C185ED612BD4329700BAE9DC /* ImportPasswordsStatusHandler.swift in Sources */,
CB9B8739278C8E72001F4906 /* WidgetEducationViewController.swift in Sources */,
F4D9C4FA25117A0F00814B71 /* HomeMessageStorage.swift in Sources */,
6F5041C92CC11A5100989E48 /* SimpleNewTabPageView.swift in Sources */,
D69FBF762B28BE3600B505F1 /* SettingsSubscriptionView.swift in Sources */,
D664C7CC2B289AA200CBFA76 /* SubscriptionPagesUserScript.swift in Sources */,
AA3D854523D9942200788410 /* AppIconSettingsViewController.swift in Sources */,
Expand Down Expand Up @@ -7851,7 +7858,7 @@
1E4DCF4627B6A33600961E25 /* DownloadsListViewModel.swift in Sources */,
37C696772C4957940073E131 /* RemoteMessagingDebugViewController.swift in Sources */,
31860A5B2C57ED2D005561F5 /* DuckPlayerStorage.swift in Sources */,
6FEC0B882C999961006B4F6E /* FavoriteDataSource.swift in Sources */,
6FEC0B882C999961006B4F6E /* FavoritesListInteractingAdapter.swift in Sources */,
F4F6DFB626E6B71300ED7E12 /* BookmarkFoldersTableViewController.swift in Sources */,
8586A11024CCCD040049720E /* TabsBarViewController.swift in Sources */,
6FEC0B852C999352006B4F6E /* FavoriteItem.swift in Sources */,
Expand Down Expand Up @@ -7907,7 +7914,7 @@
98DA35C4268CC81E00159906 /* DomainMatchingReportTests.swift in Sources */,
8590CB632684F10F0089F6BF /* ContentBlockerProtectionStoreTests.swift in Sources */,
83EDCC411F86B89C005CDFCD /* StatisticsLoaderTests.swift in Sources */,
564DE4572C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift in Sources */,
564DE4572C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift in Sources */,
C14882E327F20D9A00D59F0C /* BookmarksExporterTests.swift in Sources */,
85C29708247BDD060063A335 /* DaxDialogsBrowsingSpecTests.swift in Sources */,
9FE05CF12C36468A00D9046B /* OnboardingPixelReporterTests.swift in Sources */,
Expand Down Expand Up @@ -8018,6 +8025,7 @@
C14882EA27F20DD000D59F0C /* MockBookmarksCoreDataStorage.swift in Sources */,
1E05D1DB29C47B3300BF9A1F /* DailyPixelTests.swift in Sources */,
564DE4552C3EDEF200D23241 /* ContextualOnboardingNewTabDialogFactoryTests.swift in Sources */,
6F5AA3EF2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift in Sources */,
981FED7422046017008488D7 /* AutoClearTests.swift in Sources */,
98DDF9F322C4029D00DE38DB /* InitHelpers.swift in Sources */,
B6AD9E3628D4510A0019CDE9 /* ContentBlockerRulesManagerMock.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/BrowsingMenu/BrowsingMenuAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final class BrowsingMenuAnimator: NSObject, UIViewControllerAnimatedTransitionin

fromViewController.view.isHidden = true

if toViewController.homeViewController != nil {
if toViewController.newTabPageViewController != nil {
toViewController.presentedMenuButton.setState(.bookmarksImage, animated: true)
} else {
toViewController.presentedMenuButton.setState(.menuImage, animated: true)
Expand Down
15 changes: 13 additions & 2 deletions DuckDuckGo/DaxDialogViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DaxDialogViewController: UIViewController {
initCTA()
}
}

func calculateHeight() -> CGFloat {
guard let text = message ?? cta, !text.isEmpty else { return 370.0 }

Expand All @@ -59,7 +59,7 @@ class DaxDialogViewController: UIViewController {
let bottomMargin: CGFloat = 24.0
return iconHeight + topMargin + size.height + buttonHeight + bottomMargin
}

var onTapCta: (() -> Void)?

private var position: Int = 0
Expand Down Expand Up @@ -188,3 +188,14 @@ extension DaxDialogViewController {
}
}
}

extension DaxDialogViewController {
static func loadFromStoryboard() -> DaxDialogViewController {
let storyboard = UIStoryboard(name: "DaxOnboarding", bundle: Bundle.main)
guard let controller = storyboard.instantiateViewController(identifier: "DaxDialog") as? DaxDialogViewController else {
fatalError("Failed to instantiate DaxDialogViewController from storyboard")
}

return controller
}
}
6 changes: 5 additions & 1 deletion DuckDuckGo/FavoritesFaviconLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ actor FavoritesFaviconLoader: FavoritesFaviconLoading {
}

tasks[domain] = newTask
let value = await newTask.value
if value == nil {
tasks[domain] = nil
}

return await newTask.value
return value
}

nonisolated func existingFavicon(for favorite: Favorite, size: CGFloat) -> Favicon? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FavoriteDataSource.swift
// FavoritesListInteractingAdapter.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
Expand All @@ -24,12 +24,30 @@ import Bookmarks
final class FavoritesListInteractingAdapter: NewTabPageFavoriteDataSource {

let favoritesListInteracting: FavoritesListInteracting
let appSettings: AppSettings

init(favoritesListInteracting: FavoritesListInteracting) {
private var cancellables: Set<AnyCancellable> = []

private var displayModeSubject = PassthroughSubject<Void, Never>()

init(favoritesListInteracting: FavoritesListInteracting, appSettings: AppSettings = AppDependencyProvider.shared.appSettings) {
self.favoritesListInteracting = favoritesListInteracting
self.appSettings = appSettings
self.externalUpdates = favoritesListInteracting.externalUpdates.merge(with: displayModeSubject).eraseToAnyPublisher()

NotificationCenter.default.publisher(for: AppUserDefaults.Notifications.favoritesDisplayModeChange)
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self else {
return
}
favoritesListInteracting.favoritesDisplayMode = self.appSettings.favoritesDisplayMode
displayModeSubject.send()
}
.store(in: &cancellables)
}

var externalUpdates: AnyPublisher<Void, Never> { favoritesListInteracting.externalUpdates }
let externalUpdates: AnyPublisher<Void, Never>

var favorites: [Favorite] {
(try? favoritesListInteracting.favorites.map(Favorite.init)) ?? []
Expand Down
19 changes: 15 additions & 4 deletions DuckDuckGo/FavoritesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,31 @@ class FavoritesViewModel: ObservableObject {
private let favoriteDataSource: NewTabPageFavoriteDataSource
private let pixelFiring: PixelFiring.Type
private let dailyPixelFiring: DailyPixelFiring.Type
private let isNewTabPageCustomizationEnabled: Bool

var isEmpty: Bool {
allFavorites.filter(\.isFavorite).isEmpty
}

init(favoriteDataSource: NewTabPageFavoriteDataSource,
init(isNewTabPageCustomizationEnabled: Bool = false,
favoriteDataSource: NewTabPageFavoriteDataSource,
faviconLoader: FavoritesFaviconLoading,
pixelFiring: PixelFiring.Type = Pixel.self,
dailyPixelFiring: DailyPixelFiring.Type = DailyPixel.self) {
self.favoriteDataSource = favoriteDataSource
self.pixelFiring = pixelFiring
self.dailyPixelFiring = dailyPixelFiring
self.isNewTabPageCustomizationEnabled = isNewTabPageCustomizationEnabled
self.isCollapsed = isNewTabPageCustomizationEnabled

self.faviconLoader = MissingFaviconWrapper(loader: faviconLoader, onFaviconMissing: { [weak self] in
guard let self else { return }

await MainActor.run {
self.faviconMissing()
}
})



favoriteDataSource.externalUpdates.sink { [weak self] _ in
self?.updateData()
}.store(in: &cancellables)
Expand All @@ -93,6 +97,10 @@ class FavoritesViewModel: ObservableObject {
}

func prefixedFavorites(for columnsCount: Int) -> FavoritesSlice {
guard isNewTabPageCustomizationEnabled else {
return .init(items: allFavorites, isCollapsible: false)
}

let hasFavorites = allFavorites.contains(where: \.isFavorite)
let maxCollapsedItemsCount = hasFavorites ? columnsCount * 2 : columnsCount
let isCollapsible = allFavorites.count > maxCollapsedItemsCount
Expand Down Expand Up @@ -170,7 +178,10 @@ class FavoritesViewModel: ObservableObject {
var allFavorites = favoriteDataSource.favorites.map {
FavoriteItem.favorite($0)
}
allFavorites.append(.addFavorite)

if isNewTabPageCustomizationEnabled {
allFavorites.append(.addFavorite)
}

self.allFavorites = allFavorites
}
Expand Down
Loading
Loading