From ecb4a6a4fef6810daeb9f4753ffcb8249787be72 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 30 Apr 2026 12:54:44 +0100 Subject: [PATCH] buttons work --- StickerSlack/SwiftUI/SettingsView.swift | 3 +-- .../CollectionView/EmojiCollectionView.swift | 19 ++++----------- .../EmojiCollectionViewCell.swift | 24 ++++++++----------- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/StickerSlack/SwiftUI/SettingsView.swift b/StickerSlack/SwiftUI/SettingsView.swift index 442aebc..b525e17 100644 --- a/StickerSlack/SwiftUI/SettingsView.swift +++ b/StickerSlack/SwiftUI/SettingsView.swift @@ -118,8 +118,7 @@ struct SettingsView: View { items: hoarder.emojis.prefix(1000).map { $0.name }, pack: nil, width: 50, - style: .plainWithMenu, - edit: false + style: .plainWithMenu ) } label: { Label("grid view", systemImage: "square.grid.2x2.fill") diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index c8ee647..3f6c0f9 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -16,7 +16,7 @@ struct EmojiCollectionView: UIViewRepresentable { let pack: EmojiPack? let width: CGFloat let style: EmojiCollectionView.Style - var edit: Bool + var edit: Bool? var onRemove: ((String) -> Void)? func makeUIView(context: Context) -> UICollectionView { @@ -31,19 +31,19 @@ struct EmojiCollectionView: UIViewRepresentable { func updateUIView(_ uiView: UICollectionView, context: Context) { context.coordinator.hoarder = hoarder - context.coordinator.edit = edit - if edit { + if edit ?? false { context.coordinator.startAnimating() } else { context.coordinator.stopAnimating() } + for cell in uiView.visibleCells { if let cell = cell as? EmojiCollectionViewCell { cell.setEdit(to: edit) + cell.onDelete = onRemove } } - context.coordinator.onRemove = onRemove if items != context.coordinator.items || context.coordinator.pack != pack { context.coordinator.items = items context.coordinator.pack = pack @@ -57,9 +57,7 @@ struct EmojiCollectionView: UIViewRepresentable { items: items, pack: pack, width: width, - style: style, - edit: edit, - onRemove: onRemove + style: style ) } @@ -75,8 +73,6 @@ struct EmojiCollectionView: UIViewRepresentable { var pack: EmojiPack? var width: CGFloat var style: EmojiCollectionView.Style - var edit: Bool - var onRemove: ((String) -> Void)? let initDate = Date.now var layout = UICollectionViewFlowLayout() @@ -88,8 +84,6 @@ struct EmojiCollectionView: UIViewRepresentable { pack: EmojiPack?, width: CGFloat, style: EmojiCollectionView.Style, - edit: Bool, - onRemove: ((String) -> Void)? ) { self.hoarder = hoarder self.items = items @@ -99,8 +93,6 @@ struct EmojiCollectionView: UIViewRepresentable { } self.width = width self.style = style - self.edit = edit - self.onRemove = onRemove layout.minimumInteritemSpacing = 8 @@ -219,4 +211,3 @@ struct EmojiCollectionView: UIViewRepresentable { } } } - diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift index 8ce4e0b..5e04752 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift @@ -12,7 +12,7 @@ import SwiftUI class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { let label = UILabel() let button = UIButton(type: .custom) - var edit: Bool = false + var edit: Bool? var onDelete: ((String) -> Void)? override init(frame: CGRect) { @@ -61,25 +61,20 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { contentView.bringSubviewToFront(button) } - func setEdit(to newValue: Bool) { + func setEdit(to newValue: Bool?) { self.edit = newValue - if edit { + if edit ?? false { contentView.bringSubviewToFront(button) self.button.isHidden = false UIView.animate(withDuration: 0.2) { self.button.alpha = 1 - } completion: { _ in } } else { -// UIView.animate(withDuration: 0.1) { -// self.button.transform = CGAffineTransform.identity -// } completion: { _ in UIView.animate(withDuration: 0.2) { - self.button.alpha = 0 - } completion: { _ in - self.button.isHidden = true - } -// } + self.button.alpha = 0 + } completion: { _ in + self.button.isHidden = true + } } } @@ -89,8 +84,9 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { @objc func deleteTapped() { - onDelete?("") - print(UUID()) + if let emojiName = label.text { + onDelete?(emojiName) + } } override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {