From f0d613537996b42e1b314056ee8407196a4ab770 Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Fri, 6 Sep 2024 14:49:20 -0400 Subject: [PATCH] [iOS] Display new Default Browser prompt in the new onboarding regions This change also includes a guard against if the user is likely already set Brave as the default --- .../BrowserViewController/BVC+Callout.swift | 76 ++++++++++++------- .../FullScreenCalloutManager.swift | 2 +- .../WelcomeFocus/FocusP3AScreenView.swift | 4 +- .../FocusSystemSettingsView.swift | 52 ++++++++++--- .../Resources/FocusOnboardingStrings.swift | 8 ++ 5 files changed, 102 insertions(+), 40 deletions(-) diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Callout.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Callout.swift index c8fb977c3d9c..9dd9e31c1405 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Callout.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Callout.swift @@ -47,7 +47,7 @@ extension BrowserViewController { case .bottomBar: presentBottomBarCallout(skipSafeGuards: skipSafeGuards) case .defaultBrowser: - presentDefaultBrowserScreenCallout() + presentDefaultBrowserScreenCallout(skipSafeGuards: skipSafeGuards) case .rewards: presentBraveRewardsScreenCallout(skipSafeGuards: skipSafeGuards) case .vpnPromotion: @@ -131,37 +131,59 @@ extension BrowserViewController { present(popup, animated: false) } - private func presentDefaultBrowserScreenCallout() { - let onboardingController = WelcomeViewController( - state: WelcomeViewCalloutState.defaultBrowserCallout( - info: WelcomeViewCalloutState.WelcomeViewDefaultBrowserDetails( - title: Strings.Callout.defaultBrowserCalloutTitle, - details: Strings.Callout.defaultBrowserCalloutDescription, - primaryButtonTitle: Strings.Callout.defaultBrowserCalloutPrimaryButtonTitle, - secondaryButtonTitle: Strings.Callout.defaultBrowserCalloutSecondaryButtonTitle, - primaryButtonAction: { [weak self] in - guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { - return + private func presentDefaultBrowserScreenCallout(skipSafeGuards: Bool = false) { + if !Locale.current.isNewOnboardingRegion { + let onboardingController = WelcomeViewController( + state: WelcomeViewCalloutState.defaultBrowserCallout( + info: WelcomeViewCalloutState.WelcomeViewDefaultBrowserDetails( + title: Strings.Callout.defaultBrowserCalloutTitle, + details: Strings.Callout.defaultBrowserCalloutDescription, + primaryButtonTitle: Strings.Callout.defaultBrowserCalloutPrimaryButtonTitle, + secondaryButtonTitle: Strings.Callout.defaultBrowserCalloutSecondaryButtonTitle, + primaryButtonAction: { [weak self] in + guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { + return + } + + Preferences.General.defaultBrowserCalloutDismissed.value = true + self?.isOnboardingOrFullScreenCalloutPresented = true + + UIApplication.shared.open(settingsUrl) + self?.dismiss(animated: false) + }, + secondaryButtonAction: { [weak self] in + self?.isOnboardingOrFullScreenCalloutPresented = true + + self?.dismiss(animated: false) } + ) + ), + p3aUtilities: braveCore.p3aUtils, + attributionManager: attributionManager + ) + present(onboardingController, animated: true) + return + } - Preferences.General.defaultBrowserCalloutDismissed.value = true - self?.isOnboardingOrFullScreenCalloutPresented = true + if !skipSafeGuards { + let isLikelyDefault = DefaultBrowserHelper.isBraveLikelyDefaultBrowser() - UIApplication.shared.open(settingsUrl) - self?.dismiss(animated: false) - }, - secondaryButtonAction: { [weak self] in - self?.isOnboardingOrFullScreenCalloutPresented = true + guard !isLikelyDefault else { + return + } + } - self?.dismiss(animated: false) - } - ) - ), - p3aUtilities: braveCore.p3aUtils, - attributionManager: attributionManager - ) + let defaultBrowserCallout = UIHostingController( + rootView: FocusSystemSettingsView( + screenType: .callout, + shouldDismiss: Binding.constant(false) + ) + ).then { + $0.isModalInPresentation = true + $0.modalPresentationStyle = .overFullScreen + } - present(onboardingController, animated: true) + present(defaultBrowserCallout, animated: true) } private func presentBraveRewardsScreenCallout(skipSafeGuards: Bool = false) { diff --git a/ios/brave-ios/Sources/Onboarding/ProductNotifications/FullScreenCalloutManager.swift b/ios/brave-ios/Sources/Onboarding/ProductNotifications/FullScreenCalloutManager.swift index 805f1b28005b..df0bb6965573 100644 --- a/ios/brave-ios/Sources/Onboarding/ProductNotifications/FullScreenCalloutManager.swift +++ b/ios/brave-ios/Sources/Onboarding/ProductNotifications/FullScreenCalloutManager.swift @@ -28,7 +28,7 @@ public enum FullScreenCalloutType: CaseIterable { case .vpnUpdateBilling: return 0 case .bottomBar: return 0 case .vpnPromotion: return 4 - case .defaultBrowser: return 10 + case .defaultBrowser: return Locale.current.isNewOnboardingRegion ? 7 : 10 case .rewards: return 8 case .vpnLinkReceipt: return 0 } diff --git a/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusP3AScreenView.swift b/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusP3AScreenView.swift index bbdc7697011c..0729d6ae7b9a 100644 --- a/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusP3AScreenView.swift +++ b/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusP3AScreenView.swift @@ -53,7 +53,7 @@ struct FocusP3AScreenView: View { .background(Color(braveSystemName: .pageBackground)) .background { NavigationLink("", isActive: $isSystemSettingsViewPresented) { - FocusSystemSettingsView(shouldDismiss: $shouldDismiss) + FocusSystemSettingsView(screenType: .onboarding, shouldDismiss: $shouldDismiss) } } .toolbar(.hidden, for: .navigationBar) @@ -66,7 +66,7 @@ struct FocusP3AScreenView: View { .background(Color(braveSystemName: .pageBackground)) .background { NavigationLink("", isActive: $isSystemSettingsViewPresented) { - FocusSystemSettingsView(shouldDismiss: $shouldDismiss) + FocusSystemSettingsView(screenType: .onboarding, shouldDismiss: $shouldDismiss) } } .toolbar(.hidden, for: .navigationBar) diff --git a/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusSystemSettingsView.swift b/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusSystemSettingsView.swift index 0252f089b8fa..f5bfe10d1558 100644 --- a/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusSystemSettingsView.swift +++ b/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusSystemSettingsView.swift @@ -8,20 +8,36 @@ import Lottie import Preferences import SwiftUI -struct FocusSystemSettingsView: View { +public struct FocusSystemSettingsView: View { + + public enum DefaultBrowserScreenType { + case onboarding, callout + } + @Environment(\.colorScheme) private var colorScheme + @Environment(\.dismiss) var dismiss @Environment(\.verticalSizeClass) private var verticalSizeClass: UserInterfaceSizeClass? @Environment(\.horizontalSizeClass) private var horizontalSizeClass: UserInterfaceSizeClass? @Binding var shouldDismiss: Bool + var screenType: DefaultBrowserScreenType + private var shouldUseExtendedDesign: Bool { return horizontalSizeClass == .regular && verticalSizeClass == .regular } private let dynamicTypeRange = (...DynamicTypeSize.xLarge) - var body: some View { + public init( + screenType: DefaultBrowserScreenType, + shouldDismiss: Binding + ) { + self.screenType = screenType + self._shouldDismiss = shouldDismiss + } + + public var body: some View { if shouldUseExtendedDesign { VStack(spacing: 40) { VStack { @@ -33,7 +49,9 @@ struct FocusSystemSettingsView: View { .shadow(color: .black.opacity(0.1), radius: 18, x: 0, y: 8) .shadow(color: .black.opacity(0.05), radius: 0, x: 0, y: 1) - FocusStepsPagingIndicator(totalPages: 4, activeIndex: .constant(3)) + if screenType == .onboarding { + FocusStepsPagingIndicator(totalPages: 4, activeIndex: .constant(3)) + } } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color(braveSystemName: .pageBackground)) @@ -41,7 +59,10 @@ struct FocusSystemSettingsView: View { } else { VStack(spacing: 16) { settingsSystemContentView - FocusStepsPagingIndicator(totalPages: 4, activeIndex: .constant(3)) + + if screenType == .onboarding { + FocusStepsPagingIndicator(totalPages: 4, activeIndex: .constant(3)) + } } .padding(.bottom, 20) .background(Color(braveSystemName: .pageBackground)) @@ -97,8 +118,7 @@ struct FocusSystemSettingsView: View { UIApplication.shared.open(settingsUrl) } - Preferences.FocusOnboarding.urlBarIndicatorShowBeShown.value = true - shouldDismiss = true + completeDefaultBrowserInteraction() }, label: { Text(Strings.FocusOnboarding.systemSettingsButtonTitle) @@ -119,12 +139,13 @@ struct FocusSystemSettingsView: View { Button( action: { - Preferences.FocusOnboarding.urlBarIndicatorShowBeShown.value = true - shouldDismiss = true + completeDefaultBrowserInteraction() }, label: { Text( - "\(Strings.FocusOnboarding.startBrowseActionButtonTitle) \(Image(systemName: "arrow.right"))" + screenType == .onboarding + ? "\(Strings.FocusOnboarding.startBrowseActionButtonTitle) \(Image(systemName: "arrow.right"))" + : "\(Strings.FocusOnboarding.notNowActionButtonTitle)" ) .font(.subheadline.weight(.semibold)) .foregroundColor(Color(braveSystemName: .textInteractive)) @@ -143,6 +164,15 @@ struct FocusSystemSettingsView: View { .padding(.vertical, shouldUseExtendedDesign ? 48 : 24) .padding(.horizontal, shouldUseExtendedDesign ? 75 : 20) } + + private func completeDefaultBrowserInteraction() { + if screenType == .onboarding { + Preferences.FocusOnboarding.urlBarIndicatorShowBeShown.value = true + shouldDismiss = true + } else { + dismiss() + } + } } #if DEBUG @@ -150,7 +180,9 @@ struct FocusSystemSettingsView_Previews: PreviewProvider { static var previews: some View { @State var shouldDismiss: Bool = false - FocusSystemSettingsView(shouldDismiss: $shouldDismiss) + FocusSystemSettingsView(screenType: .onboarding, shouldDismiss: $shouldDismiss) + + FocusSystemSettingsView(screenType: .callout, shouldDismiss: $shouldDismiss) } } #endif diff --git a/ios/brave-ios/Sources/Onboarding/WelcomeFocus/Resources/FocusOnboardingStrings.swift b/ios/brave-ios/Sources/Onboarding/WelcomeFocus/Resources/FocusOnboardingStrings.swift index e82b1977d513..bb27b820f40a 100644 --- a/ios/brave-ios/Sources/Onboarding/WelcomeFocus/Resources/FocusOnboardingStrings.swift +++ b/ios/brave-ios/Sources/Onboarding/WelcomeFocus/Resources/FocusOnboardingStrings.swift @@ -120,6 +120,14 @@ extension Strings { comment: "The title of the button that finishes the onboarding without setting default" ) + public static let notNowActionButtonTitle = NSLocalizedString( + "focusOnboarding.notNowActionButtonTitle", + tableName: "FocusOnboarding", + bundle: .module, + value: "Not Now", + comment: "The title of the button that closes the default browser full screen callout" + ) + public static let urlBarIndicatorTitle = NSLocalizedString( "focusOnboarding.urlBarIndicatorTitle", tableName: "FocusOnboarding",