Skip to content

Commit

Permalink
Bugfix FXIOS-7553 [v120] Fix console warnings for layout constraints …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
imsanchit authored Oct 25, 2023
1 parent 72fee82 commit deafca2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
28 changes: 11 additions & 17 deletions BrowserKit/Sources/ComponentLibrary/CollapsibleCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,6 @@ final class FakespotReviewQualityCardView: UIView, Notifiable, ThemeApplicable {
abRatingsReliableLabelStackView.spacing = UX.abdfRatingsStackViewSpacing
dfRatingsReliableLabelStackView.spacing = UX.abdfRatingsStackViewSpacing
}

setNeedsLayout()
layoutIfNeeded()
}

private func updateA11yElementOrder() {
Expand Down

0 comments on commit deafca2

Please sign in to comment.