Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #7860: Default Browser Prompt NTP - Logic Change (#7892)
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel authored Aug 17, 2023
1 parent d9113d8 commit 7d8c78b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3162,6 +3162,9 @@ extension BrowserViewController {
}

public func handleNavigationPath(path: NavigationPath) {
// Remove Default Browser Callout if an external url is triggered
Preferences.General.defaultBrowserCalloutDismissed.value = true

executeAfterSetup {
NavigationPath.handle(nav: path, with: self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ extension BrowserViewController {
return false
}

if presentedViewController != nil || !FullScreenCalloutManager.shouldShowDefaultBrowserCallout(calloutType: calloutType) {
if presentedViewController != nil || !FullScreenCalloutManager.shouldShowCallout(calloutType: calloutType) {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class NewTabPageViewController: UIViewController {

// This is a one-off view, adding it to the NTP only if necessary.
if NTPDefaultBrowserCalloutProvider.shouldShowCallout {
// Never show Default Browser Notification over an NPT SI
if let ntpBackground = background.currentBackground, case .sponsoredImage = ntpBackground {
return
}
sections.insert(NTPDefaultBrowserCalloutProvider(), at: 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,29 @@ class NTPDefaultBrowserCalloutProvider: NSObject, NTPObservableSectionProvider {
private typealias DefaultBrowserCalloutCell = NewTabCenteredCollectionViewCell<DefaultBrowserCalloutView>

static var shouldShowCallout: Bool {
!Preferences.General.defaultBrowserCalloutDismissed.value &&
let defaultBrowserDisplayCriteria = !Preferences.General.defaultBrowserCalloutDismissed.value &&
!Preferences.Onboarding.basicOnboardingDefaultBrowserSelected.value &&
AppConstants.buildChannel == .release

guard let appRetentionLaunchDate = Preferences.DAU.appRetentionLaunchDate.value else {
return defaultBrowserDisplayCriteria
}

// User should not see default browser first 7 days
// also after 14 days
var defaultBrowserTimeConstraintCriteria = false

let rightNow = Date()
let first7DayPeriod = appRetentionLaunchDate.addingTimeInterval(
AppConstants.buildChannel.isPublic ? 7.days : 7.minutes)
let first14DayPeriod = appRetentionLaunchDate.addingTimeInterval(
AppConstants.buildChannel.isPublic ? 17.days : 14.minutes)

if rightNow > first7DayPeriod, rightNow < first14DayPeriod {
defaultBrowserTimeConstraintCriteria = true
}

return defaultBrowserDisplayCriteria && defaultBrowserTimeConstraintCriteria
}

func registerCells(to collectionView: UICollectionView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public enum FullScreenCalloutType: CaseIterable {
public struct FullScreenCalloutManager {
/// 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.
public static func shouldShowDefaultBrowserCallout(calloutType: FullScreenCalloutType) -> Bool {
public static func shouldShowCallout(calloutType: FullScreenCalloutType) -> Bool {
guard Preferences.Onboarding.isNewRetentionUser.value == true,
let appRetentionLaunchDate = Preferences.DAU.appRetentionLaunchDate.value,
!calloutType.preferenceValue.value
Expand Down

0 comments on commit 7d8c78b

Please sign in to comment.