Skip to content

Commit 8611895

Browse files
rilurylmarceau
andauthored
Refactor FXIOS-15063 [Terms of use] Refactor navigation bar from Terms of Use links VC (#32443)
* Refactor FXIOS-15063 Refactor navigation bar from Terms of Use links VC * Fixed warning * Refactor FXIOS-15063 Refactor navigation bar from Terms of Use links VC * Refactor FXIOS-15063 Refactor navigation bar from Terms of Use links VC * Update firefox-ios/Shared/Strings.swift Co-authored-by: lmarceau <lmarceau@mozilla.com> * Apply suggestions from code review Co-authored-by: lmarceau <lmarceau@mozilla.com> --------- Co-authored-by: lmarceau <lmarceau@mozilla.com>
1 parent 8e8956b commit 8611895

4 files changed

Lines changed: 26 additions & 42 deletions

File tree

firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,9 @@ final class BrowserCoordinator: BaseCoordinator,
10811081
windowUUID: windowUUID,
10821082
themeManager: themeManager
10831083
)
1084-
linkVC.modalPresentationStyle = .pageSheet
1085-
router.present(linkVC, animated: true)
1084+
let navController = UINavigationController(rootViewController: linkVC)
1085+
navController.modalPresentationStyle = .pageSheet
1086+
router.present(navController, animated: true)
10861087
}
10871088

10881089
func showCertificatesFromErrorPage(errorPageURL: URL, originalURL: URL, title: String) {

firefox-ios/Client/Frontend/Browser/TermsOfUse/TermsOfUseCoordinator.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ final class TermsOfUseCoordinator: BaseCoordinator, TermsOfUseCoordinatorDelegat
102102
themeManager: themeManager,
103103
notificationCenter: notificationCenter
104104
)
105-
linkVC.modalPresentationStyle = .pageSheet
106-
linkVC.modalTransitionStyle = .coverVertical
107-
presentedVC?.present(linkVC, animated: true)
105+
let navController = UINavigationController(rootViewController: linkVC)
106+
navController.modalPresentationStyle = .pageSheet
107+
navController.modalTransitionStyle = .coverVertical
108+
presentedVC?.present(navController, animated: true)
108109
}
109110

110111
func shouldShowTermsOfUse(context: TriggerContext = .appLaunch) -> Bool {

firefox-ios/Client/Frontend/Browser/TermsOfUse/View/TermsOfUseLinkViewController.swift

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ final class TermsOfUseLinkViewController: UIViewController,
1414
weak var coordinator: TermsOfUseCoordinatorDelegate?
1515

1616
private struct UX {
17-
static let headerHeight: CGFloat = 44
18-
static let backButtonLeading: CGFloat = 8
1917
static let progressBarHeight: CGFloat = 2
20-
static let backArrowImage = UIImage(imageLiteralResourceName: StandardImageIdentifiers.Large.chevronLeft)
2118
}
2219

2320
private let url: URL
@@ -35,22 +32,6 @@ final class TermsOfUseLinkViewController: UIViewController,
3532
bar.isHidden = true
3633
}
3734

38-
private lazy var header: UIView = .build { view in
39-
view.backgroundColor = self.currentTheme().colors.layer1
40-
}
41-
42-
private lazy var backButton: UIButton = .build { button in
43-
button.setImage(UX.backArrowImage.withRenderingMode(.alwaysTemplate), for: .normal)
44-
button.titleLabel?.adjustsFontForContentSizeCategory = true
45-
button.adjustsImageSizeForAccessibilityContentSizeCategory = true
46-
button.imageView?.contentMode = .scaleAspectFit
47-
button.titleLabel?.adjustsFontSizeToFitWidth = true
48-
button.setTitle(TermsOfUse.BackButton, for: .normal)
49-
button.setTitleColor(self.currentTheme().colors.actionPrimary, for: .normal)
50-
button.tintColor = self.currentTheme().colors.actionPrimary
51-
button.addTarget(self, action: #selector(self.closeTapped), for: .touchUpInside)
52-
}
53-
5435
private lazy var webView: WKWebView = {
5536
let config = WKWebViewConfiguration()
5637
config.setURLSchemeHandler(InternalSchemeHandler(shouldUseOldErrorPage: true), forURLScheme: InternalURL.scheme)
@@ -89,35 +70,33 @@ final class TermsOfUseLinkViewController: UIViewController,
8970
}
9071

9172
private func setupViews() {
92-
view.addSubview(header)
93-
header.addSubview(backButton)
73+
navigationItem.rightBarButtonItem = UIBarButtonItem(
74+
title: TermsOfUse.CloseButton,
75+
style: .plain,
76+
target: self,
77+
action: #selector(closeTapped)
78+
)
79+
80+
view.addSubview(progressBar)
9481
view.addSubview(webView)
95-
header.addSubview(progressBar)
9682

9783
NSLayoutConstraint.activate([
98-
header.topAnchor.constraint(equalTo: view.topAnchor),
99-
header.leadingAnchor.constraint(equalTo: view.leadingAnchor),
100-
header.trailingAnchor.constraint(equalTo: view.trailingAnchor),
101-
header.heightAnchor.constraint(equalToConstant: UX.headerHeight),
102-
103-
backButton.leadingAnchor.constraint(equalTo: header.leadingAnchor, constant: UX.backButtonLeading),
104-
backButton.centerYAnchor.constraint(equalTo: header.centerYAnchor),
105-
106-
progressBar.leadingAnchor.constraint(equalTo: header.leadingAnchor),
107-
progressBar.trailingAnchor.constraint(equalTo: header.trailingAnchor),
108-
progressBar.bottomAnchor.constraint(equalTo: header.bottomAnchor),
84+
progressBar.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
85+
progressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
86+
progressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
10987
progressBar.heightAnchor.constraint(equalToConstant: UX.progressBarHeight),
11088

111-
webView.topAnchor.constraint(equalTo: header.bottomAnchor),
89+
webView.topAnchor.constraint(equalTo: progressBar.bottomAnchor),
11290
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
11391
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
11492
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
11593
])
11694
}
11795

11896
func applyTheme() {
119-
view.backgroundColor = currentTheme().colors.layer1
120-
applyProgressBarTheme(theme: currentTheme())
97+
let theme = currentTheme()
98+
view.backgroundColor = theme.colors.layer1
99+
applyProgressBarTheme(theme: theme)
121100
}
122101

123102
@objc private func closeTapped() {

firefox-ios/firefox-ios-tests/Tests/ClientTests/Coordinators/BrowserCoordinatorTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,10 @@ final class BrowserCoordinatorTests: XCTestCase, FeatureFlaggable, StoreTestUtil
618618

619619
subject.showPrivacyNoticeLink(url: url)
620620

621-
XCTAssertNotNil(mockRouter.presentedViewController as? TermsOfUseLinkViewController)
621+
let navController = mockRouter.presentedViewController as? UINavigationController
622+
let termsOfUseLinkVC = navController?.viewControllers.first as? TermsOfUseLinkViewController
623+
624+
XCTAssertNotNil(termsOfUseLinkVC)
622625
XCTAssertEqual(mockRouter.presentCalled, 1)
623626
}
624627

0 commit comments

Comments
 (0)