mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
fix all editing related issues with emojicollectionview
not the remove item race thing yet
This commit is contained in:
4 files changed
+20
-22
No files matched your search
@@ -174,16 +174,12 @@ final class EmojiCollectionView: UICollectionViewController, UICollectionViewDel
|
||||
}
|
||||
}
|
||||
|
||||
override func setEditing(_ editing: Bool, animated: Bool) {
|
||||
super.setEditing(editing, animated: animated)
|
||||
|
||||
let offset = collectionView.contentOffset
|
||||
|
||||
func edit(_ editing: Bool, animated: Bool) {
|
||||
onEditChange?()
|
||||
|
||||
for cell in collectionView.visibleCells {
|
||||
if let cell = cell as? EmojiCollectionViewCell {
|
||||
cell.setEdit(to: isEditing)
|
||||
cell.setEdit(to: editing)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,9 +188,6 @@ final class EmojiCollectionView: UICollectionViewController, UICollectionViewDel
|
||||
} else {
|
||||
self.stopAnimating()
|
||||
}
|
||||
|
||||
collectionView.layoutIfNeeded()
|
||||
collectionView.contentOffset = offset
|
||||
}
|
||||
|
||||
override func collectionView(
|
||||
|
||||
@@ -37,6 +37,7 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
||||
contentView.addSubview(button)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
label.topAnchor.constraint(equalTo: self.view.bottomAnchor),
|
||||
label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
||||
label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||
label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
||||
@@ -99,15 +100,10 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
|
||||
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
|
||||
let layoutAttributes = super.preferredLayoutAttributesFitting(layoutAttributes)
|
||||
guard label.text != nil else { return layoutAttributes }
|
||||
let labelHeight = label.sizeThatFits(CGSize(width: layoutAttributes.size.width, height: .infinity)).height
|
||||
layoutAttributes.size = CGSize(
|
||||
width: layoutAttributes.size.width,
|
||||
height: labelHeight + 4 + layoutAttributes.size.height
|
||||
)
|
||||
return layoutAttributes
|
||||
override func preferredItemSize(for width: CGFloat) -> CGSize {
|
||||
guard label.text != nil else { return super.preferredItemSize(for: width) }
|
||||
let labelHeight = label.sizeThatFits(CGSize(width: width, height: .infinity)).height
|
||||
return CGSize(width: width, height: width + 4 + labelHeight)
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
|
||||
@@ -66,6 +66,10 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
||||
print("tap")
|
||||
}
|
||||
|
||||
func preferredItemSize(for width: CGFloat) -> CGSize {
|
||||
CGSize(width: width, height: width)
|
||||
}
|
||||
|
||||
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
|
||||
super.preferredLayoutAttributesFitting(layoutAttributes)
|
||||
guard let superview,
|
||||
@@ -82,7 +86,7 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
||||
if cols == 0 || cols == .infinity { cols = 4 }
|
||||
let totalSpacing = ((collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumInteritemSpacing ?? 0) * (cols-1)
|
||||
let itemWidth = ((availWidth-totalSpacing)/cols).rounded(.down)
|
||||
layoutAttributes.size = CGSize(width: itemWidth, height: itemWidth)
|
||||
layoutAttributes.size = preferredItemSize(for: itemWidth)
|
||||
return layoutAttributes
|
||||
}
|
||||
|
||||
|
||||
@@ -222,9 +222,14 @@ class EmojiPackDetailViewController: UIViewController {
|
||||
present(shareSheet, animated: true)
|
||||
}
|
||||
|
||||
override func setEditing(_ editing: Bool, animated: Bool) {
|
||||
super.setEditing(editing, animated: animated)
|
||||
collectionView.edit(editing, animated: animated)
|
||||
}
|
||||
|
||||
func setToolbar() {
|
||||
var items: [UIBarButtonItem] = [self.collectionView.editButtonItem]
|
||||
if collectionView.isEditing {
|
||||
var items: [UIBarButtonItem] = [self.editButtonItem]
|
||||
if self.isEditing {
|
||||
if #available(iOS 26, *) {
|
||||
items.append(.fixedSpace(0))
|
||||
}
|
||||
@@ -238,7 +243,7 @@ class EmojiPackDetailViewController: UIViewController {
|
||||
primaryAction: nil,
|
||||
menu: menu
|
||||
)
|
||||
items = [self.collectionView.editButtonItem, dotdotdotButton]
|
||||
items = [self.editButtonItem, dotdotdotButton]
|
||||
}
|
||||
self.navigationItem.setRightBarButtonItems(items, animated: true)
|
||||
}
|
||||
|
||||