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