Skip to content

Commit

Permalink
Merge pull request #1630 from MixinNetwork/bugfix/transfer
Browse files Browse the repository at this point in the history
Fix wrong cell height on iOS 14
  • Loading branch information
over140 authored Oct 13, 2024
2 parents 85e1706 + 93119ec commit 05fa17d
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 158 deletions.
16 changes: 8 additions & 8 deletions Mixin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@
944C610F2B6AB7F600C7DF06 /* TokenAmountCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 944C610D2B6AB7F600C7DF06 /* TokenAmountCell.xib */; };
944C61F32B6BF97B00C7DF06 /* PaymentUserGroupCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944C61F12B6BF97B00C7DF06 /* PaymentUserGroupCell.swift */; };
944C61F42B6BF97B00C7DF06 /* PaymentUserGroupCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 944C61F22B6BF97B00C7DF06 /* PaymentUserGroupCell.xib */; };
944C61F72B6BFAA100C7DF06 /* PaymentUserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944C61F52B6BFAA100C7DF06 /* PaymentUserCell.swift */; };
944C61F82B6BFAA100C7DF06 /* PaymentUserCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 944C61F62B6BFAA100C7DF06 /* PaymentUserCell.xib */; };
944C61F72B6BFAA100C7DF06 /* PaymentUserItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944C61F52B6BFAA100C7DF06 /* PaymentUserItemView.swift */; };
944C61F82B6BFAA100C7DF06 /* PaymentUserItemView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 944C61F62B6BFAA100C7DF06 /* PaymentUserItemView.xib */; };
944C61FA2B6BFD6F00C7DF06 /* AuthenticationPreviewDoubleButtonTrayView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 944C61F92B6BFD6F00C7DF06 /* AuthenticationPreviewDoubleButtonTrayView.xib */; };
944C61FF2B6C033500C7DF06 /* EditAddressPreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944C61FE2B6C033500C7DF06 /* EditAddressPreviewViewController.swift */; };
944C62042B6C185300C7DF06 /* AuthenticationPreviewDoubleButtonTrayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944C62032B6C185300C7DF06 /* AuthenticationPreviewDoubleButtonTrayView.swift */; };
Expand Down Expand Up @@ -2246,8 +2246,8 @@
944C610D2B6AB7F600C7DF06 /* TokenAmountCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TokenAmountCell.xib; sourceTree = "<group>"; };
944C61F12B6BF97B00C7DF06 /* PaymentUserGroupCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentUserGroupCell.swift; sourceTree = "<group>"; };
944C61F22B6BF97B00C7DF06 /* PaymentUserGroupCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PaymentUserGroupCell.xib; sourceTree = "<group>"; };
944C61F52B6BFAA100C7DF06 /* PaymentUserCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentUserCell.swift; sourceTree = "<group>"; };
944C61F62B6BFAA100C7DF06 /* PaymentUserCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PaymentUserCell.xib; sourceTree = "<group>"; };
944C61F52B6BFAA100C7DF06 /* PaymentUserItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentUserItemView.swift; sourceTree = "<group>"; };
944C61F62B6BFAA100C7DF06 /* PaymentUserItemView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PaymentUserItemView.xib; sourceTree = "<group>"; };
944C61F92B6BFD6F00C7DF06 /* AuthenticationPreviewDoubleButtonTrayView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AuthenticationPreviewDoubleButtonTrayView.xib; sourceTree = "<group>"; };
944C61FE2B6C033500C7DF06 /* EditAddressPreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAddressPreviewViewController.swift; sourceTree = "<group>"; };
944C62032B6C185300C7DF06 /* AuthenticationPreviewDoubleButtonTrayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationPreviewDoubleButtonTrayView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3833,8 +3833,8 @@
944C61052B6AB6B400C7DF06 /* AuthenticationPreviewCompactInfoCell.swift */,
944C610D2B6AB7F600C7DF06 /* TokenAmountCell.xib */,
944C610C2B6AB7F600C7DF06 /* TokenAmountCell.swift */,
944C61F62B6BFAA100C7DF06 /* PaymentUserCell.xib */,
944C61F52B6BFAA100C7DF06 /* PaymentUserCell.swift */,
944C61F62B6BFAA100C7DF06 /* PaymentUserItemView.xib */,
944C61F52B6BFAA100C7DF06 /* PaymentUserItemView.swift */,
944C61F22B6BF97B00C7DF06 /* PaymentUserGroupCell.xib */,
944C61F12B6BF97B00C7DF06 /* PaymentUserGroupCell.swift */,
941979542BA47782002BA19F /* Web3MessageCell.xib */,
Expand Down Expand Up @@ -5490,7 +5490,7 @@
7BB788B4216C5AA900EDE7B4 /* NoResultFooterView.xib in Resources */,
94463C51298D627800E63547 /* AuthenticationFailureView.xib in Resources */,
94062C5D2AE8CA7600ADAE87 /* SnapshotColumnCell.xib in Resources */,
944C61F82B6BFAA100C7DF06 /* PaymentUserCell.xib in Resources */,
944C61F82B6BFAA100C7DF06 /* PaymentUserItemView.xib in Resources */,
7BB06F45228EA7720048C2D6 /* NotificationView.xib in Resources */,
94D9DF5C25F889C600FC2F28 /* BulletinContentView.xib in Resources */,
7BE73BFC230A8D0300B97FC6 /* group_separator_3.png in Resources */,
Expand Down Expand Up @@ -6179,7 +6179,7 @@
7B894CD620D24BE2004FA5A8 /* RecorderLockView.swift in Sources */,
DFB9B39A1FAB01E6009503CE /* HomeNavigationController.swift in Sources */,
94911DC42AF00B2C00A33B2A /* TokenItem+Description.swift in Sources */,
944C61F72B6BFAA100C7DF06 /* PaymentUserCell.swift in Sources */,
944C61F72B6BFAA100C7DF06 /* PaymentUserItemView.swift in Sources */,
7B7FBF8D2282D51100644693 /* IconPrefixedTextMessageViewModel.swift in Sources */,
7C0E15DF27005376002FC718 /* UnknownURLWindow.swift in Sources */,
7BAECA3A20401DE500AEA42F /* AttachmentLoadingViewModel.swift in Sources */,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,82 +18,49 @@ final class PaymentUserGroupCell: UITableViewCell {
weak var delegate: PaymentUserGroupCellDelegate?

private var users: [UserItem] = []
private var checkmarkCondition: CheckmarkCondition = .never

private weak var collectionView: UICollectionView!
private weak var collectionViewHeightConstraint: NSLayoutConstraint!

private var collectionViewContentSizeObserver: NSKeyValueObservation?
private var itemViews: [PaymentUserItemView] = []

override func awakeFromNib() {
super.awakeFromNib()
var configuration = UICollectionLayoutListConfiguration(appearance: .plain)
configuration.backgroundColor = R.color.background()
configuration.showsSeparators = false
let layout: UICollectionViewCompositionalLayout = .list(using: configuration)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = .clear
collectionView.isScrollEnabled = false
contentStackView.addArrangedSubview(collectionView)
let collectionViewHeightConstraint = collectionView.heightAnchor.constraint(equalToConstant: 32)
collectionViewHeightConstraint.isActive = true
collectionView.register(R.nib.paymentUserCell)
collectionView.dataSource = self
collectionView.delegate = self
collectionViewContentSizeObserver = collectionView.observe(\.contentSize, options: [.new]) { [weak self] (_, change) in
guard let newValue = change.newValue, let self else {
return
}
// Dispatch to break an infinite loop on iOS 14
DispatchQueue.main.async {
UIView.performWithoutAnimation {
self.collectionViewHeightConstraint.constant = newValue.height
self.invalidateIntrinsicContentSize()
}
}
}
self.collectionView = collectionView
self.collectionViewHeightConstraint = collectionViewHeightConstraint
contentStackView.setCustomSpacing(7, after: captionLabel)
}

func reloadUsers(with users: [UserItem], checkmarkCondition: CheckmarkCondition) {
self.users = users
self.checkmarkCondition = checkmarkCondition
collectionView.reloadData()
}

}

extension PaymentUserGroupCell: UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
users.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: R.reuseIdentifier.payment_user, for: indexPath)!
let user = users[indexPath.item]
let badgeImage = user.badgeImage
cell.avatarImageView.setImage(with: user)
cell.usernameLabel.text = user.fullName
cell.identityNumberLabel.text = "(\(user.identityNumber))"
cell.badgeImageView.image = badgeImage
cell.badgeImageView.isHidden = badgeImage == nil
switch checkmarkCondition {
case .never:
cell.checkmark = nil
case .byUserID(let ids):
cell.checkmark = ids.contains(user.userId) ? .yes : .no
let numberOfItemViewsToBeAdded = users.count - itemViews.count
if numberOfItemViewsToBeAdded > 0 {
for _ in 0..<numberOfItemViewsToBeAdded {
let view = R.nib.paymentUserItemView(withOwner: nil)!
view.button.addTarget(self, action: #selector(reportSelection(_:)), for: .touchUpInside)
contentStackView.addArrangedSubview(view)
itemViews.append(view)
}
} else if numberOfItemViewsToBeAdded < 0 {
for itemView in contentStackView.arrangedSubviews.suffix(-numberOfItemViewsToBeAdded) {
itemView.removeFromSuperview()
}
itemViews.removeLast(-numberOfItemViewsToBeAdded)
}
for (i, user) in users.enumerated() {
let itemView = itemViews[i]
let badgeImage = user.badgeImage
itemView.avatarImageView.setImage(with: user)
itemView.usernameLabel.text = user.fullName
itemView.identityNumberLabel.text = "(\(user.identityNumber))"
itemView.badgeImageView.image = badgeImage
itemView.badgeImageView.isHidden = badgeImage == nil
switch checkmarkCondition {
case .never:
itemView.checkmark = nil
case .byUserID(let ids):
itemView.checkmark = ids.contains(user.userId) ? .yes : .no
}
itemView.button.tag = i
}
return cell
}

}

extension PaymentUserGroupCell: UICollectionViewDelegate {

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let user = users[indexPath.item]
@objc private func reportSelection(_ sender: UIButton) {
let user = users[sender.tag]
if user.isCreatedByMessenger {
delegate?.paymentUserGroupCell(self, didSelectMessengerUser: user)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="75"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="7" translatesAutoresizingMaskIntoConstraints="NO" id="ItJ-CF-Vhg">
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="ItJ-CF-Vhg">
<rect key="frame" x="28" y="10" width="264" height="55"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="500" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3i8-Ze-McM">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import SDWebImage

final class PaymentUserCell: UICollectionViewCell {
final class PaymentUserItemView: UIView {

enum Checkmark {
case yes
Expand All @@ -13,6 +13,7 @@ final class PaymentUserCell: UICollectionViewCell {
@IBOutlet weak var usernameLabel: UILabel!
@IBOutlet weak var identityNumberLabel: UILabel!
@IBOutlet weak var badgeImageView: SDAnimatedImageView!
@IBOutlet weak var button: UIButton!

var checkmark: Checkmark? {
didSet {
Expand Down
Loading

0 comments on commit 05fa17d

Please sign in to comment.