From e104b028dd9e40b0c6ed9ed72cf92b7a09f7b262 Mon Sep 17 00:00:00 2001 From: Nihaal Sharma <69979447+neon443@users.noreply.github.com> Date: Tue, 25 Aug 2026 17:01:50 +0530 Subject: [PATCH] fix all editing related issues with emojicollectionview not the remove item race thing yet --- .../UIKit/CollectionView/EmojiCollectionView.swift | 11 ++--------- .../CollectionView/EmojiCollectionViewCell.swift | 14 +++++--------- .../PlainEmojiCollectionViewCell.swift | 6 +++++- .../EmojiPacks/EmojiPackDetailViewController.swift | 11 ++++++++--- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index c13e01e..a14d74f 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -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( diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift index 43f6a9f..fafa75b 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift @@ -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() { diff --git a/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift index 80e7aae..cb3c59d 100644 --- a/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift +++ b/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift @@ -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 } diff --git a/StickerSlack/UIKit/EmojiPacks/EmojiPackDetailViewController.swift b/StickerSlack/UIKit/EmojiPacks/EmojiPackDetailViewController.swift index 752b2de..90906d3 100644 --- a/StickerSlack/UIKit/EmojiPacks/EmojiPackDetailViewController.swift +++ b/StickerSlack/UIKit/EmojiPacks/EmojiPackDetailViewController.swift @@ -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) }