From deafca218dd58156d729d661fc13dcd271b6f32d Mon Sep 17 00:00:00 2001 From: imsanchit Date: Wed, 25 Oct 2023 18:08:35 +0530 Subject: [PATCH] Bugfix FXIOS-7553 [v120] Fix console warnings for layout constraints in CollapsibleCardView (#16882) * issue-16798 | fixed constraint warning in CollapsibleCardView * issue-16798 | removed extra call of setNeedsLayout * issue-16698 | remove the unused code * issue-16798 | swiftlint warning --- .../CollapsibleCardView.swift | 28 ++++++++----------- .../Views/FakespotReliabilityScoreView.swift | 1 + .../Views/FakespotReviewQualityCardView.swift | 3 -- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/BrowserKit/Sources/ComponentLibrary/CollapsibleCardView.swift b/BrowserKit/Sources/ComponentLibrary/CollapsibleCardView.swift index fac42ef20493..5d11b5d146e1 100644 --- a/BrowserKit/Sources/ComponentLibrary/CollapsibleCardView.swift +++ b/BrowserKit/Sources/ComponentLibrary/CollapsibleCardView.swift @@ -56,6 +56,7 @@ public class CollapsibleCardView: ShadowCardView, UIGestureRecognizerDelegate { static let horizontalPadding: CGFloat = 8 static let titleHorizontalPadding: CGFloat = 8 static let expandButtonSize = CGSize(width: 20, height: 20) + static let margins = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0) } public enum ExpandButtonState { @@ -93,11 +94,16 @@ public class CollapsibleCardView: ShadowCardView, UIGestureRecognizerDelegate { expandState: .collapsed) // UI - private lazy var rootView: UIView = .build { _ in } + private lazy var rootView: UIStackView = .build { stackView in + stackView.axis = .vertical + stackView.spacing = UX.verticalPadding + stackView.alignment = .center + stackView.isLayoutMarginsRelativeArrangement = true + stackView.layoutMargins = UX.margins + } + private lazy var headerView: UIView = .build { _ in } private lazy var containerView: UIView = .build { _ in } - private var containerHeightConstraint: NSLayoutConstraint? - private var containerBottomConstraint: NSLayoutConstraint? private var tapRecognizer: UITapGestureRecognizer! lazy var titleLabel: UILabel = .build { label in @@ -169,24 +175,14 @@ public class CollapsibleCardView: ShadowCardView, UIGestureRecognizerDelegate { headerView.addSubview(titleLabel) headerView.addSubview(expandButton) - rootView.addSubview(headerView) - rootView.addSubview(containerView) - - containerHeightConstraint = containerView.heightAnchor.constraint(equalToConstant: 0) - containerBottomConstraint = containerView.bottomAnchor.constraint(equalTo: rootView.bottomAnchor, - constant: -UX.verticalPadding) - containerBottomConstraint?.isActive = true + rootView.addArrangedSubview(headerView) + rootView.addArrangedSubview(containerView) NSLayoutConstraint.activate([ headerView.leadingAnchor.constraint(equalTo: rootView.leadingAnchor, constant: UX.titleHorizontalPadding), - headerView.topAnchor.constraint(equalTo: rootView.topAnchor, - constant: UX.verticalPadding), headerView.trailingAnchor.constraint(equalTo: rootView.trailingAnchor, constant: -UX.titleHorizontalPadding), - headerView.bottomAnchor.constraint(equalTo: containerView.topAnchor, - constant: -UX.verticalPadding), - titleLabel.leadingAnchor.constraint(equalTo: headerView.leadingAnchor), titleLabel.topAnchor.constraint(equalTo: headerView.topAnchor), titleLabel.trailingAnchor.constraint(equalTo: expandButton.leadingAnchor, @@ -213,9 +209,7 @@ public class CollapsibleCardView: ShadowCardView, UIGestureRecognizerDelegate { viewModel.expandState = expandState expandButton.setImage(viewModel.expandState.image, for: .normal) expandButton.accessibilityLabel = viewModel.expandButtonA11yLabel - containerHeightConstraint?.isActive = isCollapsed containerView.isHidden = isCollapsed - containerBottomConstraint?.constant = isCollapsed ? 0 : -UX.verticalPadding UIAccessibility.post(notification: .layoutChanged, argument: nil) } diff --git a/Client/Frontend/Fakespot/Views/FakespotReliabilityScoreView.swift b/Client/Frontend/Fakespot/Views/FakespotReliabilityScoreView.swift index 8cdf748e402c..18d871057b3b 100644 --- a/Client/Frontend/Fakespot/Views/FakespotReliabilityScoreView.swift +++ b/Client/Frontend/Fakespot/Views/FakespotReliabilityScoreView.swift @@ -34,6 +34,7 @@ final class FakespotReliabilityScoreView: UIView, Notifiable, ThemeApplicable { init(grade: ReliabilityGrade) { self.grade = grade super.init(frame: .zero) + self.translatesAutoresizingMaskIntoConstraints = false setupNotifications(forObserver: self, observing: [.DynamicFontChanged]) setupLayout() diff --git a/Client/Frontend/Fakespot/Views/FakespotReviewQualityCardView.swift b/Client/Frontend/Fakespot/Views/FakespotReviewQualityCardView.swift index 23a6badb9807..0b3314c2f22d 100644 --- a/Client/Frontend/Fakespot/Views/FakespotReviewQualityCardView.swift +++ b/Client/Frontend/Fakespot/Views/FakespotReviewQualityCardView.swift @@ -259,9 +259,6 @@ final class FakespotReviewQualityCardView: UIView, Notifiable, ThemeApplicable { abRatingsReliableLabelStackView.spacing = UX.abdfRatingsStackViewSpacing dfRatingsReliableLabelStackView.spacing = UX.abdfRatingsStackViewSpacing } - - setNeedsLayout() - layoutIfNeeded() } private func updateA11yElementOrder() {