added a delete button

This commit is contained in:
Nihaal Sharma committed 2026-04-29 18:52:51 +01:00
1 parent 3047f24ad7
commit a62a663a6d
5 files changed
+43 -8

No files matched your search

+2 -1
View File
@@ -45,7 +45,8 @@ struct DownloadedView: View {
items: emojiHoarder.downloadedStickersArr,
pack: nil,
width: 75,
style: .plainWithMenu
style: .plainWithMenu,
edit: false
)
// GeometryReader { geo in
// ScrollView {
@@ -77,7 +77,8 @@ struct EmojiPackDetailView: View {
items: pack.items,
pack: pack,
width: 75,
style: .full
style: .full,
edit: edit
)
GeometryReader { geo in
+2 -1
View File
@@ -118,7 +118,8 @@ struct SettingsView: View {
items: hoarder.emojis.prefix(1000).map { $0.name },
pack: nil,
width: 50,
style: .plainWithMenu
style: .plainWithMenu,
edit: false
)
} label: {
Label("grid view", systemImage: "square.grid.2x2.fill")
@@ -16,6 +16,8 @@ struct EmojiCollectionView: UIViewRepresentable {
let pack: EmojiPack?
let width: CGFloat
let style: EmojiCollectionView.Style
var edit: Bool
var onRemove: ((String) -> Void)?
func makeUIView(context: Context) -> UICollectionView {
let collectionView = context.coordinator as UICollectionViewController
@@ -30,6 +32,8 @@ struct EmojiCollectionView: UIViewRepresentable {
context.coordinator.hoarder = hoarder
context.coordinator.items = items
context.coordinator.pack = pack
context.coordinator.edit = edit
context.coordinator.onRemove = onRemove
uiView.reloadData()
}
@@ -39,7 +43,9 @@ struct EmojiCollectionView: UIViewRepresentable {
items: items,
pack: pack,
width: width,
style: style
style: style,
edit: edit,
onRemove: onRemove
)
}
@@ -55,6 +61,8 @@ struct EmojiCollectionView: UIViewRepresentable {
var pack: EmojiPack?
var width: CGFloat
var style: EmojiCollectionView.Style
var edit: Bool
var onRemove: ((String) -> Void)?
var layout = UICollectionViewFlowLayout()
@@ -63,7 +71,9 @@ struct EmojiCollectionView: UIViewRepresentable {
items: [String],
pack: EmojiPack?,
width: CGFloat,
style: EmojiCollectionView.Style
style: EmojiCollectionView.Style,
edit: Bool,
onRemove: ((String) -> Void)?
) {
self.hoarder = hoarder
self.items = items
@@ -73,6 +83,8 @@ struct EmojiCollectionView: UIViewRepresentable {
}
self.width = width
self.style = style
self.edit = edit
self.onRemove = onRemove
layout.minimumInteritemSpacing = 8
@@ -102,6 +114,7 @@ struct EmojiCollectionView: UIViewRepresentable {
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell
case .full:
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell
(cell as! EmojiCollectionViewCell).setEdit(to: edit)
}
guard !hoarder.trie.dict.isEmpty else { return cell }
@@ -109,6 +122,7 @@ struct EmojiCollectionView: UIViewRepresentable {
guard let emoji = hoarder.trie.dict[emojiName] else { return cell }
cell.configure(with: hoarder, emoji: emoji)
return cell
}
@@ -11,6 +11,8 @@ import SwiftUI
class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
let label = UILabel()
let deleteButton = UIButton(type: .custom)
var edit: Bool = false
override init(frame: CGRect) {
super.init(frame: frame)
@@ -25,6 +27,14 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
])
deleteButton.setImage(UIImage(systemName: "minus.circle.fill"), for: .normal)
deleteButton.imageView?.contentMode = .scaleAspectFit
deleteButton.configuration = .plain()
contentView.addSubview(deleteButton)
deleteButton.tintColor = .systemRed
deleteButton.clipsToBounds = false
deleteButton.translatesAutoresizingMaskIntoConstraints = false
}
required init?(coder: NSCoder) {
@@ -38,10 +48,18 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
override func configure(with: EmojiHoarder, emoji: Emoji) {
super.configure(with: with, emoji: emoji)
label.text = emoji.UIName
contentView.bringSubviewToFront(deleteButton)
if label.superview == nil {
contentView.addSubview(label)
}
NSLayoutConstraint.activate([
deleteButton.topAnchor.constraint(equalTo: hostingController!.view.topAnchor, constant: -16),
deleteButton.leadingAnchor.constraint(equalTo: hostingController!.view.leadingAnchor, constant: -16),
deleteButton.heightAnchor.constraint(equalToConstant: 32),
deleteButton.widthAnchor.constraint(equalToConstant: 32)
])
}
func setEdit(to newValue: Bool) {
self.edit = newValue
}
override func prepareForReuse() {
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.