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
+16 -30

No files matched your search

+1 -2
View File
@@ -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")
@@ -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 {
}
}
}
@@ -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? {
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.