fix: profile field wrong layout margin issue
This commit is contained in:
parent
db71850fb3
commit
6f55c0288c
|
@ -28,6 +28,10 @@ extension ProfileFieldSection {
|
||||||
case .field(let field, let attribute):
|
case .field(let field, let attribute):
|
||||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: ProfileFieldCollectionViewCell.self), for: indexPath) as! ProfileFieldCollectionViewCell
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: ProfileFieldCollectionViewCell.self), for: indexPath) as! ProfileFieldCollectionViewCell
|
||||||
|
|
||||||
|
let margin = max(0, collectionView.frame.width - collectionView.readableContentGuide.layoutFrame.width)
|
||||||
|
cell.containerStackView.layoutMargins = UIEdgeInsets(top: 0, left: margin, bottom: 0, right: margin)
|
||||||
|
cell.separatorLineToMarginLeadingLayoutConstraint.constant = margin
|
||||||
|
|
||||||
// set key
|
// set key
|
||||||
cell.fieldView.titleTextField.text = field.name.value
|
cell.fieldView.titleTextField.text = field.name.value
|
||||||
field.name
|
field.name
|
||||||
|
@ -38,7 +42,6 @@ extension ProfileFieldSection {
|
||||||
cell.fieldView.titleTextField.text = name
|
cell.fieldView.titleTextField.text = name
|
||||||
}
|
}
|
||||||
.store(in: &cell.disposeBag)
|
.store(in: &cell.disposeBag)
|
||||||
|
|
||||||
|
|
||||||
// set value
|
// set value
|
||||||
cell.fieldView.valueActiveLabel.configure(field: field.value.value, emojiDict: attribute.emojiDict.value)
|
cell.fieldView.valueActiveLabel.configure(field: field.value.value, emojiDict: attribute.emojiDict.value)
|
||||||
|
@ -89,6 +92,10 @@ extension ProfileFieldSection {
|
||||||
case .addEntry(let attribute):
|
case .addEntry(let attribute):
|
||||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: ProfileFieldAddEntryCollectionViewCell.self), for: indexPath) as! ProfileFieldAddEntryCollectionViewCell
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: ProfileFieldAddEntryCollectionViewCell.self), for: indexPath) as! ProfileFieldAddEntryCollectionViewCell
|
||||||
|
|
||||||
|
let margin = max(0, collectionView.frame.width - collectionView.readableContentGuide.layoutFrame.width)
|
||||||
|
cell.containerStackView.layoutMargins = UIEdgeInsets(top: 0, left: margin, bottom: 0, right: margin)
|
||||||
|
cell.separatorLineToMarginLeadingLayoutConstraint.constant = margin
|
||||||
|
|
||||||
cell.bottomSeparatorLine.isHidden = attribute.isLast
|
cell.bottomSeparatorLine.isHidden = attribute.isLast
|
||||||
cell.delegate = profileFieldAddEntryCollectionViewCellDelegate
|
cell.delegate = profileFieldAddEntryCollectionViewCellDelegate
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ final class ProfileFieldAddEntryCollectionViewCell: UICollectionViewCell {
|
||||||
return button
|
return button
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var separatorLineToMarginLeadingLayoutConstraint: NSLayoutConstraint!
|
||||||
var separatorLineToEdgeTrailingLayoutConstraint: NSLayoutConstraint!
|
var separatorLineToEdgeTrailingLayoutConstraint: NSLayoutConstraint!
|
||||||
var separatorLineToMarginTrailingLayoutConstraint: NSLayoutConstraint!
|
var separatorLineToMarginTrailingLayoutConstraint: NSLayoutConstraint!
|
||||||
let bottomSeparatorLine = UIView.separatorLine
|
let bottomSeparatorLine = UIView.separatorLine
|
||||||
|
@ -70,11 +71,12 @@ extension ProfileFieldAddEntryCollectionViewCell {
|
||||||
contentView.addSubview(containerStackView)
|
contentView.addSubview(containerStackView)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
containerStackView.topAnchor.constraint(equalTo: contentView.topAnchor),
|
containerStackView.topAnchor.constraint(equalTo: contentView.topAnchor),
|
||||||
containerStackView.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
|
containerStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||||
containerStackView.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor),
|
containerStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
||||||
containerStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
containerStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
||||||
containerStackView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh),
|
containerStackView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh),
|
||||||
])
|
])
|
||||||
|
containerStackView.isLayoutMarginsRelativeArrangement = true
|
||||||
|
|
||||||
containerStackView.addArrangedSubview(editButton)
|
containerStackView.addArrangedSubview(editButton)
|
||||||
containerStackView.addArrangedSubview(fieldView)
|
containerStackView.addArrangedSubview(fieldView)
|
||||||
|
@ -83,13 +85,14 @@ extension ProfileFieldAddEntryCollectionViewCell {
|
||||||
editButton.setContentHuggingPriority(.required - 1, for: .horizontal)
|
editButton.setContentHuggingPriority(.required - 1, for: .horizontal)
|
||||||
|
|
||||||
bottomSeparatorLine.translatesAutoresizingMaskIntoConstraints = false
|
bottomSeparatorLine.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
separatorLineToMarginLeadingLayoutConstraint = bottomSeparatorLine.leadingAnchor.constraint(equalTo: contentView.leadingAnchor)
|
||||||
separatorLineToEdgeTrailingLayoutConstraint = bottomSeparatorLine.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
separatorLineToEdgeTrailingLayoutConstraint = bottomSeparatorLine.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
||||||
separatorLineToMarginTrailingLayoutConstraint = bottomSeparatorLine.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor)
|
separatorLineToMarginTrailingLayoutConstraint = bottomSeparatorLine.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor)
|
||||||
|
|
||||||
addSubview(bottomSeparatorLine)
|
addSubview(bottomSeparatorLine)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
separatorLineToMarginLeadingLayoutConstraint,
|
||||||
bottomSeparatorLine.bottomAnchor.constraint(equalTo: bottomAnchor),
|
bottomSeparatorLine.bottomAnchor.constraint(equalTo: bottomAnchor),
|
||||||
bottomSeparatorLine.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
|
|
||||||
bottomSeparatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)).priority(.defaultHigh),
|
bottomSeparatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)).priority(.defaultHigh),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ final class ProfileFieldCollectionViewCell: UICollectionViewCell {
|
||||||
return imageView
|
return imageView
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var separatorLineToMarginLeadingLayoutConstraint: NSLayoutConstraint!
|
||||||
var separatorLineToEdgeTrailingLayoutConstraint: NSLayoutConstraint!
|
var separatorLineToEdgeTrailingLayoutConstraint: NSLayoutConstraint!
|
||||||
var separatorLineToMarginTrailingLayoutConstraint: NSLayoutConstraint!
|
var separatorLineToMarginTrailingLayoutConstraint: NSLayoutConstraint!
|
||||||
let bottomSeparatorLine = UIView.separatorLine
|
let bottomSeparatorLine = UIView.separatorLine
|
||||||
|
@ -76,11 +77,12 @@ extension ProfileFieldCollectionViewCell {
|
||||||
contentView.addSubview(containerStackView)
|
contentView.addSubview(containerStackView)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
containerStackView.topAnchor.constraint(equalTo: contentView.topAnchor),
|
containerStackView.topAnchor.constraint(equalTo: contentView.topAnchor),
|
||||||
containerStackView.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
|
containerStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||||
containerStackView.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor),
|
containerStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
||||||
containerStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
containerStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
||||||
containerStackView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh),
|
containerStackView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh),
|
||||||
])
|
])
|
||||||
|
containerStackView.isLayoutMarginsRelativeArrangement = true
|
||||||
|
|
||||||
containerStackView.addArrangedSubview(editButton)
|
containerStackView.addArrangedSubview(editButton)
|
||||||
containerStackView.addArrangedSubview(fieldView)
|
containerStackView.addArrangedSubview(fieldView)
|
||||||
|
@ -92,13 +94,14 @@ extension ProfileFieldCollectionViewCell {
|
||||||
reorderBarImageView.setContentCompressionResistancePriority(.required - 1, for: .horizontal)
|
reorderBarImageView.setContentCompressionResistancePriority(.required - 1, for: .horizontal)
|
||||||
|
|
||||||
bottomSeparatorLine.translatesAutoresizingMaskIntoConstraints = false
|
bottomSeparatorLine.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
separatorLineToMarginLeadingLayoutConstraint = bottomSeparatorLine.leadingAnchor.constraint(equalTo: contentView.leadingAnchor)
|
||||||
separatorLineToEdgeTrailingLayoutConstraint = bottomSeparatorLine.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
separatorLineToEdgeTrailingLayoutConstraint = bottomSeparatorLine.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
||||||
separatorLineToMarginTrailingLayoutConstraint = bottomSeparatorLine.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor)
|
separatorLineToMarginTrailingLayoutConstraint = bottomSeparatorLine.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor)
|
||||||
|
|
||||||
addSubview(bottomSeparatorLine)
|
addSubview(bottomSeparatorLine)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
separatorLineToMarginLeadingLayoutConstraint,
|
||||||
bottomSeparatorLine.bottomAnchor.constraint(equalTo: bottomAnchor),
|
bottomSeparatorLine.bottomAnchor.constraint(equalTo: bottomAnchor),
|
||||||
bottomSeparatorLine.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
|
|
||||||
bottomSeparatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)).priority(.defaultHigh),
|
bottomSeparatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)).priority(.defaultHigh),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,8 @@ final class ProfileHeaderView: UIView {
|
||||||
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(44))
|
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(44))
|
||||||
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
|
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
|
||||||
let section = NSCollectionLayoutSection(group: group)
|
let section = NSCollectionLayoutSection(group: group)
|
||||||
|
// note: manually set layout inset to workaround header footer layout issue
|
||||||
|
// section.contentInsetsReference = .readableContent
|
||||||
|
|
||||||
let headerFooterSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(1))
|
let headerFooterSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(1))
|
||||||
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
|
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
|
||||||
|
|
Loading…
Reference in New Issue