This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Soner Yuksel <grkmyksl@gmail.com>
- Loading branch information
1 parent
d70a0cc
commit df087be
Showing
23 changed files
with
562 additions
and
13 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
Client/Assets/Images.xcassets/Shields/cookie-consent-animation-dark.dataset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"data" : [ | ||
{ | ||
"filename" : "dark-mode.gif", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+560 KB
...ets/Images.xcassets/Shields/cookie-consent-animation-dark.dataset/dark-mode.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions
13
Client/Assets/Images.xcassets/Shields/cookie-consent-animation.dataset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"data" : [ | ||
{ | ||
"filename" : "light-mode.gif", | ||
"idiom" : "universal", | ||
"universal-type-identifier" : "com.compuserve.gif" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+563 KB
.../Assets/Images.xcassets/Shields/cookie-consent-animation.dataset/light-mode.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18 KB
.../Images.xcassets/Shields/cookie-consent-background.imageset/Background@2x-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.8 KB
...ts/Images.xcassets/Shields/cookie-consent-background.imageset/Background@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29.2 KB
.../Images.xcassets/Shields/cookie-consent-background.imageset/Background@3x-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+26.4 KB
...ts/Images.xcassets/Shields/cookie-consent-background.imageset/Background@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
Client/Assets/Images.xcassets/Shields/cookie-consent-background.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "dark" | ||
} | ||
], | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "Background@2x.png", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "dark" | ||
} | ||
], | ||
"filename" : "Background@2x-1.png", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "Background@3x.png", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "dark" | ||
} | ||
], | ||
"filename" : "Background@3x-1.png", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "original" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...tend/Browser/BrowserViewController/BrowserViewController+CookieNotificationBlocking.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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 Foundation | ||
import SwiftUI | ||
import BraveUI | ||
import BraveShared | ||
import Data | ||
|
||
extension BrowserViewController { | ||
func presentCookieNotificationBlockingCalloutIfNeeded() { | ||
// Don't show this if we already enabled the setting | ||
guard !FilterListResourceDownloader.shared.isEnabled(for: FilterList.cookieConsentNoticesComponentID) else { return } | ||
// Don't show this if we are presenting another popup already | ||
guard !isOnboardingOrFullScreenCalloutPresented else { return } | ||
// We only show the popup on second launch | ||
guard !Preferences.General.isFirstLaunch.value else { return } | ||
// Ensure we successfully shown basic onboarding first | ||
guard Preferences.FullScreenCallout.omniboxCalloutCompleted.value else { return } | ||
|
||
// Make sure we didn't already show this popup | ||
guard presentedViewController == nil && FullScreenCalloutManager.shouldShowDefaultBrowserCallout(calloutType: .blockCookieConsentNotices) else { | ||
return | ||
} | ||
|
||
let popover = PopoverController( | ||
contentController: CookieNotificationBlockingConsentViewController(), | ||
contentSizeBehavior: .preferredContentSize) | ||
popover.addsConvenientDismissalMargins = false | ||
popover.present(from: topToolbar.locationView.shieldsButton, on: self) | ||
} | ||
} | ||
|
||
class CookieNotificationBlockingConsentViewController: UIHostingController<CookieNotificationBlockingConsentView>, PopoverContentComponent { | ||
init() { | ||
super.init(rootView: CookieNotificationBlockingConsentView()) | ||
|
||
self.preferredContentSize = CGSize( | ||
width: CookieNotificationBlockingConsentView.contentWidth, | ||
height: CookieNotificationBlockingConsentView.contentHeight | ||
) | ||
|
||
self.rootView.onDismiss = { [weak self] in | ||
self?.dismiss(animated: true) | ||
} | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = UIColor.braveBackground | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
Client/Frontend/Popup/CookieNotificationBlockingConsentView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// 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 SwiftUI | ||
import Strings | ||
import DesignSystem | ||
import BraveShared | ||
|
||
struct CookieNotificationBlockingConsentView: View { | ||
public static let contentHeight = 480.0 | ||
public static let contentWidth = 344.0 | ||
private static let gifHeight = 328.0 | ||
private static let bottomSectionHeight = contentHeight - gifHeight | ||
private static let textPadding = 16.0 | ||
|
||
private let animation = Animation.easeOut(duration: 0.5).delay(0) | ||
private let transition = AnyTransition.scale(scale: 1.1).combined(with: .opacity) | ||
|
||
@Environment(\.presentationMode) @Binding private var presentationMode | ||
@State private var showAnimation = false | ||
var onDismiss: (() -> Void)? | ||
|
||
private var yesButton: some View { | ||
Button(Strings.yesBlockCookieConsentNotices) { | ||
withAnimation(animation) { | ||
self.showAnimation = true | ||
} | ||
|
||
if !FilterListResourceDownloader.shared.enableFilterList(for: FilterList.cookieConsentNoticesComponentID, isEnabled: true) { | ||
assertionFailure("This filter list should exist or this UI is completely useless") | ||
} | ||
|
||
Task { @MainActor in | ||
try await Task.sleep(seconds: 3.5) | ||
self.dismiss() | ||
} | ||
} | ||
.buttonStyle(BraveFilledButtonStyle(size: .large)) | ||
.multilineTextAlignment(.center) | ||
.transition(transition) | ||
} | ||
|
||
private var noButton: some View { | ||
Button(Strings.noThanks) { | ||
self.dismiss() | ||
} | ||
.font(Font.body.weight(.semibold)) | ||
.foregroundColor(.accentColor) | ||
.multilineTextAlignment(.center) | ||
.transition(transition) | ||
} | ||
|
||
var body: some View { | ||
ScrollView { | ||
VStack { | ||
VStack { | ||
if !showAnimation { | ||
VStack(spacing: Self.textPadding) { | ||
Text(Strings.blockCookieConsentNoticesPopupTitle).font(.title) | ||
Text(Strings.blockCookieConsentNoticesPopupDescription).font(.body) | ||
} | ||
.transition(transition) | ||
.padding(Self.textPadding) | ||
.padding(.top, 80) | ||
.foregroundColor(Color(UIColor.braveLabel)) | ||
.multilineTextAlignment(.center) | ||
.fixedSize(horizontal: false, vertical: true) | ||
} | ||
} | ||
.frame(width: Self.contentWidth) | ||
.frame(minHeight: Self.gifHeight) | ||
.background( | ||
GIFImage(asset: "cookie-consent-animation", animate: showAnimation) | ||
.frame(width: Self.contentWidth, height: Self.gifHeight, alignment: .top), | ||
alignment: .top | ||
) | ||
|
||
VStack(spacing: Self.textPadding) { | ||
if !showAnimation { | ||
yesButton | ||
noButton | ||
} | ||
} | ||
.padding(Self.textPadding) | ||
} | ||
} | ||
.frame(width: Self.contentWidth, height: Self.contentHeight) | ||
.background( | ||
Image("cookie-consent-background", bundle: .module), | ||
alignment: .bottomLeading | ||
) | ||
.background(Color(UIColor.braveBackground)) | ||
} | ||
|
||
private func dismiss() { | ||
// Dismiss on presentation mode does not work on iOS 14 | ||
// when using the UIHostingController is parent view. | ||
// As a workaround a completion handler is used instead. | ||
if #available(iOS 15, *) { | ||
presentationMode.dismiss() | ||
} else { | ||
onDismiss?() | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct CookieNotificationBlockingConsentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
CookieNotificationBlockingConsentView() | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.