Skip to content

Commit

Permalink
Show improved Dax onboarding on New Tab Page
Browse files Browse the repository at this point in the history
  • Loading branch information
dus7 committed Aug 7, 2024
1 parent 45220c5 commit 8a14f59
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
7 changes: 5 additions & 2 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions DuckDuckGo/NewTabPageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import Foundation
final class NewTabPageModel: ObservableObject {

@Published private(set) var isIntroMessageVisible: Bool
@Published private(set) var isOnboarding: Bool

private let appSettings: AppSettings

init(appSettings: AppSettings = AppDependencyProvider.shared.appSettings) {
self.appSettings = appSettings

isIntroMessageVisible = appSettings.newTabPageIntroMessageEnabled ?? false
isOnboarding = false
}

func increaseIntroMessageCounter() {
Expand All @@ -42,4 +44,12 @@ final class NewTabPageModel: ObservableObject {
appSettings.newTabPageIntroMessageEnabled = false
isIntroMessageVisible = false
}

func startOnboarding() {
isOnboarding = true
}

func finishOnboarding() {
isOnboarding = false
}
}
10 changes: 8 additions & 2 deletions DuckDuckGo/NewTabPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct NewTabPageView<FavoritesModelType: FavoritesModel>: View {
!shortcutsSettingsModel.enabledItems.isEmpty
}

var body: some View {
private var mainView: some View {
GeometryReader { proxy in
ScrollView {
VStack {
Expand Down Expand Up @@ -158,10 +158,16 @@ struct NewTabPageView<FavoritesModelType: FavoritesModel>: View {
}, content: {
NavigationView {
NewTabPageSettingsView(shortcutsSettingsModel: shortcutsSettingsModel,
sectionsSettingsModel: sectionsSettingsModel)
sectionsSettingsModel: sectionsSettingsModel)
}
})
}

var body: some View {
if !newTabPageModel.isOnboarding {
mainView
}
}
}

private extension View {
Expand Down
70 changes: 67 additions & 3 deletions DuckDuckGo/NewTabPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
import SwiftUI
import DDGSync
import Bookmarks
import BrowserServicesKit
import Core

final class NewTabPageViewController: UIHostingController<NewTabPageView<FavoritesDefaultModel>>, 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)

Expand All @@ -37,16 +41,24 @@ final class NewTabPageViewController: UIHostingController<NewTabPageView<Favorit
private let sectionsSettingsModel: NewTabPageSectionsSettingsModel
private let tab: Tab

private var hostingController: UIHostingController<AnyView>?

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()
Expand All @@ -71,6 +83,8 @@ final class NewTabPageViewController: UIHostingController<NewTabPageView<Favorit
super.viewDidAppear(animated)

tab.viewed = true

presentNextDaxDialog()
}

// MARK: - Private
Expand Down Expand Up @@ -146,17 +160,25 @@ final class NewTabPageViewController: UIHostingController<NewTabPageView<Favorit
}

func showNextDaxDialog() {

showNextDaxDialogNew(dialogProvider: newTabDialogTypeProvider, factory: newTabDialogFactory)
}

func onboardingCompleted() {

presentNextDaxDialog()
}

func reloadFavorites() {

}

// MARK: - Onboarding

private func presentNextDaxDialog() {
if variantManager.isSupported(feature: .newOnboardingIntro) {
showNextDaxDialogNew(dialogProvider: newTabDialogTypeProvider, factory: newTabDialogFactory)
}
}

// MARK: -

@available(*, unavailable)
Expand All @@ -174,3 +196,45 @@ extension NewTabPageViewController: HomeScreenTransitionSource {
view
}
}

extension NewTabPageViewController {

func showNextDaxDialogNew(dialogProvider: NewTabDialogSpecProvider, factory: any NewTabDaxDialogProvider) {
dismissHostingController(didFinishNTPOnboarding: false)

guard let spec = dialogProvider.nextHomeScreenMessageNew() else { return }

let onDismiss = {
dialogProvider.dismiss()
self.dismissHostingController(didFinishNTPOnboarding: true)
}
let daxDialogView = AnyView(factory.createDaxDialog(for: spec, onDismiss: onDismiss))
let hostingController = UIHostingController(rootView: daxDialogView)
self.hostingController = hostingController

hostingController.view.backgroundColor = .clear
addChild(hostingController)
view.addSubview(hostingController.view)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
hostingController.view.topAnchor.constraint(equalTo: view.topAnchor),
hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])

hostingController.didMove(toParent: self)

newTabPageModel.startOnboarding()
}

private func dismissHostingController(didFinishNTPOnboarding: Bool) {
hostingController?.willMove(toParent: nil)
hostingController?.view.removeFromSuperview()
hostingController?.removeFromParent()
if didFinishNTPOnboarding {
self.newTabPageModel.finishOnboarding()
}
}
}

0 comments on commit 8a14f59

Please sign in to comment.