mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
uikit colectionview for emojipackdetailview
emojicollectionview has better handling of changing widths and can have custom item widths addRemove to add or remove an emoji from a pack fix delete all from pack not using batch delete extract a view to empty emojipackview
This commit is contained in:
9 files changed
+237
-174
No files matched your search
@@ -11,9 +11,9 @@ import SwiftUI
|
||||
|
||||
struct EmojiCollectionView: UIViewRepresentable {
|
||||
let hoarder: EmojiHoarder
|
||||
let items: [String]
|
||||
let spacing: Int = 0
|
||||
let columns: Int?
|
||||
let pack: EmojiPack
|
||||
let width: CGFloat
|
||||
let spacing: CGFloat = 16
|
||||
|
||||
func makeUIView(context: Context) -> UICollectionView {
|
||||
let collectionView = context.coordinator as UICollectionViewController
|
||||
@@ -24,31 +24,31 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
|
||||
func updateUIView(_ uiView: UICollectionView, context: Context) {
|
||||
context.coordinator.hoarder = hoarder
|
||||
context.coordinator.items = items
|
||||
context.coordinator.pack = pack
|
||||
uiView.reloadData()
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(hoarder: hoarder, items: items, columns: 6)
|
||||
Coordinator(hoarder: hoarder, pack: pack, width: width, spacing: spacing)
|
||||
}
|
||||
|
||||
final class Coordinator: UICollectionViewController {
|
||||
var hoarder: EmojiHoarder
|
||||
var items: [String]
|
||||
var columns: Int?
|
||||
var pack: EmojiPack
|
||||
var width: CGFloat
|
||||
var spacing: CGFloat
|
||||
var layout = UICollectionViewFlowLayout()
|
||||
|
||||
init(hoarder: EmojiHoarder, items: [String], columns: Int?) {
|
||||
init(hoarder: EmojiHoarder, pack: EmojiPack, width: CGFloat, spacing: CGFloat) {
|
||||
self.hoarder = hoarder
|
||||
self.items = items
|
||||
self.columns = columns
|
||||
self.pack = pack
|
||||
self.width = width
|
||||
self.spacing = spacing
|
||||
|
||||
if columns != nil {
|
||||
layout.itemSize = CGSize(
|
||||
width: UIScreen.main.bounds.width/CGFloat(columns!),
|
||||
height: UIScreen.main.bounds.width/CGFloat(columns!)
|
||||
)
|
||||
}
|
||||
layout.sectionInset.left = 16
|
||||
layout.sectionInset.right = 16
|
||||
|
||||
layout.itemSize = CGSize(width: width, height: width)
|
||||
|
||||
super.init(collectionViewLayout: layout)
|
||||
}
|
||||
@@ -57,8 +57,15 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewDidLayoutSubviews() {
|
||||
layout.sectionInset.left = 16
|
||||
layout.sectionInset.right = 16
|
||||
|
||||
layout.itemSize = CGSize(width: width, height: width)
|
||||
}
|
||||
|
||||
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return items.count
|
||||
return pack.items.count
|
||||
}
|
||||
|
||||
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
@@ -66,7 +73,7 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
|
||||
guard !hoarder.trie.dict.isEmpty else { return cell }
|
||||
|
||||
let emojiName = items[indexPath.item]
|
||||
let emojiName = pack.items[indexPath.item]
|
||||
|
||||
guard let emoji = hoarder.trie.dict[emojiName] else { return cell }
|
||||
|
||||
|
||||