From ec6f4c870d4d549586dedb6171ac687b68210f56 Mon Sep 17 00:00:00 2001 From: Marceau TONELLI Date: Thu, 19 Dec 2024 16:26:22 +0100 Subject: [PATCH] Refactor FXIOS-10205 [Swiftlint] Resolve 3 implicitly_unwrapped_optional violations in Client/Extensions (#23893) * Resolve implicitly_unwrapped_optional violations in ShareViewController * Resolve implicitly_unwrapped_optional violations in EmbeddedNavController --- .../ShareTo/EmbeddedNavController.swift | 2 +- .../ShareTo/ShareViewController.swift | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/firefox-ios/Extensions/ShareTo/EmbeddedNavController.swift b/firefox-ios/Extensions/ShareTo/EmbeddedNavController.swift index 388b6544ae88..832d0160736d 100644 --- a/firefox-ios/Extensions/ShareTo/EmbeddedNavController.swift +++ b/firefox-ios/Extensions/ShareTo/EmbeddedNavController.swift @@ -11,7 +11,7 @@ class EmbeddedNavController { weak var parent: UIViewController? var controllers = [UIViewController]() var navigationController: UINavigationController - var heightConstraint: NSLayoutConstraint! + var heightConstraint: NSLayoutConstraint let isSearchMode: Bool init(isSearchMode: Bool, parent: UIViewController, rootViewController: UIViewController) { diff --git a/firefox-ios/Extensions/ShareTo/ShareViewController.swift b/firefox-ios/Extensions/ShareTo/ShareViewController.swift index a2040324465e..9af22b74ce17 100644 --- a/firefox-ios/Extensions/ShareTo/ShareViewController.swift +++ b/firefox-ios/Extensions/ShareTo/ShareViewController.swift @@ -70,9 +70,9 @@ func addAppExtensionTelemetryEvent(forMethod method: String) { class ShareViewController: UIViewController { var shareItem: ExtensionUtils.ExtractedShareItem? private var viewsShownDuringDoneAnimation = [UIView]() - private var stackView: UIStackView! + private var stackView: UIStackView? private var spinner: UIActivityIndicatorView? - private var actionDoneRow: (row: UIStackView, label: UILabel)! + private var actionDoneRow: (row: UIStackView, label: UILabel)? private var sendToDevice: SendToDevice? private var pageInfoHeight: NSLayoutConstraint? private var actionRowHeights = [NSLayoutConstraint]() @@ -135,6 +135,8 @@ class ShareViewController: UIViewController { } private func setupRows() { + guard let stackView else { return } + let theme = currentTheme() let pageInfoRow = makePageInfoRow(addTo: stackView) pageInfoRowTitleLabel = pageInfoRow.titleLabel @@ -199,11 +201,12 @@ class ShareViewController: UIViewController { // done state, without this space, the page info label moves down slightly. footerSpaceRow.heightAnchor.constraint(greaterThanOrEqualToConstant: 0).isActive = true - actionDoneRow = makeActionDoneRow(addTo: stackView) + let actionDoneRow = makeActionDoneRow(addTo: stackView) // Fully constructing and pre-adding as a subview ensures that only the show operation will animate // during the UIView.animate(), and other animatable properties will not unexpectedly animate because // they are modified in the same event loop as the animation. actionDoneRow.row.isHidden = true + self.actionDoneRow = actionDoneRow // All other views are hidden for the done animation. viewsShownDuringDoneAnimation += [pageInfoRow.row, footerSpaceRow, actionDoneRow.row] @@ -338,11 +341,11 @@ class ShareViewController: UIViewController { equalToConstant: CGFloat(UX.viewHeightForDoneState) ).isActive = true - actionDoneRow.label.text = title + actionDoneRow?.label.text = title UIView.animate(withDuration: UX.doneDialogAnimationDuration) { - self.actionDoneRow.row.isHidden = false - self.stackView.arrangedSubviews + self.actionDoneRow?.row.isHidden = false + self.stackView?.arrangedSubviews .filter { !self.viewsShownDuringDoneAnimation.contains($0) } .forEach { $0.removeFromSuperview() } @@ -406,7 +409,7 @@ class ShareViewController: UIViewController { } private func setupStackView() { - stackView = UIStackView() + let stackView = UIStackView() stackView.axis = .vertical stackView.spacing = 4 stackView.translatesAutoresizingMaskIntoConstraints = false @@ -416,7 +419,8 @@ class ShareViewController: UIViewController { stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor), stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor), stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor) - ]) + ]) + self.stackView = stackView } private func showProgressIndicator() {