fix: remove section inset hacking and set header footer with overflow layout constraint

This commit is contained in:
CMK 2021-05-27 17:32:42 +08:00
parent 629309904a
commit 252c58ad2c
4 changed files with 6 additions and 20 deletions

View File

@ -28,10 +28,6 @@ extension ProfileFieldSection {
case .field(let field, let attribute):
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
cell.fieldView.titleActiveLabel.configure(field: field.name.value, emojiDict: attribute.emojiDict.value)
cell.fieldView.titleTextField.text = field.name.value
@ -99,10 +95,6 @@ extension ProfileFieldSection {
case .addEntry(let attribute):
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.delegate = profileFieldAddEntryCollectionViewCellDelegate

View File

@ -228,14 +228,6 @@ extension ProfileHeaderViewController {
super.viewDidAppear(animated)
viewModel.viewDidAppear.value = true
// Deprecated:
// not needs this tweak due to force layout update in the parent
// if !isAdjustBannerImageViewForSafeAreaInset {
// isAdjustBannerImageViewForSafeAreaInset = true
// profileHeaderView.bannerImageView.frame.origin.y = -containerSafeAreaInset.top
// profileHeaderView.bannerImageView.frame.size.height += containerSafeAreaInset.top
// }
}
override func viewDidLayoutSubviews() {

View File

@ -32,8 +32,9 @@ extension ProfileFieldCollectionViewHeaderFooterView {
addSubview(separatorLine)
NSLayoutConstraint.activate([
separatorLine.topAnchor.constraint(equalTo: topAnchor),
separatorLine.leadingAnchor.constraint(equalTo: leadingAnchor),
separatorLine.trailingAnchor.constraint(equalTo: trailingAnchor),
// workaround SDK supplementariesFollowContentInsets not works issue
separatorLine.leadingAnchor.constraint(equalTo: leadingAnchor, constant: -9999),
separatorLine.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 9999),
separatorLine.bottomAnchor.constraint(equalTo: bottomAnchor),
separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)).priority(.defaultHigh),
])

View File

@ -159,13 +159,14 @@ final class ProfileHeaderView: UIView {
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(44))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
// note: manually set layout inset to workaround header footer layout issue
// section.contentInsetsReference = .readableContent
section.contentInsetsReference = .readableContent
let headerFooterSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(1))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
let footer = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize, elementKind: UICollectionView.elementKindSectionFooter, alignment: .bottom)
section.boundarySupplementaryItems = [header, footer]
// note: toggle this not take effect
// section.supplementariesFollowContentInsets = false
return UICollectionViewCompositionalLayout(section: section)
}