Skip to content

Commit

Permalink
fix(Header): Header does not display correctly in iOS 14
Browse files Browse the repository at this point in the history
* IOS-10266 Change in Header component from layoutMargins to constraint
  • Loading branch information
DavidMarinCalleja authored Jun 6, 2024
1 parent dc993ad commit c0edf11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ extension UICatalogHeaderViewController: UITableViewDataSource, UITableViewDeleg
vc.headerView.title = titleText
vc.headerView.descriptionValue = descriptionText

show(vc, sender: self)
present(vc, animated: true)
}
}

Expand Down
53 changes: 12 additions & 41 deletions Sources/Mistica/Components/Header/HeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@ public class HeaderView: UIView {
private lazy var stackView: UIStackView = {
let stackView = UIStackView()

stackView.axis = .vertical
stackView.distribution = .fillProportionally
stackView.spacing = Constants.noSpacing
stackView.isLayoutMarginsRelativeArrangement = true
stackView.layoutMargins = UIEdgeInsets(
top: Constants.marginTop,
left: Constants.marginLeft,
bottom: Constants.marginBottom,
right: Constants.marginRight
)

return stackView
}()

private lazy var topStackView: UIStackView = {
let stackView = UIStackView()

stackView.axis = .vertical
stackView.spacing = Constants.spacing

Expand Down Expand Up @@ -225,42 +208,40 @@ private extension HeaderView {
setContentHuggingPriority(.required, for: .vertical)
setContentCompressionResistancePriority(.required, for: .vertical)

updateLayoutMarginsGuide()
updateColors()

addSubview(stackView, constraints: [
stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
stackView.topAnchor.constraint(equalTo: topAnchor),
stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
bottomAnchor.constraint(equalTo: stackView.bottomAnchor)
stackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: Constants.marginLeft),
stackView.topAnchor.constraint(equalTo: topAnchor, constant: Constants.marginTop),
trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: Constants.marginRight),
bottomAnchor.constraint(equalTo: stackView.bottomAnchor, constant: Constants.marginBottom)
])

stackView.addArrangedSubview(topStackView)
}

func updateTopStackView() {
bringSubviewToFront(stackView)
topStackView.removeArrangedSubviews()
stackView.removeArrangedSubviews()

if let pretitle = pretitle {
stylePretitleLabel(pretitle)
topStackView.addArrangedSubview(pretitleLabel)
stackView.addArrangedSubview(pretitleLabel)

let heightLayoutConstraint = pretitleLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.heightLabel)
topStackView.addConstraint(heightLayoutConstraint)
stackView.addConstraint(heightLayoutConstraint)
}
if let title = title {
styleTitleLabel(title)
topStackView.addArrangedSubview(titleLabel)
stackView.addArrangedSubview(titleLabel)

let heightLayoutConstraint = titleLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.heightLabel)
topStackView.addConstraint(heightLayoutConstraint)
stackView.addConstraint(heightLayoutConstraint)
}
if let descriptionValue = descriptionValue {
styleDescriptionLabel(descriptionValue)
topStackView.addArrangedSubview(descriptionLabel)
stackView.addArrangedSubview(descriptionLabel)

let heightLayoutConstraint = descriptionLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.heightLabel)
topStackView.addConstraint(heightLayoutConstraint)
stackView.addConstraint(heightLayoutConstraint)
}
}

Expand Down Expand Up @@ -306,16 +287,6 @@ private extension HeaderView {
}
}

func updateLayoutMarginsGuide() {
updateColors()
directionalLayoutMargins = NSDirectionalEdgeInsets(
top: Constants.marginTop,
leading: Constants.marginLeft,
bottom: Constants.marginBottom,
trailing: Constants.marginRight
)
}

func updatePretitleLabelVisibilityState() {
pretitleLabel.isHidden = pretitleLabel.text == nil && pretitleLabel.attributedText == nil
}
Expand Down

0 comments on commit c0edf11

Please sign in to comment.