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
+121
-58
No files matched your search
@@ -49,6 +49,8 @@
|
|||||||
A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
|
A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
|
||||||
A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
|
A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
|
||||||
A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */; };
|
A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */; };
|
||||||
|
A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; };
|
||||||
|
A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; };
|
||||||
A986A6AE2EB658DF00B6E0FA /* Messages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A969D6932EA3E86500399C05 /* Messages.framework */; };
|
A986A6AE2EB658DF00B6E0FA /* Messages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A969D6932EA3E86500399C05 /* Messages.framework */; };
|
||||||
A986A6BA2EB658E100B6E0FA /* StickerSlackiMessageApp.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
A986A6BA2EB658E100B6E0FA /* StickerSlackiMessageApp.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||||
A986A6C12EB6595F00B6E0FA /* EmojiHoarder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F72EA04F2300215164 /* EmojiHoarder.swift */; };
|
A986A6C12EB6595F00B6E0FA /* EmojiHoarder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F72EA04F2300215164 /* EmojiHoarder.swift */; };
|
||||||
@@ -206,6 +208,7 @@
|
|||||||
A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = "<group>"; };
|
A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = "<group>"; };
|
||||||
A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; };
|
A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; };
|
A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; };
|
||||||
|
A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyEmojiPackView.swift; sourceTree = "<group>"; };
|
||||||
A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = StickerSlackiMessageApp.appex; sourceTree = BUILT_PRODUCTS_DIR; };
|
A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = StickerSlackiMessageApp.appex; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
A986A6C62EB659E000B6E0FA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
A986A6C62EB659E000B6E0FA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
A986A6C72EB659E000B6E0FA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
A986A6C72EB659E000B6E0FA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
@@ -325,6 +328,7 @@
|
|||||||
A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */,
|
A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */,
|
||||||
A9F7B37F2F8951210071F198 /* EmojiPackImporterView.swift */,
|
A9F7B37F2F8951210071F198 /* EmojiPackImporterView.swift */,
|
||||||
A9C52F6E2F89A22000078588 /* Wiggle.metal */,
|
A9C52F6E2F89A22000078588 /* Wiggle.metal */,
|
||||||
|
A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */,
|
||||||
);
|
);
|
||||||
path = EmojiPacks;
|
path = EmojiPacks;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -685,6 +689,7 @@
|
|||||||
A9104C802EB4022500D160EA /* MSSticker.swift in Sources */,
|
A9104C802EB4022500D160EA /* MSSticker.swift in Sources */,
|
||||||
A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */,
|
A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */,
|
||||||
A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */,
|
A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */,
|
||||||
|
A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */,
|
||||||
A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */,
|
A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */,
|
||||||
A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */,
|
A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */,
|
||||||
A957C1742ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */,
|
A957C1742ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */,
|
||||||
@@ -799,6 +804,7 @@
|
|||||||
A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */,
|
A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */,
|
||||||
A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */,
|
A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */,
|
||||||
A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */,
|
A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */,
|
||||||
|
A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */,
|
||||||
A955B3F62EC22EE900E1732D /* SearchView.swift in Sources */,
|
A955B3F62EC22EE900E1732D /* SearchView.swift in Sources */,
|
||||||
A9BDEADF2F82BC93002798DF /* NoStickersView.swift in Sources */,
|
A9BDEADF2F82BC93002798DF /* NoStickersView.swift in Sources */,
|
||||||
A9B9A8322EB2CD29004C9245 /* SlackResponse.swift in Sources */,
|
A9B9A8322EB2CD29004C9245 /* SlackResponse.swift in Sources */,
|
||||||
|
|||||||
@@ -105,6 +105,14 @@ struct EmojiPack: Identifiable, Codable {
|
|||||||
self.items.remove(at: index)
|
self.items.remove(at: index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutating func addRemove(_ item: String) {
|
||||||
|
if items.contains(item) {
|
||||||
|
self.remove(item)
|
||||||
|
} else {
|
||||||
|
self.add(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nonisolated func downloadAll(hoarder: EmojiHoarder) async {
|
nonisolated func downloadAll(hoarder: EmojiHoarder) async {
|
||||||
let dict = await hoarder.trie.dict
|
let dict = await hoarder.trie.dict
|
||||||
var emojis: [Emoji] = []
|
var emojis: [Emoji] = []
|
||||||
@@ -117,11 +125,15 @@ struct EmojiPack: Identifiable, Codable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nonisolated func deleteAll(hoarder: EmojiHoarder) async {
|
nonisolated func deleteAll(hoarder: EmojiHoarder) async {
|
||||||
|
let dict = await hoarder.trie.dict
|
||||||
|
var emojis: [Emoji] = []
|
||||||
for item in items {
|
for item in items {
|
||||||
guard let emoji = await hoarder.trie.dict[item] else { continue }
|
if let foundEmoji = dict[item] {
|
||||||
await hoarder.delete(emoji: emoji)
|
emojis.append(foundEmoji)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await hoarder.batchDelete(emojis: emojis)
|
||||||
|
}
|
||||||
|
|
||||||
func shareLink() -> URL {
|
func shareLink() -> URL {
|
||||||
// var url = URL(string: "stickerslack://shared.pack/")!
|
// var url = URL(string: "stickerslack://shared.pack/")!
|
||||||
|
|||||||
@@ -196,7 +196,6 @@ class EmojiHoarder: BaseHoarder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nonisolated func batchDownload(emojis emojisToDownload: [any StickerProtocol]) async {
|
nonisolated func batchDownload(emojis emojisToDownload: [any StickerProtocol]) async {
|
||||||
let emojiNames = emojisToDownload.map { $0.name }
|
|
||||||
for emoji in emojisToDownload {
|
for emoji in emojisToDownload {
|
||||||
await download(emoji: emoji, skipStoreIndex: true)
|
await download(emoji: emoji, skipStoreIndex: true)
|
||||||
|
|
||||||
@@ -219,7 +218,6 @@ class EmojiHoarder: BaseHoarder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nonisolated func batchDelete(emojis emojisToDelete: [any StickerProtocol]) async {
|
nonisolated func batchDelete(emojis emojisToDelete: [any StickerProtocol]) async {
|
||||||
let emojiNames = emojisToDelete.map { $0.name }
|
|
||||||
for emoji in emojisToDelete {
|
for emoji in emojisToDelete {
|
||||||
await delete(emoji: emoji, skipStoreIndex: true)
|
await delete(emoji: emoji, skipStoreIndex: true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ struct EmojiPackDetailView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView2 {
|
NavigationView2 {
|
||||||
GeometryReader { geo in
|
// GeometryReader { geo in
|
||||||
ScrollView {
|
VStack {
|
||||||
Button() {
|
Button() {
|
||||||
editName.toggle()
|
editName.toggle()
|
||||||
} label: {
|
} label: {
|
||||||
@@ -70,37 +70,19 @@ struct EmojiPackDetailView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pack.items.isEmpty {
|
if pack.items.isEmpty {
|
||||||
VStack(alignment: .center) {
|
EmptyEmojiPackView()
|
||||||
HStack {
|
|
||||||
Image(systemName: "exclamationmark.triangle.fill")
|
|
||||||
Text("No Emoji")
|
|
||||||
.bold()
|
|
||||||
Image(systemName: "exclamationmark.triangle.fill")
|
|
||||||
}
|
|
||||||
.foregroundStyle(.yellow)
|
|
||||||
Text("This pack contians no emojis")
|
|
||||||
.padding(.vertical, 5)
|
|
||||||
.foregroundStyle(.foreground)
|
|
||||||
Text("Add emojis to this pack by editing it using the pencil button in the toolbar.")
|
|
||||||
Text("You can also change the name and description by tapping it in edit mode.")
|
|
||||||
.padding(.vertical, 5)
|
|
||||||
}
|
|
||||||
.transition(.scale)
|
|
||||||
.foregroundStyle(.gray)
|
|
||||||
.multilineTextAlignment(.center)
|
|
||||||
.frame(maxWidth: .infinity)
|
|
||||||
.padding()
|
|
||||||
.background {
|
|
||||||
Color.accentColor.opacity(0.2)
|
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
||||||
.blur(radius: 5)
|
|
||||||
.shadow(color: .accentColor, radius: 5)
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EmojiCollectionView(
|
||||||
|
hoarder: hoarder,
|
||||||
|
pack: pack,
|
||||||
|
width: 80
|
||||||
|
)
|
||||||
|
|
||||||
|
GeometryReader { geo in
|
||||||
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
|
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
|
||||||
let layout = Array(repeating: col, count: columns)
|
let layout = Array(repeating: col, count: columns)
|
||||||
|
ScrollView {
|
||||||
LazyVGrid(columns: layout, spacing: spacing) {
|
LazyVGrid(columns: layout, spacing: spacing) {
|
||||||
ForEach(pack.items, id: \.self) { name in
|
ForEach(pack.items, id: \.self) { name in
|
||||||
TimelineView(.animation) { tl in
|
TimelineView(.animation) { tl in
|
||||||
@@ -194,6 +176,8 @@ struct EmojiPackDetailView: View {
|
|||||||
}
|
}
|
||||||
.animation(.spring, value: pack.items)
|
.animation(.spring, value: pack.items)
|
||||||
.padding()
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Text("\(pack.items.count) Emoji\(pack.items.count.plural)")
|
Text("\(pack.items.count) Emoji\(pack.items.count.plural)")
|
||||||
.bold()
|
.bold()
|
||||||
@@ -213,7 +197,7 @@ struct EmojiPackDetailView: View {
|
|||||||
"",
|
"",
|
||||||
systemImage: edit ? "checkmark" : "pencil"
|
systemImage: edit ? "checkmark" : "pencil"
|
||||||
) {
|
) {
|
||||||
withAnimation { edit.toggle() }
|
withAnimation(.spring) { edit.toggle() }
|
||||||
}
|
}
|
||||||
.modifier(glassButtonIfAv(edit))
|
.modifier(glassButtonIfAv(edit))
|
||||||
.tint(edit ? Color.accentColor : .primary)
|
.tint(edit ? Color.accentColor : .primary)
|
||||||
@@ -245,7 +229,7 @@ struct EmojiPackDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// EmptyEmojiPackView.swift
|
||||||
|
// StickerSlack
|
||||||
|
//
|
||||||
|
// Created by neon443 on 26/04/2026.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct EmptyEmojiPackView: View {
|
||||||
|
var body: some View {
|
||||||
|
VStack(alignment: .center) {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "exclamationmark.triangle.fill")
|
||||||
|
Text("No Emoji")
|
||||||
|
.bold()
|
||||||
|
Image(systemName: "exclamationmark.triangle.fill")
|
||||||
|
}
|
||||||
|
.foregroundStyle(.yellow)
|
||||||
|
Text("This pack contians no emojis")
|
||||||
|
.padding(.vertical, 5)
|
||||||
|
.foregroundStyle(.foreground)
|
||||||
|
Text("Add emojis to this pack by editing it using the pencil button in the toolbar.")
|
||||||
|
Text("You can also change the name and description by tapping it in edit mode.")
|
||||||
|
.padding(.vertical, 5)
|
||||||
|
}
|
||||||
|
.transition(.scale)
|
||||||
|
.foregroundStyle(.gray)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.padding()
|
||||||
|
.background {
|
||||||
|
Color.accentColor.opacity(0.2)
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||||
|
.blur(radius: 5)
|
||||||
|
.shadow(color: .accentColor, radius: 5)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
EmptyEmojiPackView()
|
||||||
|
}
|
||||||
@@ -115,8 +115,8 @@ struct SettingsView: View {
|
|||||||
NavigationLink {
|
NavigationLink {
|
||||||
EmojiCollectionView(
|
EmojiCollectionView(
|
||||||
hoarder: hoarder,
|
hoarder: hoarder,
|
||||||
items: hoarder.emojis.prefix(100).map { $0.name },
|
pack: .test,
|
||||||
columns: 4
|
width: 50
|
||||||
)
|
)
|
||||||
} label: {
|
} label: {
|
||||||
Label("grid view", systemImage: "square.grid.2x2.fill")
|
Label("grid view", systemImage: "square.grid.2x2.fill")
|
||||||
|
|||||||
@@ -126,10 +126,13 @@ struct AddToPackMenuView: View {
|
|||||||
}
|
}
|
||||||
ForEach($emojiHoarder.emojiPacks) { $pack in
|
ForEach($emojiHoarder.emojiPacks) { $pack in
|
||||||
Button() {
|
Button() {
|
||||||
pack.add(sticker.name)
|
pack.addRemove(sticker.name)
|
||||||
} label: {
|
} label: {
|
||||||
|
if pack.items.contains(sticker.name) {
|
||||||
|
Image(systemName: "checkmark")
|
||||||
|
}
|
||||||
Text(pack.name)
|
Text(pack.name)
|
||||||
Text("\(pack.description)\n\(pack.items.count) item\(pack.items.count.plural)")
|
Text("\(pack.items.count) item"+pack.items.count.plural)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import SwiftUI
|
|||||||
|
|
||||||
struct EmojiCollectionView: UIViewRepresentable {
|
struct EmojiCollectionView: UIViewRepresentable {
|
||||||
let hoarder: EmojiHoarder
|
let hoarder: EmojiHoarder
|
||||||
let items: [String]
|
let pack: EmojiPack
|
||||||
let spacing: Int = 0
|
let width: CGFloat
|
||||||
let columns: Int?
|
let spacing: CGFloat = 16
|
||||||
|
|
||||||
func makeUIView(context: Context) -> UICollectionView {
|
func makeUIView(context: Context) -> UICollectionView {
|
||||||
let collectionView = context.coordinator as UICollectionViewController
|
let collectionView = context.coordinator as UICollectionViewController
|
||||||
@@ -24,31 +24,31 @@ 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.items = items
|
context.coordinator.pack = pack
|
||||||
uiView.reloadData()
|
uiView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCoordinator() -> Coordinator {
|
func makeCoordinator() -> Coordinator {
|
||||||
Coordinator(hoarder: hoarder, items: items, columns: 6)
|
Coordinator(hoarder: hoarder, pack: pack, width: width, spacing: spacing)
|
||||||
}
|
}
|
||||||
|
|
||||||
final class Coordinator: UICollectionViewController {
|
final class Coordinator: UICollectionViewController {
|
||||||
var hoarder: EmojiHoarder
|
var hoarder: EmojiHoarder
|
||||||
var items: [String]
|
var pack: EmojiPack
|
||||||
var columns: Int?
|
var width: CGFloat
|
||||||
|
var spacing: CGFloat
|
||||||
var layout = UICollectionViewFlowLayout()
|
var layout = UICollectionViewFlowLayout()
|
||||||
|
|
||||||
init(hoarder: EmojiHoarder, items: [String], columns: Int?) {
|
init(hoarder: EmojiHoarder, pack: EmojiPack, width: CGFloat, spacing: CGFloat) {
|
||||||
self.hoarder = hoarder
|
self.hoarder = hoarder
|
||||||
self.items = items
|
self.pack = pack
|
||||||
self.columns = columns
|
self.width = width
|
||||||
|
self.spacing = spacing
|
||||||
|
|
||||||
if columns != nil {
|
layout.sectionInset.left = 16
|
||||||
layout.itemSize = CGSize(
|
layout.sectionInset.right = 16
|
||||||
width: UIScreen.main.bounds.width/CGFloat(columns!),
|
|
||||||
height: UIScreen.main.bounds.width/CGFloat(columns!)
|
layout.itemSize = CGSize(width: width, height: width)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
super.init(collectionViewLayout: layout)
|
super.init(collectionViewLayout: layout)
|
||||||
}
|
}
|
||||||
@@ -57,8 +57,15 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
fatalError("init(coder:) has not been implemented")
|
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 {
|
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 {
|
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||||
@@ -66,7 +73,7 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
|
|
||||||
guard !hoarder.trie.dict.isEmpty else { return cell }
|
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 }
|
guard let emoji = hoarder.trie.dict[emojiName] else { return cell }
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import SwiftUI
|
|||||||
|
|
||||||
class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
||||||
let spinner = UIActivityIndicatorView()
|
let spinner = UIActivityIndicatorView()
|
||||||
|
var hostingController: UIHostingController<StickerPreview>?
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
@@ -37,7 +38,12 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
|||||||
|
|
||||||
func configure(with: EmojiHoarder, emoji: Emoji) {
|
func configure(with: EmojiHoarder, emoji: Emoji) {
|
||||||
let swiftUIView = StickerPreview(sticker: emoji)
|
let swiftUIView = StickerPreview(sticker: emoji)
|
||||||
|
|
||||||
|
if let hostingController {
|
||||||
|
hostingController.rootView = swiftUIView
|
||||||
|
} else {
|
||||||
let hostingController = UIHostingController(rootView: swiftUIView)
|
let hostingController = UIHostingController(rootView: swiftUIView)
|
||||||
|
self.hostingController = hostingController
|
||||||
self.contentView.addSubview(hostingController.view)
|
self.contentView.addSubview(hostingController.view)
|
||||||
|
|
||||||
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
|
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
@@ -48,13 +54,16 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
|||||||
hostingController.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
hostingController.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func prepareForReuse() {
|
override func prepareForReuse() {
|
||||||
super.prepareForReuse()
|
super.prepareForReuse()
|
||||||
|
|
||||||
spinner.removeFromSuperview()
|
hostingController?.view.removeFromSuperview()
|
||||||
|
hostingController = nil
|
||||||
if spinner.superview == nil {
|
if spinner.superview == nil {
|
||||||
configureSkeleton()
|
configureSkeleton()
|
||||||
}
|
}
|
||||||
|
spinner.startAnimating()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||