mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
added a delete button
This commit is contained in:
5 files changed
+43
-8
No files matched your search
@@ -45,7 +45,8 @@ struct DownloadedView: View {
|
|||||||
items: emojiHoarder.downloadedStickersArr,
|
items: emojiHoarder.downloadedStickersArr,
|
||||||
pack: nil,
|
pack: nil,
|
||||||
width: 75,
|
width: 75,
|
||||||
style: .plainWithMenu
|
style: .plainWithMenu,
|
||||||
|
edit: false
|
||||||
)
|
)
|
||||||
// GeometryReader { geo in
|
// GeometryReader { geo in
|
||||||
// ScrollView {
|
// ScrollView {
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ struct EmojiPackDetailView: View {
|
|||||||
items: pack.items,
|
items: pack.items,
|
||||||
pack: pack,
|
pack: pack,
|
||||||
width: 75,
|
width: 75,
|
||||||
style: .full
|
style: .full,
|
||||||
|
edit: edit
|
||||||
)
|
)
|
||||||
|
|
||||||
GeometryReader { geo in
|
GeometryReader { geo in
|
||||||
|
|||||||
@@ -118,7 +118,8 @@ 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,6 +16,8 @@ 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 onRemove: ((String) -> Void)?
|
||||||
|
|
||||||
func makeUIView(context: Context) -> UICollectionView {
|
func makeUIView(context: Context) -> UICollectionView {
|
||||||
let collectionView = context.coordinator as UICollectionViewController
|
let collectionView = context.coordinator as UICollectionViewController
|
||||||
@@ -30,6 +32,8 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
context.coordinator.hoarder = hoarder
|
context.coordinator.hoarder = hoarder
|
||||||
context.coordinator.items = items
|
context.coordinator.items = items
|
||||||
context.coordinator.pack = pack
|
context.coordinator.pack = pack
|
||||||
|
context.coordinator.edit = edit
|
||||||
|
context.coordinator.onRemove = onRemove
|
||||||
uiView.reloadData()
|
uiView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +43,9 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
items: items,
|
items: items,
|
||||||
pack: pack,
|
pack: pack,
|
||||||
width: width,
|
width: width,
|
||||||
style: style
|
style: style,
|
||||||
|
edit: edit,
|
||||||
|
onRemove: onRemove
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +61,8 @@ 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)?
|
||||||
|
|
||||||
var layout = UICollectionViewFlowLayout()
|
var layout = UICollectionViewFlowLayout()
|
||||||
|
|
||||||
@@ -63,7 +71,9 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
items: [String],
|
items: [String],
|
||||||
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
|
||||||
@@ -73,6 +83,8 @@ 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
|
||||||
|
|
||||||
@@ -102,6 +114,7 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell
|
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell
|
||||||
case .full:
|
case .full:
|
||||||
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell
|
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell
|
||||||
|
(cell as! EmojiCollectionViewCell).setEdit(to: edit)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard !hoarder.trie.dict.isEmpty else { return cell }
|
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 }
|
guard let emoji = hoarder.trie.dict[emojiName] else { return cell }
|
||||||
|
|
||||||
cell.configure(with: hoarder, emoji: emoji)
|
cell.configure(with: hoarder, emoji: emoji)
|
||||||
|
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import SwiftUI
|
|||||||
|
|
||||||
class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
||||||
let label = UILabel()
|
let label = UILabel()
|
||||||
|
let deleteButton = UIButton(type: .custom)
|
||||||
|
var edit: Bool = false
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
@@ -25,6 +27,14 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
|||||||
label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||||
label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
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) {
|
required init?(coder: NSCoder) {
|
||||||
@@ -38,10 +48,18 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
|||||||
override func configure(with: EmojiHoarder, emoji: Emoji) {
|
override func configure(with: EmojiHoarder, emoji: Emoji) {
|
||||||
super.configure(with: with, emoji: emoji)
|
super.configure(with: with, emoji: emoji)
|
||||||
label.text = emoji.UIName
|
label.text = emoji.UIName
|
||||||
|
contentView.bringSubviewToFront(deleteButton)
|
||||||
|
|
||||||
if label.superview == nil {
|
NSLayoutConstraint.activate([
|
||||||
contentView.addSubview(label)
|
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() {
|
override func prepareForReuse() {
|
||||||
|
|||||||