Skip to content

Commit

Permalink
Prevent presenting the keyboard on new tap page when Add to Dock inst…
Browse files Browse the repository at this point in the history
…ructions are presented to the user
  • Loading branch information
alessandroboron committed Oct 30, 2024
1 parent 439863f commit 0e4210b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 12 additions & 1 deletion DuckDuckGo/DaxDialogs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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?

Expand All @@ -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 {
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -733,6 +743,7 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {
private func clearOnboardingBrowsingData() {
removeLastShownDaxDialog()
removeLastVisitedOnboardingWebsite()
currentHomeSpec = nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
5 changes: 4 additions & 1 deletion DuckDuckGo/NewTabPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0e4210b

Please sign in to comment.