From db5fb858de6e8bff629591370bb4488cab75583b Mon Sep 17 00:00:00 2001 From: Alexandru Farcasanu Date: Fri, 22 Nov 2024 13:05:29 +0200 Subject: [PATCH 1/2] FXIOS-10568 Firefox iOS: Show Onboarding Links in Modal Browser --- .../AccessibilityIdentifiers.swift | 1 + .../Views/TermsOfServiceViewController.swift | 61 ++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/firefox-ios/Client/Application/AccessibilityIdentifiers.swift b/firefox-ios/Client/Application/AccessibilityIdentifiers.swift index 0b457674ea3e..15889651e801 100644 --- a/firefox-ios/Client/Application/AccessibilityIdentifiers.swift +++ b/firefox-ios/Client/Application/AccessibilityIdentifiers.swift @@ -519,6 +519,7 @@ public struct AccessibilityIdentifiers { static let privacyNoticeAgreement = "TermsOfService.PrivacyNoticeAgreement" static let manageDataCollectionAgreement = "TermsOfService.ManageDataCollectionAgreement" static let agreeAndContinueButton = "TermsOfService.AgreeAndContinueButton" + static let doneButton = "TermsOfService.DoneButton" } struct Upgrade { diff --git a/firefox-ios/Client/Frontend/Onboarding/Views/TermsOfServiceViewController.swift b/firefox-ios/Client/Frontend/Onboarding/Views/TermsOfServiceViewController.swift index 4ec84b9a28a0..9062717859b0 100644 --- a/firefox-ios/Client/Frontend/Onboarding/Views/TermsOfServiceViewController.swift +++ b/firefox-ios/Client/Frontend/Onboarding/Views/TermsOfServiceViewController.swift @@ -7,6 +7,12 @@ import Shared import UIKit import ComponentLibrary +enum LinkType: Int { + case termsOfService + case privacyNotice + case manage +} + class TermsOfServiceViewController: UIViewController, Themeable { struct UX { @@ -87,6 +93,7 @@ class TermsOfServiceViewController: UIViewController, let termsOfServiceAgreement = String(format: .Onboarding.TermsOfService.TermsOfServiceAgreement, termsOfServiceLink) setupAgreementTextView(with: termsOfServiceAgreement, linkTitle: termsOfServiceLink, + linkType: .termsOfService, and: AccessibilityIdentifiers.TermsOfService.termsOfServiceAgreement) let privacyNoticeLink = String.Onboarding.TermsOfService.PrivacyNoticeLink @@ -94,6 +101,7 @@ class TermsOfServiceViewController: UIViewController, let privacyAgreement = String(format: privacyNoticeText, AppName.shortName.rawValue, privacyNoticeLink) setupAgreementTextView(with: privacyAgreement, linkTitle: privacyNoticeLink, + linkType: .privacyNotice, and: AccessibilityIdentifiers.TermsOfService.privacyNoticeAgreement) let manageLink = String.Onboarding.TermsOfService.ManageLink @@ -101,6 +109,7 @@ class TermsOfServiceViewController: UIViewController, let manageAgreement = String(format: manageText, AppName.shortName.rawValue, manageLink) setupAgreementTextView(with: manageAgreement, linkTitle: manageLink, + linkType: .manage, and: AccessibilityIdentifiers.TermsOfService.manageDataCollectionAgreement) } @@ -156,10 +165,10 @@ class TermsOfServiceViewController: UIViewController, ]) } - // TODO: FXIOS-10347 Firefox iOS: Manage Privacy Preferences during Onboarding - private func setupAgreementTextView(with title: String, linkTitle: String, and a11yId: String) { + private func setupAgreementTextView(with title: String, linkTitle: String, linkType: LinkType, and a11yId: String) { let agreementLabel: UILabel = .build() agreementLabel.accessibilityIdentifier = a11yId + agreementLabel.tag = linkType.rawValue agreementLabel.numberOfLines = 0 agreementLabel.textAlignment = .center agreementLabel.adjustsFontForContentSizeCategory = true @@ -176,10 +185,58 @@ class TermsOfServiceViewController: UIViewController, value: themeManager.getCurrentTheme(for: windowUUID).colors.textAccent, range: linkedText) + agreementLabel.isUserInteractionEnabled = true + + if linkType != .manage { + let gesture = UITapGestureRecognizer(target: self, action: #selector(presentLink)) + agreementLabel.addGestureRecognizer(gesture) + } else { + let gesture = UITapGestureRecognizer(target: self, action: #selector(presentManagePreferences)) + agreementLabel.addGestureRecognizer(gesture) + } + agreementLabel.attributedText = linkedAgreementDescription agreementContent.addArrangedSubview(agreementLabel) } + // MARK: - Button actions + @objc + private func presentLink(_ gesture: UIGestureRecognizer) { + let url: URL? = { + // TODO: FXIOS-10638 Firefox iOS: Use the correct Terms of Service and Privacy Notice URLs in ToSViewController + switch gesture.view?.tag { + case LinkType.termsOfService.rawValue: + return nil + case LinkType.privacyNotice.rawValue: + return nil + default: return nil + } + }() + + guard let url else { return } + let presentLinkVC = PrivacyPolicyViewController(url: url, windowUUID: windowUUID) + let buttonItem = UIBarButtonItem( + title: .SettingsSearchDoneButton, + style: .plain, + target: self, + action: #selector(dismissPresentedLinkVC)) + buttonItem.accessibilityIdentifier = AccessibilityIdentifiers.TermsOfService.doneButton + + presentLinkVC.navigationItem.rightBarButtonItem = buttonItem + let controller = DismissableNavigationViewController(rootViewController: presentLinkVC) + present(controller, animated: true) + } + + @objc + private func presentManagePreferences(_ gesture: UIGestureRecognizer) { + // TODO: FXIOS-10347 Firefox iOS: Manage Privacy Preferences during Onboarding + } + + @objc + private func dismissPresentedLinkVC() { + dismiss(animated: true, completion: nil) + } + // MARK: - Themable func applyTheme() { let theme = themeManager.getCurrentTheme(for: windowUUID) From b788be1d263927a8d1db0d75ed37eb401b74be5b Mon Sep 17 00:00:00 2001 From: Alexandru Farcasanu Date: Mon, 25 Nov 2024 12:25:00 +0200 Subject: [PATCH 2/2] Refactored some code --- .../Views/TermsOfServiceViewController.swift | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/firefox-ios/Client/Frontend/Onboarding/Views/TermsOfServiceViewController.swift b/firefox-ios/Client/Frontend/Onboarding/Views/TermsOfServiceViewController.swift index 9062717859b0..7cf38088193b 100644 --- a/firefox-ios/Client/Frontend/Onboarding/Views/TermsOfServiceViewController.swift +++ b/firefox-ios/Client/Frontend/Onboarding/Views/TermsOfServiceViewController.swift @@ -168,7 +168,6 @@ class TermsOfServiceViewController: UIViewController, private func setupAgreementTextView(with title: String, linkTitle: String, linkType: LinkType, and a11yId: String) { let agreementLabel: UILabel = .build() agreementLabel.accessibilityIdentifier = a11yId - agreementLabel.tag = linkType.rawValue agreementLabel.numberOfLines = 0 agreementLabel.textAlignment = .center agreementLabel.adjustsFontForContentSizeCategory = true @@ -187,10 +186,14 @@ class TermsOfServiceViewController: UIViewController, agreementLabel.isUserInteractionEnabled = true - if linkType != .manage { - let gesture = UITapGestureRecognizer(target: self, action: #selector(presentLink)) + switch linkType { + case .termsOfService: + let gesture = UITapGestureRecognizer(target: self, action: #selector(presentTermsOfService)) agreementLabel.addGestureRecognizer(gesture) - } else { + case .privacyNotice: + let gesture = UITapGestureRecognizer(target: self, action: #selector(presentPrivacyNotice)) + agreementLabel.addGestureRecognizer(gesture) + case .manage: let gesture = UITapGestureRecognizer(target: self, action: #selector(presentManagePreferences)) agreementLabel.addGestureRecognizer(gesture) } @@ -199,20 +202,7 @@ class TermsOfServiceViewController: UIViewController, agreementContent.addArrangedSubview(agreementLabel) } - // MARK: - Button actions - @objc - private func presentLink(_ gesture: UIGestureRecognizer) { - let url: URL? = { - // TODO: FXIOS-10638 Firefox iOS: Use the correct Terms of Service and Privacy Notice URLs in ToSViewController - switch gesture.view?.tag { - case LinkType.termsOfService.rawValue: - return nil - case LinkType.privacyNotice.rawValue: - return nil - default: return nil - } - }() - + private func presentLink(with url: URL?) { guard let url else { return } let presentLinkVC = PrivacyPolicyViewController(url: url, windowUUID: windowUUID) let buttonItem = UIBarButtonItem( @@ -227,6 +217,19 @@ class TermsOfServiceViewController: UIViewController, present(controller, animated: true) } + // MARK: - Button actions + @objc + private func presentTermsOfService(_ gesture: UIGestureRecognizer) { + // TODO: FXIOS-10638 Firefox iOS: Use the correct Terms of Service and Privacy Notice URLs in ToSViewController + presentLink(with: nil) + } + + @objc + private func presentPrivacyNotice(_ gesture: UIGestureRecognizer) { + // TODO: FXIOS-10638 Firefox iOS: Use the correct Terms of Service and Privacy Notice URLs in ToSViewController + presentLink(with: nil) + } + @objc private func presentManagePreferences(_ gesture: UIGestureRecognizer) { // TODO: FXIOS-10347 Firefox iOS: Manage Privacy Preferences during Onboarding