Skip to content

Commit

Permalink
Merge pull request #25476 from brave/ios/enhancement/default-browser-…
Browse files Browse the repository at this point in the history
…logic

[iOS] Display new Default Browser prompt in the new onboarding regions
  • Loading branch information
kylehickinson committed Sep 13, 2024
2 parents 4b0f291 + f0d6135 commit 3903779
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension BrowserViewController {
case .bottomBar:
presentBottomBarCallout(skipSafeGuards: skipSafeGuards)
case .defaultBrowser:
presentDefaultBrowserScreenCallout()
presentDefaultBrowserScreenCallout(skipSafeGuards: skipSafeGuards)
case .rewards:
presentBraveRewardsScreenCallout(skipSafeGuards: skipSafeGuards)
case .vpnPromotion:
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bool>
) {
self.screenType = screenType
self._shouldDismiss = shouldDismiss
}

public var body: some View {
if shouldUseExtendedDesign {
VStack(spacing: 40) {
VStack {
Expand All @@ -33,15 +49,20 @@ 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))
.toolbar(.hidden, for: .navigationBar)
} 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))
Expand Down Expand Up @@ -97,8 +118,7 @@ struct FocusSystemSettingsView: View {
UIApplication.shared.open(settingsUrl)
}

Preferences.FocusOnboarding.urlBarIndicatorShowBeShown.value = true
shouldDismiss = true
completeDefaultBrowserInteraction()
},
label: {
Text(Strings.FocusOnboarding.systemSettingsButtonTitle)
Expand All @@ -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))
Expand All @@ -143,14 +164,25 @@ 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3903779

Please sign in to comment.