forked from wordpress-mobile/WordPress-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wordpress-mobile#21012 from wordpress-mobile/compl…
…iance-pop-up [EU/US Compliance] Wire up popover to the flow
- Loading branch information
Showing
13 changed files
with
429 additions
and
30 deletions.
There are no files selected for viewing
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
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
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
7 changes: 7 additions & 0 deletions
7
WordPress/Classes/ViewRelated/EEUUSCompliance/ComplianceLocationService.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,7 @@ | ||
import WordPressKit | ||
|
||
final class ComplianceLocationService { | ||
func getIPCountryCode(completion: @escaping (Result<String, Error>) -> Void) { | ||
IPLocationRemote().fetchIPCountryCode(completion: completion) | ||
} | ||
} |
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
112 changes: 112 additions & 0 deletions
112
WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverCoordinator.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,112 @@ | ||
import UIKit | ||
|
||
protocol CompliancePopoverCoordinatorProtocol { | ||
func presentIfNeeded() | ||
func navigateToSettings() | ||
func dismiss() | ||
} | ||
|
||
final class CompliancePopoverCoordinator: CompliancePopoverCoordinatorProtocol { | ||
private let viewController: UIViewController | ||
private let complianceService = ComplianceLocationService() | ||
private let defaults: UserDefaults | ||
|
||
init(viewController: UIViewController, defaults: UserDefaults = UserDefaults.standard) { | ||
self.viewController = viewController | ||
self.defaults = defaults | ||
} | ||
|
||
func presentIfNeeded() { | ||
guard FeatureFlag.compliancePopover.enabled else { | ||
return | ||
} | ||
complianceService.getIPCountryCode { [weak self] result in | ||
if case .success(let countryCode) = result { | ||
guard let self, self.shouldShowPrivacyBanner(countryCode: countryCode) else { | ||
return | ||
} | ||
DispatchQueue.main.async { | ||
self.presentPopover() | ||
} | ||
} | ||
} | ||
} | ||
|
||
func navigateToSettings() { | ||
viewController.dismiss(animated: true) { | ||
RootViewCoordinator.sharedPresenter.navigateToPrivacySettings() | ||
} | ||
} | ||
|
||
func dismiss() { | ||
viewController.dismiss(animated: true) | ||
} | ||
|
||
private func shouldShowPrivacyBanner(countryCode: String) -> Bool { | ||
let isCountryInEU = Self.gdprCountryCodes.contains(countryCode) | ||
return isCountryInEU && !defaults.didShowCompliancePopup | ||
} | ||
|
||
private func presentPopover() { | ||
let complianceViewModel = CompliancePopoverViewModel( | ||
defaults: defaults, | ||
contextManager: ContextManager.shared | ||
) | ||
complianceViewModel.coordinator = self | ||
let complianceViewController = CompliancePopoverViewController(viewModel: complianceViewModel) | ||
let bottomSheetViewController = BottomSheetViewController(childViewController: complianceViewController, customHeaderSpacing: 0) | ||
|
||
bottomSheetViewController.show(from: self.viewController) | ||
} | ||
} | ||
|
||
private extension CompliancePopoverCoordinator { | ||
static let gdprCountryCodes: Set<String> = [ | ||
"AT", "AUT", // Austria | ||
"BE", "BEL", // Belgium | ||
"BG", "BGR", // Bulgaria | ||
"HR", "HRV", // Croatia | ||
"CY", "CYP", // Cyprus | ||
"CZ", "CZE", // Czech Republic | ||
"DK", "DNK", // Denmark | ||
"EE", "EST", // Estonia | ||
"FI", "FIN", // Finland | ||
"FR", "FRA", // France | ||
"DE", "DEU", // Germany | ||
"GR", "GRC", // Greece | ||
"HU", "HUN", // Hungary | ||
"IE", "IRL", // Ireland | ||
"IT", "ITA", // Italy | ||
"LV", "LVA", // Latvia | ||
"LT", "LTU", // Lithuania | ||
"LU", "LUX", // Luxembourg | ||
"MT", "MLT", // Malta | ||
"NL", "NLD", // Netherlands | ||
"NO", "NOR", // Norway | ||
"PL", "POL", // Poland | ||
"PT", "PRT", // Portugal | ||
"RO", "ROU", // Romania | ||
"SK", "SVK", // Slovakia | ||
"SI", "SVN", // Slovenia | ||
"ES", "ESP", // Spain | ||
"SE", "SWE", // Sweden | ||
"CH", "CHE", // Switzerland | ||
"IS", | ||
"LI", | ||
"GB", | ||
// *Although the UK has departed from the EU as of January 2021, | ||
// the GDPR was enacted before its withdrawal and is therefore considered a valid UK law.* | ||
] | ||
} | ||
|
||
extension UserDefaults { | ||
static let didShowCompliancePopupKey = "didShowCompliancePopup" | ||
|
||
var didShowCompliancePopup: Bool { | ||
get { | ||
bool(forKey: Self.didShowCompliancePopupKey) | ||
} set { | ||
set(newValue, forKey: Self.didShowCompliancePopupKey) | ||
} | ||
} | ||
} |
Oops, something went wrong.