mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
using diffable datasource for collectionview
fixed stretched images in uikit gifview testing always animating tableview changes added adding to emojipack support from the sheet lol
This commit is contained in:
7 files changed
+44
-24
No files matched your search
@@ -110,19 +110,17 @@ struct EmojiPackDetailView: View {
|
|||||||
SearchView(
|
SearchView(
|
||||||
hoarder: hoarder,
|
hoarder: hoarder,
|
||||||
fromPackEditor: true,
|
fromPackEditor: true,
|
||||||
callback: { emoji in
|
callback: { pack.add($0); showAdder.toggle() }
|
||||||
pack.add(emoji.name)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
.navigationTitle("Search Emojis")
|
.navigationTitle("Search Emojis")
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
Button("", systemImage: "xmark") {
|
Button("", systemImage: "check") {
|
||||||
showAdder.toggle()
|
showAdder.toggle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.modifier(presentationHalfAndFullIfAv())
|
|
||||||
}
|
}
|
||||||
|
.modifier(presentationHalfAndFullIfAv())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ struct EmojiPackGridView: View {
|
|||||||
NavigationView2 {
|
NavigationView2 {
|
||||||
SearchView(hoarder: hoarder, fromPackEditor: true) { selection in
|
SearchView(hoarder: hoarder, fromPackEditor: true) { selection in
|
||||||
withAnimation(.spring) {
|
withAnimation(.spring) {
|
||||||
pack.add(selection.name)
|
pack.add(selection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Search Emojis")
|
.navigationTitle("Search Emojis")
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ struct SearchView: View {
|
|||||||
@State var stickerType: StickerType = .slackEmoji
|
@State var stickerType: StickerType = .slackEmoji
|
||||||
|
|
||||||
@State var fromPackEditor: Bool = false
|
@State var fromPackEditor: Bool = false
|
||||||
@State var callback: ((Emoji) -> Void) = { _ in }
|
@State var callback: ((String) -> Void) = { _ in }
|
||||||
var minColWidth: CGFloat { 75 }
|
var minColWidth: CGFloat { 75 }
|
||||||
var spacing: CGFloat { 10 }
|
var spacing: CGFloat { 10 }
|
||||||
var col: GridItem {
|
var col: GridItem {
|
||||||
@@ -51,7 +51,7 @@ struct SearchView: View {
|
|||||||
// .padding()
|
// .padding()
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
EmojiCollectionView(hoarder: hoarder, items: searchResult, width: 75, style: .plain)
|
EmojiCollectionView(hoarder: hoarder, items: searchResult, width: 75, style: .plain, onTapCallback: { callback($0) })
|
||||||
} else {
|
} else {
|
||||||
Picker("", selection: $stickerType) {
|
Picker("", selection: $stickerType) {
|
||||||
ForEach(StickerType.allCases) { type in
|
ForEach(StickerType.allCases) { type in
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
let style: EmojiCollectionView.Style
|
let style: EmojiCollectionView.Style
|
||||||
var edit: Bool?
|
var edit: Bool?
|
||||||
var onRemoveSUI: ((String) -> Void)?
|
var onRemoveSUI: ((String) -> Void)?
|
||||||
|
var onTapCallback: ((String) -> Void)?
|
||||||
|
|
||||||
func makeUIView(context: Context) -> UICollectionView {
|
func makeUIView(context: Context) -> UICollectionView {
|
||||||
let collectionView = context.coordinator as UICollectionViewController
|
let collectionView = context.coordinator as UICollectionViewController
|
||||||
collectionView.collectionView.register(PlainEmojiCollectionViewCell.self, forCellWithReuseIdentifier: "plain")
|
collectionView.collectionView.register(PlainEmojiCollectionViewCell.self, forCellWithReuseIdentifier: "plain")
|
||||||
collectionView.collectionView.register(EmojiCollectionViewCell.self, forCellWithReuseIdentifier: "full")
|
collectionView.collectionView.register(EmojiCollectionViewCell.self, forCellWithReuseIdentifier: "full")
|
||||||
collectionView.collectionView.dataSource = context.coordinator
|
|
||||||
collectionView.collectionView.delegate = context.coordinator
|
collectionView.collectionView.delegate = context.coordinator
|
||||||
return collectionView.collectionView
|
return collectionView.collectionView
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,7 @@ 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.onRemove = onRemoveSUI
|
context.coordinator.onRemove = onRemoveSUI
|
||||||
|
context.coordinator.onTap = onTapCallback
|
||||||
|
|
||||||
context.coordinator.edit = edit
|
context.coordinator.edit = edit
|
||||||
if edit ?? false {
|
if edit ?? false {
|
||||||
@@ -44,9 +45,22 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if items != context.coordinator.items {
|
// if items != context.coordinator.items {
|
||||||
|
// context.coordinator.items = items
|
||||||
|
// uiView.reloadData()
|
||||||
|
// }
|
||||||
|
let itemsBefore = context.coordinator.items
|
||||||
|
let itemsAfter = items
|
||||||
context.coordinator.items = items
|
context.coordinator.items = items
|
||||||
uiView.reloadData()
|
Task.detached {
|
||||||
|
// if !(-10_000...10_000).contains(itemsBefore.count-itemsAfter.count) ||
|
||||||
|
// itemsAfter == itemsBefore {
|
||||||
|
// //diff of more than 10k
|
||||||
|
// fatalError()
|
||||||
|
// await context.coordinator.instantApplySnapshot()
|
||||||
|
// } else {
|
||||||
|
await context.coordinator.applySnapshot(animated: true)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +87,7 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
var style: EmojiCollectionView.Style
|
var style: EmojiCollectionView.Style
|
||||||
var edit: Bool? = false
|
var edit: Bool? = false
|
||||||
var onRemove: ((String) -> Void)?
|
var onRemove: ((String) -> Void)?
|
||||||
|
var onTap: ((String) -> Void)?
|
||||||
|
|
||||||
var dataSource: UICollectionViewDiffableDataSource<Int, String>!
|
var dataSource: UICollectionViewDiffableDataSource<Int, String>!
|
||||||
|
|
||||||
@@ -97,7 +112,7 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
super.init(collectionViewLayout: layout)
|
super.init(collectionViewLayout: layout)
|
||||||
|
|
||||||
self.dataSource = UICollectionViewDiffableDataSource<Int, String>(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in
|
self.dataSource = UICollectionViewDiffableDataSource<Int, String>(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in
|
||||||
collectionView.cellForItem(at: indexPath)
|
self.collectionView(collectionView, cellForItemAt: indexPath)
|
||||||
}
|
}
|
||||||
collectionView.dataSource = dataSource
|
collectionView.dataSource = dataSource
|
||||||
|
|
||||||
@@ -136,6 +151,9 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
cellForItemAt indexPath: IndexPath
|
cellForItemAt indexPath: IndexPath
|
||||||
) -> UICollectionViewCell {
|
) -> UICollectionViewCell {
|
||||||
let cell: PlainEmojiCollectionViewCell
|
let cell: PlainEmojiCollectionViewCell
|
||||||
|
guard !hoarder.trie.dict.isEmpty else { return UICollectionViewCell() }
|
||||||
|
let emojiName = items[indexPath.item]
|
||||||
|
|
||||||
switch style {
|
switch style {
|
||||||
case .plain, .plainWithMenu, .jumboMoji:
|
case .plain, .plainWithMenu, .jumboMoji:
|
||||||
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell
|
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell
|
||||||
@@ -145,13 +163,14 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
(cell as! EmojiCollectionViewCell).onRemove = {
|
(cell as! EmojiCollectionViewCell).onRemove = {
|
||||||
guard let index = self.items.firstIndex(of: $0) else { return }
|
guard let index = self.items.firstIndex(of: $0) else { return }
|
||||||
self.items.remove(at: index)
|
self.items.remove(at: index)
|
||||||
collectionView.deleteItems(at: [IndexPath(row: index, section: 0)])
|
Task.detached {
|
||||||
|
await self.applySnapshot(animated: true)
|
||||||
|
}
|
||||||
self.onRemove?($0)
|
self.onRemove?($0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guard !hoarder.trie.dict.isEmpty else { return cell }
|
cell.onTap = { self.onTap?(emojiName) }
|
||||||
let emojiName = items[indexPath.item]
|
|
||||||
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)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
|||||||
var view: UIKitGifView = UIKitGifView(image: nil)
|
var view: UIKitGifView = UIKitGifView(image: nil)
|
||||||
var hostingController: UIHostingController<StickerPreview>?
|
var hostingController: UIHostingController<StickerPreview>?
|
||||||
var imageLoadTask: Task<Void, Never>?
|
var imageLoadTask: Task<Void, Never>?
|
||||||
|
var onTap: (() -> Void)?
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
@@ -24,7 +25,8 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
|||||||
view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
||||||
view.heightAnchor.constraint(equalTo: view.widthAnchor),
|
view.heightAnchor.constraint(equalTo: view.widthAnchor),
|
||||||
])
|
])
|
||||||
addGestureRecognizer(UITapGestureRecognizer())
|
let gestureRecogniser = UITapGestureRecognizer(target: self, action: #selector(handleTap))
|
||||||
|
addGestureRecognizer(gestureRecogniser)
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
@@ -56,8 +58,9 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
|||||||
// ])
|
// ])
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleTap(sender: UITapGestureRecognizer) {
|
@objc func handleTap(sender: UITapGestureRecognizer) {
|
||||||
guard sender.state == .ended else { return }
|
guard sender.state == .ended else { return }
|
||||||
|
onTap?()
|
||||||
print("tap")
|
print("tap")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ struct EmojiTableView: UIViewRepresentable {
|
|||||||
context.coordinator.items = items
|
context.coordinator.items = items
|
||||||
// guard itemsBefore != itemsAfter else { return }
|
// guard itemsBefore != itemsAfter else { return }
|
||||||
Task.detached {
|
Task.detached {
|
||||||
if !(-10_000...10_000).contains(itemsBefore.count-itemsAfter.count) ||
|
// if !(-10_000...10_000).contains(itemsBefore.count-itemsAfter.count) ||
|
||||||
itemsAfter == itemsBefore {
|
// itemsAfter == itemsBefore {
|
||||||
//diff of more than 10k
|
// //diff of more than 10k
|
||||||
await context.coordinator.instantApplySnapshot()
|
// await context.coordinator.instantApplySnapshot()
|
||||||
} else {
|
// } else {
|
||||||
await context.coordinator.applySnapshot(animated: true)
|
await context.coordinator.applySnapshot(animated: true)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import UIKit
|
|||||||
|
|
||||||
class UIKitGifView: UIImageView {
|
class UIKitGifView: UIImageView {
|
||||||
override init(image: UIImage?) {
|
override init(image: UIImage?) {
|
||||||
// <#code#>
|
|
||||||
super.init(image: image)
|
super.init(image: image)
|
||||||
|
self.contentMode = .scaleAspectFit
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
|
|||||||