buttons work

This commit is contained in:
neon443 committed 2026-04-30 12:54:44 +01:00
1 parent 56853e9cff
commit ecb4a6a4fe
3 files changed
+12 -26

No files matched your search

+1 -2
View File
@@ -118,8 +118,7 @@ struct SettingsView: View {
items: hoarder.emojis.prefix(1000).map { $0.name }, items: hoarder.emojis.prefix(1000).map { $0.name },
pack: nil, pack: nil,
width: 50, width: 50,
style: .plainWithMenu, style: .plainWithMenu
edit: false
) )
} label: { } label: {
Label("grid view", systemImage: "square.grid.2x2.fill") Label("grid view", systemImage: "square.grid.2x2.fill")
@@ -16,7 +16,7 @@ struct EmojiCollectionView: UIViewRepresentable {
let pack: EmojiPack? let pack: EmojiPack?
let width: CGFloat let width: CGFloat
let style: EmojiCollectionView.Style let style: EmojiCollectionView.Style
var edit: Bool var edit: Bool?
var onRemove: ((String) -> Void)? var onRemove: ((String) -> Void)?
func makeUIView(context: Context) -> UICollectionView { func makeUIView(context: Context) -> UICollectionView {
@@ -31,19 +31,19 @@ struct EmojiCollectionView: UIViewRepresentable {
func updateUIView(_ uiView: UICollectionView, context: Context) { func updateUIView(_ uiView: UICollectionView, context: Context) {
context.coordinator.hoarder = hoarder context.coordinator.hoarder = hoarder
context.coordinator.edit = edit if edit ?? false {
if edit {
context.coordinator.startAnimating() context.coordinator.startAnimating()
} else { } else {
context.coordinator.stopAnimating() context.coordinator.stopAnimating()
} }
for cell in uiView.visibleCells { for cell in uiView.visibleCells {
if let cell = cell as? EmojiCollectionViewCell { if let cell = cell as? EmojiCollectionViewCell {
cell.setEdit(to: edit) cell.setEdit(to: edit)
cell.onDelete = onRemove
} }
} }
context.coordinator.onRemove = onRemove
if items != context.coordinator.items || context.coordinator.pack != pack { if items != context.coordinator.items || context.coordinator.pack != pack {
context.coordinator.items = items context.coordinator.items = items
context.coordinator.pack = pack context.coordinator.pack = pack
@@ -57,9 +57,7 @@ struct EmojiCollectionView: UIViewRepresentable {
items: items, items: items,
pack: pack, pack: pack,
width: width, width: width,
style: style, style: style
edit: edit,
onRemove: onRemove
) )
} }
@@ -75,8 +73,6 @@ struct EmojiCollectionView: UIViewRepresentable {
var pack: EmojiPack? var pack: EmojiPack?
var width: CGFloat var width: CGFloat
var style: EmojiCollectionView.Style var style: EmojiCollectionView.Style
var edit: Bool
var onRemove: ((String) -> Void)?
let initDate = Date.now let initDate = Date.now
var layout = UICollectionViewFlowLayout() var layout = UICollectionViewFlowLayout()
@@ -88,8 +84,6 @@ struct EmojiCollectionView: UIViewRepresentable {
pack: EmojiPack?, pack: EmojiPack?,
width: CGFloat, width: CGFloat,
style: EmojiCollectionView.Style, style: EmojiCollectionView.Style,
edit: Bool,
onRemove: ((String) -> Void)?
) { ) {
self.hoarder = hoarder self.hoarder = hoarder
self.items = items self.items = items
@@ -99,8 +93,6 @@ struct EmojiCollectionView: UIViewRepresentable {
} }
self.width = width self.width = width
self.style = style self.style = style
self.edit = edit
self.onRemove = onRemove
layout.minimumInteritemSpacing = 8 layout.minimumInteritemSpacing = 8
@@ -219,4 +211,3 @@ struct EmojiCollectionView: UIViewRepresentable {
} }
} }
} }
@@ -12,7 +12,7 @@ import SwiftUI
class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
let label = UILabel() let label = UILabel()
let button = UIButton(type: .custom) let button = UIButton(type: .custom)
var edit: Bool = false var edit: Bool?
var onDelete: ((String) -> Void)? var onDelete: ((String) -> Void)?
override init(frame: CGRect) { override init(frame: CGRect) {
@@ -61,25 +61,20 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
contentView.bringSubviewToFront(button) contentView.bringSubviewToFront(button)
} }
func setEdit(to newValue: Bool) { func setEdit(to newValue: Bool?) {
self.edit = newValue self.edit = newValue
if edit { if edit ?? false {
contentView.bringSubviewToFront(button) contentView.bringSubviewToFront(button)
self.button.isHidden = false self.button.isHidden = false
UIView.animate(withDuration: 0.2) { UIView.animate(withDuration: 0.2) {
self.button.alpha = 1 self.button.alpha = 1
} completion: { _ in
} }
} else { } else {
// UIView.animate(withDuration: 0.1) {
// self.button.transform = CGAffineTransform.identity
// } completion: { _ in
UIView.animate(withDuration: 0.2) { UIView.animate(withDuration: 0.2) {
self.button.alpha = 0 self.button.alpha = 0
} completion: { _ in } completion: { _ in
self.button.isHidden = true self.button.isHidden = true
} }
// }
} }
} }
@@ -89,8 +84,9 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
@objc @objc
func deleteTapped() { func deleteTapped() {
onDelete?("") if let emojiName = label.text {
print(UUID()) onDelete?(emojiName)
}
} }
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.