From 0e4210b68d26c2751403fc9d7b4cebcc21495c49 Mon Sep 17 00:00:00 2001 From: Alessandro Boron Date: Wed, 30 Oct 2024 16:28:56 +0100 Subject: [PATCH] Prevent presenting the keyboard on new tap page when Add to Dock instructions are presented to the user --- DuckDuckGo/DaxDialogs.swift | 13 ++++++++++++- DuckDuckGo/MainViewController.swift | 2 +- DuckDuckGo/NewTabPageViewController.swift | 5 ++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/DuckDuckGo/DaxDialogs.swift b/DuckDuckGo/DaxDialogs.swift index d1793efb6b..1a3f2b42fe 100644 --- a/DuckDuckGo/DaxDialogs.swift +++ b/DuckDuckGo/DaxDialogs.swift @@ -41,6 +41,7 @@ protocol ContextualOnboardingLogic { var shouldShowPrivacyButtonPulse: Bool { get } var isShowingSearchSuggestions: Bool { get } var isShowingSitesSuggestions: Bool { get } + var isShowingAddToDockDialog: Bool { get } func setSearchMessageSeen() func setFireEducationMessageSeen() @@ -211,6 +212,7 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic { private var settings: DaxDialogsSettings private var entityProviding: EntityProviding private let variantManager: VariantManager + private let addToDockManager: OnboardingAddToDockManaging private var nextHomeScreenMessageOverride: HomeScreenSpec? @@ -222,10 +224,13 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic { /// Use singleton accessor, this is only accessible for tests init(settings: DaxDialogsSettings = DefaultDaxDialogsSettings(), entityProviding: EntityProviding, - variantManager: VariantManager = DefaultVariantManager()) { + variantManager: VariantManager = DefaultVariantManager(), + onboardingManager: OnboardingAddToDockManaging = OnboardingManager() + ) { self.settings = settings self.entityProviding = entityProviding self.variantManager = variantManager + self.addToDockManager = onboardingManager } private var isNewOnboarding: Bool { @@ -276,6 +281,11 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic { return lastShownDaxDialogType.flatMap(BrowsingSpec.SpecType.init(rawValue:)) == .visitWebsite || currentHomeSpec == .subsequent } + var isShowingAddToDockDialog: Bool { + guard isNewOnboarding else { return false } + return currentHomeSpec == .final && addToDockManager.isAddToDockEnabled + } + var isEnabled: Bool { // skip dax dialogs in integration tests guard ProcessInfo.processInfo.environment["DAXDIALOGS"] != "false" else { return false } @@ -733,6 +743,7 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic { private func clearOnboardingBrowsingData() { removeLastShownDaxDialog() removeLastVisitedOnboardingWebsite() + currentHomeSpec = nil } } diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index d1a2fd2e36..7800b7cc2a 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -2672,7 +2672,7 @@ extension MainViewController: AutoClearWorker { // Ideally this should happen once data clearing has finished AND the animation is finished if showNextDaxDialog { self.newTabPageViewController?.showNextDaxDialog() - } else if KeyboardSettings().onNewTab { + } else if KeyboardSettings().onNewTab && !self.contextualOnboardingLogic.isShowingAddToDockDialog { // If we're showing the Add to Dock dialog prevent address bar to become first responder. We want to make sure the user focues on the Add to Dock instructions. let showKeyboardAfterFireButton = DispatchWorkItem { self.enterSearch() } diff --git a/DuckDuckGo/NewTabPageViewController.swift b/DuckDuckGo/NewTabPageViewController.swift index 0f24599de6..ace3f92348 100644 --- a/DuckDuckGo/NewTabPageViewController.swift +++ b/DuckDuckGo/NewTabPageViewController.swift @@ -310,9 +310,12 @@ extension NewTabPageViewController { guard let spec = dialogProvider.nextHomeScreenMessageNew() else { return } - let onDismiss = { + let onDismiss = { [weak self] in + guard let self else { return } dialogProvider.dismiss() self.dismissHostingController(didFinishNTPOnboarding: true) + // Make the address bar first responder after closing the new tap page final dialog. + self.launchNewSearch() } let daxDialogView = AnyView(factory.createDaxDialog(for: spec, onDismiss: onDismiss)) let hostingController = UIHostingController(rootView: daxDialogView)