From 2f5817ff56a8fcdf68baac70817918ea34c63473 Mon Sep 17 00:00:00 2001 From: Soner Yuksel Date: Wed, 2 Nov 2022 08:14:13 -0400 Subject: [PATCH] Adding p3a transparent callout, logic is added --- App/iOS/Delegates/AppDelegate.swift | 4 +- .../Browser/BrowserViewController.swift | 23 ++--- .../BrowserViewController/BVC+Rewards.swift | 2 +- .../BrowserViewController+Callout.swift | 40 ++++++++ .../BrowserViewController+Onboarding.swift | 4 +- ...erViewController+ProductNotification.swift | 2 +- Client/Frontend/ClientPreferences.swift | 39 -------- ...onPreferencesDebugMenuViewController.swift | 4 +- .../DataSourceExtensions.swift | 0 .../UIViewExtensions.swift | 0 .../Onboarding/OnboardingPreferences.swift | 63 +++++++++++- .../OnboardingWebViewController.swift | 14 +-- .../Resources}/FullScreenCalloutManager.swift | 29 +++--- .../Welcome/Welcome3PAViewController.swift | 96 +++++++++++++++++++ .../Welcome/WelcomeViewController.swift | 44 +++++---- 15 files changed, 266 insertions(+), 98 deletions(-) rename Sources/BraveUI/{UIKit => Extensions}/DataSourceExtensions.swift (100%) rename Sources/BraveUI/{UIKit => Extensions}/UIViewExtensions.swift (100%) rename {Client/Frontend/Browser => Sources/Onboarding/ProductNotifications/Resources}/FullScreenCalloutManager.swift (60%) create mode 100644 Sources/Onboarding/Welcome/Welcome3PAViewController.swift diff --git a/App/iOS/Delegates/AppDelegate.swift b/App/iOS/Delegates/AppDelegate.swift index 81ee1112603..59546bee5eb 100644 --- a/App/iOS/Delegates/AppDelegate.swift +++ b/App/iOS/Delegates/AppDelegate.swift @@ -269,8 +269,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } // Check if user has launched the application before and determine if it is a new retention user - if Preferences.General.isFirstLaunch.value, Preferences.General.isNewRetentionUser.value == nil { - Preferences.General.isNewRetentionUser.value = true + if Preferences.General.isFirstLaunch.value, Preferences.Onboarding.isNewRetentionUser.value == nil { + Preferences.Onboarding.isNewRetentionUser.value = true } if Preferences.DAU.appRetentionLaunchDate.value == nil { diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 8285eeab95d..71a27a4110e 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -1112,21 +1112,22 @@ public class BrowserViewController: UIViewController { } override public func viewDidAppear(_ animated: Bool) { - // Passcode Migration has highest priority, it should be presented over everything else - presentPassCodeMigration() - - // Present Onboarding to new users, existing users will not see the onboarding - presentOnboardingIntro() - - // Full Screen Callout Presentation - // Priority: VPN - Default Browser - Rewards - Sync - // TODO: Remove the dispatch after with a proper fix and fix calling present functions before super.viewDidAppear - DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { +// // Passcode Migration has highest priority, it should be presented over everything else +// presentPassCodeMigration() +// +// // Present Onboarding to new users, existing users will not see the onboarding +// presentOnboardingIntro() +// +// // Full Screen Callout Presentation +// // Priority: P3A - VPN - Default Browser - Rewards +// // TODO: Remove the dispatch after with a proper fix and fix calling present functions before super.viewDidAppear +// DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { + self.presentP3AScreenCallout() self.presentVPNAlertCallout() self.presentDefaultBrowserScreenCallout() self.presentBraveRewardsScreenCallout() self.presentCookieNotificationBlockingCalloutIfNeeded() - } +// } screenshotHelper.viewIsVisible = true screenshotHelper.takePendingScreenshots(tabManager.allTabs) diff --git a/Client/Frontend/Browser/BrowserViewController/BVC+Rewards.swift b/Client/Frontend/Browser/BrowserViewController/BVC+Rewards.swift index d8eab507bed..572ccadb4fd 100644 --- a/Client/Frontend/Browser/BrowserViewController/BVC+Rewards.swift +++ b/Client/Frontend/Browser/BrowserViewController/BVC+Rewards.swift @@ -37,7 +37,7 @@ extension BrowserViewController { func showBraveRewardsPanel() { if !Preferences.FullScreenCallout.rewardsCalloutCompleted.value, - Preferences.General.isNewRetentionUser.value == true, + Preferences.Onboarding.isNewRetentionUser.value == true, !Preferences.Rewards.rewardsToggledOnce.value { let controller = OnboardingRewardsAgreementViewController() diff --git a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+Callout.swift b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+Callout.swift index efec1432b5f..0af5bef6dd5 100644 --- a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+Callout.swift +++ b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+Callout.swift @@ -29,6 +29,46 @@ extension BrowserViewController { present(controller, animated: false) } } + + func presentP3AScreenCallout() { +// if Preferences.DebugFlag.skipNTPCallouts == true || isOnboardingOrFullScreenCalloutPresented { return } +// +// if presentedViewController != nil || !FullScreenCalloutManager.shouldShowDefaultBrowserCallout(calloutType: .p3a) { +// return +// } + +// let onboardingP3ACalloutController = WelcomeViewController(p3aUtilities: braveCore.p3aUtils) + + let onboardingP3ACalloutController = Welcome3PAViewController(p3aUtilities: braveCore.p3aUtils) + + let state = WelcomeViewCalloutState.p3a( + info: WelcomeViewCalloutState.WelcomeViewDefaultBrowserDetails( + title: "Help make Brave better.", + toggleTitle: "Share anonymous, private product insights.", + details: "This helps us learn what Brave features are used most often. Change this at any time in Brave Settings under ‘Brave Shields and Privacy’.", + linkDescription: "Learn more about our Privacy Preserving Product Analytics (P3A).", + primaryButtonTitle: "Done", + toggleAction: { [weak self] isOn in + self?.braveCore.p3aUtils.isP3AEnabled = isOn + }, + linkAction: { url in + onboardingP3ACalloutController.present(OnboardingWebViewController(url: .p3aDescription), animated: true, completion: nil) + }, + primaryButtonAction: { [weak self] in + Preferences.Onboarding.p3aOnboardingShown.value = true + + self?.isOnboardingOrFullScreenCalloutPresented = true + self?.dismiss(animated: false) + } + ) + ) + + onboardingP3ACalloutController.setLayoutState(state: state) + + if !isOnboardingOrFullScreenCalloutPresented { + present(onboardingP3ACalloutController, animated: true) + } + } func presentVPNAlertCallout() { if Preferences.DebugFlag.skipNTPCallouts == true || isOnboardingOrFullScreenCalloutPresented { return } diff --git a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+Onboarding.swift b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+Onboarding.swift index 625ef1692bf..fc1a4a7c1a8 100644 --- a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+Onboarding.swift +++ b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+Onboarding.swift @@ -32,7 +32,7 @@ extension BrowserViewController { // 1. User is brand new // 2. User hasn't completed onboarding if Preferences.Onboarding.basicOnboardingCompleted.value != OnboardingState.completed.rawValue, - Preferences.General.isNewRetentionUser.value == true { + Preferences.Onboarding.isNewRetentionUser.value == true { let onboardingController = WelcomeViewController(p3aUtilities: braveCore.p3aUtils) onboardingController.modalPresentationStyle = .fullScreen parentController.present(onboardingController, animated: false) @@ -58,7 +58,7 @@ extension BrowserViewController { Preferences.DebugFlag.skipNTPCallouts != true { if !Preferences.FullScreenCallout.omniboxCalloutCompleted.value, - Preferences.General.isNewRetentionUser.value == true { + Preferences.Onboarding.isNewRetentionUser.value == true { presentOmniBoxOnboarding() addNTPTutorialPage() } diff --git a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+ProductNotification.swift b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+ProductNotification.swift index efab21b3944..f905eb06e86 100644 --- a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+ProductNotification.swift +++ b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+ProductNotification.swift @@ -43,7 +43,7 @@ extension BrowserViewController { !Preferences.General.onboardingAdblockPopoverShown.value, !benchmarkNotificationPresented, !Preferences.AppState.backgroundedCleanly.value, - Preferences.General.isNewRetentionUser.value == true, + Preferences.Onboarding.isNewRetentionUser.value == true, !topToolbar.inOverlayMode, !isTabTrayActive, selectedTab.webView?.scrollView.isDragging == false, diff --git a/Client/Frontend/ClientPreferences.swift b/Client/Frontend/ClientPreferences.swift index 8f06addd611..a6f726104ed 100644 --- a/Client/Frontend/ClientPreferences.swift +++ b/Client/Frontend/ClientPreferences.swift @@ -62,8 +62,6 @@ extension Preferences { final public class General { /// Whether this is the first time user has ever launched Brave after intalling. *Should never be set to `true` manually!* public static let isFirstLaunch = Option(key: "general.first-launch", default: true) - /// Whether this is a new user who installed the application after onboarding retention updates - public static let isNewRetentionUser = Option(key: "general.new-retention", default: nil) /// Whether or not to save logins in Brave static let saveLogins = Option(key: "general.save-logins", default: true) /// Whether or not to block popups from websites automaticaly @@ -112,43 +110,6 @@ extension Preferences { static let isUsingBottomBar = Option(key: "general.bottom-bar", default: false) } - final public class FullScreenCallout { - /// Whether the block cookie consent notices callout is shown. - static let blockCookieConsentNoticesCalloutCompleted = - Option(key: "fullScreenCallout.full-screen-cookie-consent-notices-callout-completed", default: false) - - /// Whether the vpn callout is shown. - static let vpnCalloutCompleted = - Option(key: "fullScreenCallout.full-screen-vpn-callout-completed", default: false) - - /// Whether the rewards callout is shown. - static let rewardsCalloutCompleted = - Option(key: "fullScreenCallout.full-screen-rewards-callout-completed", default: false) - - /// Whether the whats new callout should be shown. - static let whatsNewCalloutOptIn = - Option(key: "fullScreenCallout.full-screen-whats-new-callout-completed", default: false) - - /// Whether the ntp callout is shown. - static let ntpCalloutCompleted = - Option(key: "fullScreenCallout.full-screen-ntp-callout-completed", default: false) - - /// Whether the omnibox callout is shown. - static let omniboxCalloutCompleted = - Option(key: "fullScreenCallout.full-screen-omnibox-callout-completed", default: false) - } - - final public class DefaultBrowserIntro { - /// Whether the default browser onboarding completed. This can happen by opening app settings or after the user - /// dismissed the intro screen enough amount of times. - static let completed = - Option(key: "defaultBrowserIntro.intro-completed", default: false) - - /// Whether system notification showed or not - static let defaultBrowserNotificationScheduled = - Option(key: "general.default-browser-notification-scheduled", default: false) - } - final public class Search { /// Whether or not to show suggestions while the user types static let showSuggestions = Option(key: "search.show-suggestions", default: false) diff --git a/Client/Frontend/Settings/RetentionPreferencesDebugMenuViewController.swift b/Client/Frontend/Settings/RetentionPreferencesDebugMenuViewController.swift index cffad141e7a..4e2abb8fc4f 100644 --- a/Client/Frontend/Settings/RetentionPreferencesDebugMenuViewController.swift +++ b/Client/Frontend/Settings/RetentionPreferencesDebugMenuViewController.swift @@ -107,11 +107,11 @@ class RetentionPreferencesDebugMenuViewController: TableViewController { .boolRow( title: "Retention User", detailText: "Flag showing if the user installed the application after new onboarding is added.", - toggleValue: Preferences.General.isNewRetentionUser.value ?? false, + toggleValue: Preferences.Onboarding.isNewRetentionUser.value ?? false, valueChange: { if $0 { let status = $0 - Preferences.General.isNewRetentionUser.value = status + Preferences.Onboarding.isNewRetentionUser.value = status } }, cellReuseId: "RetentionUserCell"), diff --git a/Sources/BraveUI/UIKit/DataSourceExtensions.swift b/Sources/BraveUI/Extensions/DataSourceExtensions.swift similarity index 100% rename from Sources/BraveUI/UIKit/DataSourceExtensions.swift rename to Sources/BraveUI/Extensions/DataSourceExtensions.swift diff --git a/Sources/BraveUI/UIKit/UIViewExtensions.swift b/Sources/BraveUI/Extensions/UIViewExtensions.swift similarity index 100% rename from Sources/BraveUI/UIKit/UIViewExtensions.swift rename to Sources/BraveUI/Extensions/UIViewExtensions.swift diff --git a/Sources/Onboarding/OnboardingPreferences.swift b/Sources/Onboarding/OnboardingPreferences.swift index 94ee9159173..757d13e7284 100644 --- a/Sources/Onboarding/OnboardingPreferences.swift +++ b/Sources/Onboarding/OnboardingPreferences.swift @@ -15,11 +15,72 @@ extension Preferences { public static let basicOnboardingCompleted = Option( key: "general.basic-onboarding-completed", default: OnboardingState.undetermined.rawValue) + /// The time until the next on-boarding shows public static let basicOnboardingDefaultBrowserSelected = Option( key: "general.basic-onboarding-default-browser-selected", default: false) + /// The progress the user has made with onboarding - public static let basicOnboardingProgress = Option(key: "general.basic-onboarding-progress", default: OnboardingProgress.none.rawValue) + public static let basicOnboardingProgress = Option( + key: "general.basic-onboarding-progress", + default: OnboardingProgress.none.rawValue) + + /// The bool detemining if p3a infomartion is shown in onboarding to a user so they will not see it again as pop-over + public static let p3aOnboardingShown = Option( + key: "onboarding.basic-onboarding-default-browser-selected", + default: false) + + /// Whether this is a new user who installed the application after onboarding retention updates + public static let isNewRetentionUser = Option(key: "general.new-retention", default: nil) + } +} + +extension Preferences { + public final class FullScreenCallout { + /// Whether the block cookie consent notices callout is shown. + static let blockCookieConsentNoticesCalloutCompleted = Option( + key: "fullScreenCallout.full-screen-cookie-consent-notices-callout-completed", + default: false) + + /// Whether the vpn callout is shown. + public static let vpnCalloutCompleted = Option( + key: "fullScreenCallout.full-screen-vpn-callout-completed", + default: false) + + /// Whether the rewards callout is shown. + public static let rewardsCalloutCompleted = Option( + key: "fullScreenCallout.full-screen-rewards-callout-completed", + default: false) + + /// Whether the whats new callout should be shown. + public static let whatsNewCalloutOptIn = Option( + key: "fullScreenCallout.full-screen-whats-new-callout-completed", + default: false) + + /// Whether the ntp callout is shown. + public static let ntpCalloutCompleted = Option( + key: "fullScreenCallout.full-screen-ntp-callout-completed", + default: false) + + /// Whether the omnibox callout is shown. + public static let omniboxCalloutCompleted = Option( + key: "fullScreenCallout.full-screen-omnibox-callout-completed", + default: false) + } +} + +extension Preferences { + public final class DefaultBrowserIntro { + /// Whether the default browser onboarding completed. This can happen by opening app settings or after the user + /// dismissed the intro screen enough amount of times. + public static let completed = Option( + key: "defaultBrowserIntro.intro-completed", + default: false) + + /// Whether system notification showed or not + public static let defaultBrowserNotificationScheduled = Option( + key: "general.default-browser-notification-scheduled", + default: false) } } diff --git a/Sources/Onboarding/OnboardingWebViewController.swift b/Sources/Onboarding/OnboardingWebViewController.swift index 6e5e6725249..1e9aec3e475 100644 --- a/Sources/Onboarding/OnboardingWebViewController.swift +++ b/Sources/Onboarding/OnboardingWebViewController.swift @@ -10,9 +10,9 @@ import BraveUI import UIKit import Storage -class OnboardingWebViewController: UIViewController, WKNavigationDelegate { +public class OnboardingWebViewController: UIViewController, WKNavigationDelegate { - enum URLType { + public enum URLType { case termsOfService case privacyPolicy case p3aDescription @@ -52,7 +52,7 @@ class OnboardingWebViewController: UIViewController, WKNavigationDelegate { KVOs.forEach { webView.removeObserver(self, forKeyPath: $0.rawValue) } } - init(url: URLType) { + public init(url: URLType) { self.urlType = url super.init(nibName: nil, bundle: nil) } @@ -61,7 +61,7 @@ class OnboardingWebViewController: UIViewController, WKNavigationDelegate { fatalError("init(coder:) has not been implemented") } - override func viewDidLoad() { + public override func viewDidLoad() { super.viewDidLoad() let stackView = UIStackView().then { @@ -93,7 +93,7 @@ class OnboardingWebViewController: UIViewController, WKNavigationDelegate { toolbar.forwardButton.addTarget(self, action: #selector(onForward), for: .touchUpInside) } - override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) { + public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) { guard let webView = object as? WKWebView, let kp = keyPath, let path = KVOConstants(rawValue: kp) else { return } @@ -181,7 +181,7 @@ class OnboardingWebViewController: UIViewController, WKNavigationDelegate { toolbar.forwardButton.tintColor = webView.canGoForward ? UX.buttonEnabledColor : UX.buttonDisabledColor } - func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { + public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { let error = error as NSError if error.domain == "WebKitErrorDomain" && error.code == 102 { return @@ -197,7 +197,7 @@ class OnboardingWebViewController: UIViewController, WKNavigationDelegate { } } - func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { + public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { completionHandler(.performDefaultHandling, nil) } } diff --git a/Client/Frontend/Browser/FullScreenCalloutManager.swift b/Sources/Onboarding/ProductNotifications/Resources/FullScreenCalloutManager.swift similarity index 60% rename from Client/Frontend/Browser/FullScreenCalloutManager.swift rename to Sources/Onboarding/ProductNotifications/Resources/FullScreenCalloutManager.swift index d83237b82b3..3cfd59ea6da 100644 --- a/Client/Frontend/Browser/FullScreenCalloutManager.swift +++ b/Sources/Onboarding/ProductNotifications/Resources/FullScreenCalloutManager.swift @@ -7,36 +7,43 @@ import Foundation import Shared import BraveShared -struct FullScreenCalloutManager { +public struct FullScreenCalloutManager { - enum FullScreenCalloutType { - case vpn, rewards, defaultBrowser, blockCookieConsentNotices + public enum FullScreenCalloutType { + case p3a, vpn, rewards, defaultBrowser, blockCookieConsentNotices /// The number of days passed to show certain type of callout var period: Int { switch self { - case .blockCookieConsentNotices: return 0 + case .p3a: return 0 case .vpn: return 4 case .rewards: return 8 case .defaultBrowser: return 10 + case .blockCookieConsentNotices: return 0 } } /// The preference value stored for complete state - var preferenceValue: Preferences.Option { + public var preferenceValue: Preferences.Option { switch self { - case .blockCookieConsentNotices: return Preferences.FullScreenCallout.blockCookieConsentNoticesCalloutCompleted - case .vpn: return Preferences.FullScreenCallout.vpnCalloutCompleted - case .rewards: return Preferences.FullScreenCallout.rewardsCalloutCompleted - case .defaultBrowser: return Preferences.DefaultBrowserIntro.completed + case .p3a: + return Preferences.Onboarding.p3aOnboardingShown + case .vpn: + return Preferences.FullScreenCallout.vpnCalloutCompleted + case .rewards: + return Preferences.FullScreenCallout.rewardsCalloutCompleted + case .defaultBrowser: + return Preferences.DefaultBrowserIntro.completed + case .blockCookieConsentNotices: + return Preferences.FullScreenCallout.blockCookieConsentNoticesCalloutCompleted } } } /// It determines whether we should show show the designated callout or not and sets corresponding preferences accordingly. /// Returns true if the callout should be shown. - static func shouldShowDefaultBrowserCallout(calloutType: FullScreenCalloutType) -> Bool { - guard Preferences.General.isNewRetentionUser.value == true, + public static func shouldShowDefaultBrowserCallout(calloutType: FullScreenCalloutType) -> Bool { + guard Preferences.Onboarding.isNewRetentionUser.value == true, let appRetentionLaunchDate = Preferences.DAU.appRetentionLaunchDate.value, !calloutType.preferenceValue.value else { diff --git a/Sources/Onboarding/Welcome/Welcome3PAViewController.swift b/Sources/Onboarding/Welcome/Welcome3PAViewController.swift new file mode 100644 index 00000000000..7e5da4f4265 --- /dev/null +++ b/Sources/Onboarding/Welcome/Welcome3PAViewController.swift @@ -0,0 +1,96 @@ +// Copyright 2022 The Brave Authors. All rights reserved. +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import UIKit +import Shared +import BraveShared +import BraveUI +import BraveCore + +public class Welcome3PAViewController: UIViewController { + + private let backgroundView = UIView() + private let calloutView = WelcomeViewCallout() + + private let p3aUtilities: BraveP3AUtils + + public init(p3aUtilities: BraveP3AUtils) { + self.p3aUtilities = p3aUtilities + super.init(nibName: nil, bundle: nil) + + self.modalPresentationStyle = .fullScreen + self.loadViewIfNeeded() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public override func viewDidLoad() { + super.viewDidLoad() + + let backgroundView = UIView().then { + $0.backgroundColor = UIColor.black.withAlphaComponent(0.3) + } + + view.addSubview(backgroundView) + backgroundView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + + view.addSubview(calloutView) + calloutView.snp.makeConstraints { + + $0.leading.trailing.equalToSuperview() + + $0.centerY.centerX.equalToSuperview() + +// $0.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).inset(16) + } + + } + + public func setLayoutState(state: WelcomeViewCalloutState) { + calloutView.setState(state: state) + } +} + + +//// calloutView.do { +//// $0.setContentHuggingPriority(.init(rawValue: 5), for: .vertical) +//// } +// +// let backgroundView = UIView().then { +// $0.backgroundColor = UIColor.black.withAlphaComponent(0.3) +// } +// +// view.addSubview(backgroundView) +// backgroundView.snp.makeConstraints { +// $0.edges.equalToSuperview() +// } +// +// view.addSubview(calloutView) +// calloutView.snp.makeConstraints { +// $0.leading.trailing.equalToSuperview() +// $0.centerX.centerY.equalToSuperview() +// } +// +//// let stack = UIStackView().then { +//// $0.distribution = .equalSpacing +//// $0.axis = .vertical +//// $0.setContentHuggingPriority(.init(rawValue: 5), for: .vertical) +//// } +//// +//// view.addSubview(stack) +//// stack.snp.makeConstraints { +//// $0.leading.trailing.top.equalToSuperview() +//// $0.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).inset(16) +//// } +//// +//// stack.addStackViewItems( +//// .view(UIView.spacer(.vertical, amount: 1)), +//// .view(calloutView), +//// .view(UIView.spacer(.vertical, amount: 1))) +// } diff --git a/Sources/Onboarding/Welcome/WelcomeViewController.swift b/Sources/Onboarding/Welcome/WelcomeViewController.swift index ad321a3ad6e..c848a40d295 100644 --- a/Sources/Onboarding/Welcome/WelcomeViewController.swift +++ b/Sources/Onboarding/Welcome/WelcomeViewController.swift @@ -9,6 +9,7 @@ import SnapKit import BraveShared import Shared import BraveCore +import BraveUI private enum WelcomeViewID: Int { case background = 1 @@ -29,7 +30,6 @@ public class WelcomeViewController: UIViewController { self.init(state: .loading, p3aUtilities: p3aUtilities) } - public init(state: WelcomeViewCalloutState?, p3aUtilities: BraveP3AUtils) { self.state = state self.p3aUtilities = p3aUtilities @@ -200,7 +200,7 @@ public class WelcomeViewController: UIViewController { } } - private func setLayoutState(state: WelcomeViewCalloutState) { + public func setLayoutState(state: WelcomeViewCalloutState) { self.state = state switch state { @@ -357,28 +357,30 @@ public class WelcomeViewController: UIViewController { private func animateToP3aState() { let nextController = WelcomeViewController(state: nil, p3aUtilities: self.p3aUtilities) - let state = WelcomeViewCalloutState.p3a( - info: WelcomeViewCalloutState.WelcomeViewDefaultBrowserDetails( - title: "Help make Brave better.", - toggleTitle: "Share anonymous, private product insights.", - details: "This helps us learn what Brave features are used most often. Change this at any time in Brave Settings under ‘Brave Shields and Privacy’.", - linkDescription: "Learn more about our Privacy Preserving Product Analytics (P3A).", - primaryButtonTitle: "Done", - toggleAction: { [weak self] isOn in - self?.p3aUtilities.isP3AEnabled = isOn - }, - linkAction: { url in - nextController.present(OnboardingWebViewController(url: .p3aDescription), animated: true, completion: nil) - }, - - primaryButtonAction: { [weak self] in - self?.close() - } - ) + let state = WelcomeViewCalloutState.p3a( + info: WelcomeViewCalloutState.WelcomeViewDefaultBrowserDetails( + title: "Help make Brave better.", + toggleTitle: "Share anonymous, private product insights.", + details: "This helps us learn what Brave features are used most often. Change this at any time in Brave Settings under ‘Brave Shields and Privacy’.", + linkDescription: "Learn more about our Privacy Preserving Product Analytics (P3A).", + primaryButtonTitle: "Done", + toggleAction: { [weak self] isOn in + self?.p3aUtilities.isP3AEnabled = isOn + }, + linkAction: { url in + nextController.present(OnboardingWebViewController(url: .p3aDescription), animated: true, completion: nil) + }, + + primaryButtonAction: { [weak self] in + self?.close() + } ) + ) nextController.setLayoutState(state: state) - present(nextController, animated: true) + present(nextController, animated: true) { + Preferences.Onboarding.p3aOnboardingShown.value = true + } } private func onSetDefaultBrowser() {