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

Show improved Dax onboarding on New Tab Page #3203

Merged
merged 2 commits into from
Aug 8, 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
5 changes: 3 additions & 2 deletions DuckDuckGo/HomeViewController+DaxDialogs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ extension HomeViewController {
hostingController = UIHostingController(rootView: daxDialogView)
guard let hostingController else { return }
hostingController.view.backgroundColor = .clear
addChild(hostingController)
view.addSubview(hostingController.view)
hostingController.didMove(toParent: self)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
hideLogo()
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)
hideLogo()
configureCollectionView()
}

Expand Down
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()
}
Comment on lines +202 to +230
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied the code from HomeViewController+DaxDialogs, but included addChild(hostingController) which was missing in the original.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included this call in the HomeViewController code (cd424a9).


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