From 8a14f59c88e18d13aaec3ee4823b9b89b522707d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20=C5=9Apiewak?= Date: Wed, 7 Aug 2024 18:10:25 +0200 Subject: [PATCH] Show improved Dax onboarding on New Tab Page --- DuckDuckGo/MainViewController.swift | 7 ++- DuckDuckGo/NewTabPageModel.swift | 10 ++++ DuckDuckGo/NewTabPageView.swift | 10 +++- DuckDuckGo/NewTabPageViewController.swift | 70 ++++++++++++++++++++++- 4 files changed, 90 insertions(+), 7 deletions(-) diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index 4dc2268ffe..4dc4a48666 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -765,13 +765,17 @@ class MainViewController: UIViewController { fatalError("No tab model") } + let newTabDaxDialogFactory = NewTabDaxDialogFactory(delegate: self, contextualOnboardingLogic: DaxDialogs.shared) if homeTabManager.isNewTabPageSectionsEnabled { let controller = NewTabPageViewController(tab: tabModel, interactionModel: favoritesViewModel, syncService: syncService, syncBookmarksAdapter: syncDataProviders.bookmarksAdapter, homePageMessagesConfiguration: homePageConfiguration, - privacyProDataReporting: privacyProDataReporter) + privacyProDataReporting: privacyProDataReporter, + variantManager: variantManager, + newTabDialogFactory: newTabDaxDialogFactory, + newTabDialogTypeProvider: DaxDialogs.shared) controller.delegate = self controller.shortcutsDelegate = self @@ -782,7 +786,6 @@ class MainViewController: UIViewController { viewCoordinator.logoContainer.isHidden = true adjustNewTabPageSafeAreaInsets(for: appSettings.currentAddressBarPosition) } else { - let newTabDaxDialogFactory = NewTabDaxDialogFactory(delegate: self, contextualOnboardingLogic: DaxDialogs.shared) let homePageDependencies = HomePageDependencies(homePageConfiguration: homePageConfiguration, model: tabModel, favoritesViewModel: favoritesViewModel, diff --git a/DuckDuckGo/NewTabPageModel.swift b/DuckDuckGo/NewTabPageModel.swift index a8ff0d2e70..fc002768d5 100644 --- a/DuckDuckGo/NewTabPageModel.swift +++ b/DuckDuckGo/NewTabPageModel.swift @@ -22,6 +22,7 @@ import Foundation final class NewTabPageModel: ObservableObject { @Published private(set) var isIntroMessageVisible: Bool + @Published private(set) var isOnboarding: Bool private let appSettings: AppSettings @@ -29,6 +30,7 @@ final class NewTabPageModel: ObservableObject { self.appSettings = appSettings isIntroMessageVisible = appSettings.newTabPageIntroMessageEnabled ?? false + isOnboarding = false } func increaseIntroMessageCounter() { @@ -42,4 +44,12 @@ final class NewTabPageModel: ObservableObject { appSettings.newTabPageIntroMessageEnabled = false isIntroMessageVisible = false } + + func startOnboarding() { + isOnboarding = true + } + + func finishOnboarding() { + isOnboarding = false + } } diff --git a/DuckDuckGo/NewTabPageView.swift b/DuckDuckGo/NewTabPageView.swift index 19d80086ab..90d6ea6331 100644 --- a/DuckDuckGo/NewTabPageView.swift +++ b/DuckDuckGo/NewTabPageView.swift @@ -115,7 +115,7 @@ struct NewTabPageView: View { !shortcutsSettingsModel.enabledItems.isEmpty } - var body: some View { + private var mainView: some View { GeometryReader { proxy in ScrollView { VStack { @@ -158,10 +158,16 @@ struct NewTabPageView: View { }, content: { NavigationView { NewTabPageSettingsView(shortcutsSettingsModel: shortcutsSettingsModel, - sectionsSettingsModel: sectionsSettingsModel) + sectionsSettingsModel: sectionsSettingsModel) } }) } + + var body: some View { + if !newTabPageModel.isOnboarding { + mainView + } + } } private extension View { diff --git a/DuckDuckGo/NewTabPageViewController.swift b/DuckDuckGo/NewTabPageViewController.swift index 71f0ac7af7..a7a490ef64 100644 --- a/DuckDuckGo/NewTabPageViewController.swift +++ b/DuckDuckGo/NewTabPageViewController.swift @@ -20,12 +20,16 @@ import SwiftUI import DDGSync import Bookmarks +import BrowserServicesKit import Core final class NewTabPageViewController: UIHostingController>, NewTabPage { private let syncService: DDGSyncing private let syncBookmarksAdapter: SyncBookmarksAdapter + private let variantManager: VariantManager + private let newTabDialogFactory: any NewTabDaxDialogProvider + private let newTabDialogTypeProvider: NewTabDialogSpecProvider private(set) lazy var faviconsFetcherOnboarding = FaviconsFetcherOnboarding(syncService: syncService, syncBookmarksAdapter: syncBookmarksAdapter) @@ -37,16 +41,24 @@ final class NewTabPageViewController: UIHostingController? + init(tab: Tab, interactionModel: FavoritesListInteracting, syncService: DDGSyncing, syncBookmarksAdapter: SyncBookmarksAdapter, homePageMessagesConfiguration: HomePageMessagesConfiguration, - privacyProDataReporting: PrivacyProDataReporting? = nil) { + privacyProDataReporting: PrivacyProDataReporting? = nil, + variantManager: VariantManager, + newTabDialogFactory: any NewTabDaxDialogProvider, + newTabDialogTypeProvider: NewTabDialogSpecProvider) { self.tab = tab self.syncService = syncService self.syncBookmarksAdapter = syncBookmarksAdapter + self.variantManager = variantManager + self.newTabDialogFactory = newTabDialogFactory + self.newTabDialogTypeProvider = newTabDialogTypeProvider newTabPageModel = NewTabPageModel() shortcutsSettingsModel = NewTabPageShortcutsSettingsModel() @@ -71,6 +83,8 @@ final class NewTabPageViewController: UIHostingController