diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 969e324..5f5dd71 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -14,8 +14,8 @@ A9104C7C2EB3AE6300D160EA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A949B1EF2EA04E8200215164 /* Assets.xcassets */; }; A9104C7F2EB4022500D160EA /* MSSticker.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9104C7D2EB4022500D160EA /* MSSticker.swift */; }; A9104C802EB4022500D160EA /* MSSticker.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9104C7D2EB4022500D160EA /* MSSticker.swift */; }; - A917BACE2F9B787B008DB31E /* EmojiCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */; }; - A917BACF2F9B787B008DB31E /* EmojiCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */; }; + A917BACE2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A917BACD2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift */; }; + A917BACF2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A917BACD2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift */; }; A917BAD12F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */; }; A917BAD22F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */; }; A921C2DF2ED067BB00E57B1A /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A921C2DE2ED067BB00E57B1A /* WelcomeView.swift */; }; @@ -54,8 +54,6 @@ A975F9202FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */; }; A975F9212FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F91F2FA52B3600A5C62E /* AddToPackMenuView.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 */; }; A97BFFBF2F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */; }; A97BFFC02F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */; }; A97D3E7E2FA5235300BF3273 /* Haptics in Frameworks */ = {isa = PBXBuildFile; productRef = A97D3E7D2FA5235300BF3273 /* Haptics */; }; @@ -72,6 +70,8 @@ A986A6D12EB659E000B6E0FA /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A986A6C92EB659E000B6E0FA /* MainInterface.storyboard */; }; A98FA65B2FF3B29700D50212 /* EmojiTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98FA65A2FF3B29700D50212 /* EmojiTableView.swift */; }; A98FA65C2FF3B29700D50212 /* EmojiTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98FA65A2FF3B29700D50212 /* EmojiTableView.swift */; }; + A98FA6612FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98FA6602FF3BD5400D50212 /* EmojiCollectionView.swift */; }; + A98FA6622FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98FA6602FF3BD5400D50212 /* EmojiCollectionView.swift */; }; A99589AF2F5E0D83003A4A8C /* image.png in Resources */ = {isa = PBXBuildFile; fileRef = A99589AE2F5E0D83003A4A8C /* image.png */; }; A99589B02F5E0D83003A4A8C /* image.png in Resources */ = {isa = PBXBuildFile; fileRef = A99589AE2F5E0D83003A4A8C /* image.png */; }; A99589B12F5E0D83003A4A8C /* image.png in Resources */ = {isa = PBXBuildFile; fileRef = A99589AE2F5E0D83003A4A8C /* image.png */; }; @@ -199,7 +199,7 @@ A9104C722EB3AE4700D160EA /* Icon.pxd */ = {isa = PBXFileReference; lastKnownFileType = file; path = Icon.pxd; sourceTree = ""; }; A9104C732EB3AE4700D160EA /* StickerSlack.icon */ = {isa = PBXFileReference; lastKnownFileType = folder.iconcomposer.icon; path = StickerSlack.icon; sourceTree = ""; }; A9104C7D2EB4022500D160EA /* MSSticker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSSticker.swift; sourceTree = ""; }; - A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionView.swift; sourceTree = ""; }; + A917BACD2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewRepresentable.swift; sourceTree = ""; }; A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlainEmojiCollectionViewCell.swift; sourceTree = ""; }; A921C2DE2ED067BB00E57B1A /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = ""; }; A924C3712EA9127200F20781 /* Emoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Emoji.swift; sourceTree = ""; }; @@ -227,7 +227,6 @@ A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackGridView.swift; sourceTree = ""; }; A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToPackMenuView.swift; sourceTree = ""; }; A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = ""; }; - A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyEmojiPackView.swift; sourceTree = ""; }; A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewCell.swift; sourceTree = ""; }; 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 = ""; }; @@ -236,6 +235,7 @@ A986A6CA2EB659E000B6E0FA /* MessagesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = ""; }; A986A6CB2EB659E000B6E0FA /* StickerBrowserDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerBrowserDataSource.swift; sourceTree = ""; }; A98FA65A2FF3B29700D50212 /* EmojiTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiTableView.swift; sourceTree = ""; }; + A98FA6602FF3BD5400D50212 /* EmojiCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionView.swift; sourceTree = ""; }; A99589AE2F5E0D83003A4A8C /* image.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = image.png; sourceTree = ""; }; A995D95A2F6EBBDD0043E5F5 /* TestStructures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestStructures.swift; sourceTree = ""; }; A9A7A43E2F6835F800BB84C6 /* Trending.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Trending.swift; sourceTree = ""; }; @@ -350,7 +350,6 @@ A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */, A9F7B37F2F8951210071F198 /* EmojiPackImporterView.swift */, A9C52F6E2F89A22000078588 /* Wiggle.metal */, - A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */, A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */, ); path = EmojiPacks; @@ -446,8 +445,8 @@ isa = PBXGroup; children = ( A98FA65A2FF3B29700D50212 /* EmojiTableView.swift */, - A9C52F782F89BB0800078588 /* EmojiTableViewCell.swift */, A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */, + A9C52F782F89BB0800078588 /* EmojiTableViewCell.swift */, ); path = TableView; sourceTree = ""; @@ -455,7 +454,8 @@ A94F3E642F9E385300FA6995 /* CollectionView */ = { isa = PBXGroup; children = ( - A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */, + A98FA6602FF3BD5400D50212 /* EmojiCollectionView.swift */, + A917BACD2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift */, A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */, A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */, ); @@ -721,7 +721,6 @@ A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */, A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */, A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */, - A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */, A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */, A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */, A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */, @@ -758,7 +757,8 @@ A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */, A9BE30F02F5B004800A57668 /* GifHoarder.swift in Sources */, A9BE30F22F5B004E00A57668 /* Gif.swift in Sources */, - A917BACF2F9B787B008DB31E /* EmojiCollectionView.swift in Sources */, + A917BACF2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift in Sources */, + A98FA6612FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */, A9BE30EC2F5AFE1E00A57668 /* StickerType.swift in Sources */, A9A7A4482F68361200BB84C6 /* Meta.swift in Sources */, A995D95C2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */, @@ -845,9 +845,9 @@ A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */, A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */, A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */, - A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */, A955B3F62EC22EE900E1732D /* SearchView.swift in Sources */, A97322A52FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */, + A98FA6622FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */, A9BDEADF2F82BC93002798DF /* NoStickersView.swift in Sources */, A97BFFC02F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */, A9B9A8322EB2CD29004C9245 /* SlackResponse.swift in Sources */, @@ -855,7 +855,7 @@ A921C2E02ED067BB00E57B1A /* WelcomeView.swift in Sources */, A9B9A82E2EB2CCBE004C9245 /* StickerSlackTests.swift in Sources */, A9A7A44F2F68383900BB84C6 /* GiphyImages.swift in Sources */, - A917BACE2F9B787B008DB31E /* EmojiCollectionView.swift in Sources */, + A917BACE2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift in Sources */, A9BE30F32F5B004E00A57668 /* Gif.swift in Sources */, A9A7A44C2F6837A800BB84C6 /* GiphyUser.swift in Sources */, A9B9A8312EB2CD14004C9245 /* FilterCategory.swift in Sources */, diff --git a/StickerSlack/StickerSlackApp.swift b/StickerSlack/StickerSlackApp.swift index eb9614a..1a441b5 100644 --- a/StickerSlack/StickerSlackApp.swift +++ b/StickerSlack/StickerSlackApp.swift @@ -32,7 +32,7 @@ import SwiftUI //} @main -class AirAPApp: UIResponder, UIApplicationDelegate { +class StickerSlackApp: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { diff --git a/StickerSlack/SwiftUI/DownloadedView.swift b/StickerSlack/SwiftUI/DownloadedView.swift index 7e2a276..470cfa4 100644 --- a/StickerSlack/SwiftUI/DownloadedView.swift +++ b/StickerSlack/SwiftUI/DownloadedView.swift @@ -41,7 +41,7 @@ struct DownloadedView: View { .padding() } - EmojiCollectionView( + EmojiCollectionViewRepresentable( hoarder: emojiHoarder, items: emojiHoarder.downloadedStickersArr, width: 75, diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift index 200245b..4dc9223 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift @@ -58,7 +58,11 @@ struct EmojiPackDetailView: View { } if pack.items.isEmpty { - EmptyEmojiPackView() + EmptyCollectionView( + title: "No Emoji", + details: "Add emojis to this pack by editing it using the pencil button in the toolbar.", + systemImage: "exclamationmark.triangle.fill" + ) } if useSwiftUIGrid { @@ -68,7 +72,7 @@ struct EmojiPackDetailView: View { edit: $edit ) } else { - EmojiCollectionView( + EmojiCollectionViewRepresentable( hoarder: hoarder, items: pack.items, width: 75, diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift index 833f6f8..41dcc4a 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift @@ -14,37 +14,41 @@ struct EmojiPackManager: View { var body: some View { NavigationView2 { - List { + VStack { if hoarder.emojiPacks.isEmpty { EmptyCollectionView( title: "No Emoji Packs", details: "Create one using the button in the toolbar.", systemImage: "square.stack.3d.up.slash" ) - } - ForEach($hoarder.emojiPacks) { $pack in - NavigationLink { - EmojiPackDetailView(hoarder: hoarder, pack: $pack, useSwiftUIGrid: useSwiftUIGrid) - } label: { - Text(pack.name) - } - .swipeActions(edge: .trailing) { - Button { - hoarder.removeEmojiPack(pack) - } label: { - Label("Delete", systemImage: "trash") - } - .tint(.red) - if #available(iOS 16, *) { - ShareLink(item: pack.shareLink()) - } else { - Button { - showShareSheet.toggle() + Spacer() + } else { + List { + ForEach($hoarder.emojiPacks) { $pack in + NavigationLink { + EmojiPackDetailView(hoarder: hoarder, pack: $pack, useSwiftUIGrid: useSwiftUIGrid) } label: { - Label("Share", systemImage: "square.and.arrow.up") + Text(pack.name) } - .sheet(isPresented: $showShareSheet) { - ShareSheet(activityItems: [pack.shareLink()]) + .swipeActions(edge: .trailing) { + Button { + hoarder.removeEmojiPack(pack) + } label: { + Label("", systemImage: "trash") + } + .tint(.red) + if #available(iOS 16, *) { + ShareLink(item: pack.shareLink()) + } else { + Button { + showShareSheet.toggle() + } label: { + Label("", systemImage: "square.and.arrow.up") + } + .sheet(isPresented: $showShareSheet) { + ShareSheet(activityItems: [pack.shareLink()]) + } + } } } } diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmptyEmojiPackView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmptyEmojiPackView.swift deleted file mode 100644 index be9bbaa..0000000 --- a/StickerSlack/SwiftUI/EmojiPacks/EmptyEmojiPackView.swift +++ /dev/null @@ -1,44 +0,0 @@ -// -// 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() -} diff --git a/StickerSlack/SwiftUI/JumboMojiTestView.swift b/StickerSlack/SwiftUI/JumboMojiTestView.swift index 1f1f522..c6314e7 100644 --- a/StickerSlack/SwiftUI/JumboMojiTestView.swift +++ b/StickerSlack/SwiftUI/JumboMojiTestView.swift @@ -28,7 +28,7 @@ struct JumboMojiTestView: View { } ForEach(jumboMoji, id: \.self) { jumboMoji in HStack { - EmojiCollectionView( + EmojiCollectionViewRepresentable( hoarder: hoarder, items: jumboMoji.items, width: CGFloat(jumboMoji.width), diff --git a/StickerSlack/SwiftUI/Misc/EmptyCollectionView.swift b/StickerSlack/SwiftUI/Misc/EmptyCollectionView.swift index 3f2b8ae..7c609d6 100644 --- a/StickerSlack/SwiftUI/Misc/EmptyCollectionView.swift +++ b/StickerSlack/SwiftUI/Misc/EmptyCollectionView.swift @@ -13,29 +13,37 @@ struct EmptyCollectionView: View { @State var systemImage: String var body: some View { - ZStack { - Color.accentColor - .opacity(0.4) - .padding(.horizontal, -15) - .padding(.vertical, -15) - .blur(radius: 5) + VStack { HStack { Image(systemName: systemImage) .resizable() .scaledToFit() .frame(width: 25) + .padding(.horizontal, 5) Text(title) .bold() .font(.title3) } + HStack { + Spacer() + Text(details) + .multilineTextAlignment(.center) + .foregroundStyle(.gray) + Spacer() + } } .listRowSeparator(.hidden) - HStack { - Spacer() - Text(details) - .multilineTextAlignment(.center) - Spacer() + .transition(.scale) + .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() } } diff --git a/StickerSlack/SwiftUI/SearchView.swift b/StickerSlack/SwiftUI/SearchView.swift index 4008614..a271dc7 100644 --- a/StickerSlack/SwiftUI/SearchView.swift +++ b/StickerSlack/SwiftUI/SearchView.swift @@ -57,20 +57,55 @@ struct SearchView: View { var body: some View { VStack { - if fromPackEditor { - EmojiCollectionView( + if searchTerm.isEmpty { + EmptyCollectionView(title: "Search", details: "", systemImage: "magnifyingglass") + .frame(maxHeight: 100) + .padding() + Spacer() + } else if searchResult.isEmpty { + EmptyCollectionView(title: "No Results", details: "Try a new search", systemImage: "exclamationmark.magnifyingglass") + .frame(maxHeight: 100) + .padding() + Spacer() + } else if fromPackEditor { + EmojiCollectionViewRepresentable( hoarder: hoarder, items: searchResult, width: 75, style: .plainWithLabel, onTapCallback: { callback($0) }) + } else { + EmojiTableViewRepresentable(hoarder: hoarder, items: searchResult) + } + + if fromPackEditor { + if searchResult.isEmpty { + EmptyCollectionView(title: "No Results", details: "Try a new search", systemImage: "exclamationmark.magnifyingglass") + .frame(maxHeight: 100) + .padding() + Spacer() + } else { + EmojiCollectionViewRepresentable( + hoarder: hoarder, + items: searchResult, + width: 75, + style: .plainWithLabel, + onTapCallback: { callback($0) + }) + } } else { switch stickerType { case .slackEmoji: Text("\(searchResult.count)") - EmojiTableViewRepresentable(hoarder: hoarder, items: searchResult) - .padding(.bottom, 10) + if searchResult.isEmpty { + EmptyCollectionView(title: "No Results", details: "Try a new search", systemImage: "exclamationmark.magnifyingglass") + .frame(maxHeight: 100) + .padding() + Spacer() + } else { + EmojiTableViewRepresentable(hoarder: hoarder, items: searchResult) + } case .giphyGifs: Text("uhh") } diff --git a/StickerSlack/SwiftUI/SettingsView.swift b/StickerSlack/SwiftUI/SettingsView.swift index 76a9b44..934f3f1 100644 --- a/StickerSlack/SwiftUI/SettingsView.swift +++ b/StickerSlack/SwiftUI/SettingsView.swift @@ -118,7 +118,7 @@ struct SettingsView: View { Label("jumbomoji search", systemImage: "text.page.badge.magnifyingglass") } NavigationLink { - EmojiCollectionView( + EmojiCollectionViewRepresentable( hoarder: hoarder, items: [ "btn-3kh0-1", @@ -147,7 +147,7 @@ struct SettingsView: View { Label("jumbomoji", systemImage: "square.split.2x2") } NavigationLink { - EmojiCollectionView( + EmojiCollectionViewRepresentable( hoarder: hoarder, items: hoarder.emojis.prefix(10000).map { $0.name }, width: 10, diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index 390cab1..30f3d2c 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -7,68 +7,59 @@ import Foundation import UIKit -import SwiftUI import Haptics -struct EmojiCollectionView: UIViewRepresentable { - let hoarder: EmojiHoarder - let items: [String] - let width: CGFloat - let style: EmojiCollectionView.Style - var edit: Bool? - var onRemoveSUI: ((String) -> Void)? - var onTapCallback: ((String) -> Void)? +final class EmojiCollectionView: UICollectionViewController, UICollectionViewDelegateFlowLayout { + var hoarder: EmojiHoarder + var items: [String] + var width: CGFloat + var style: EmojiCollectionView.Style + var edit: Bool? = false + var onRemove: ((String) -> Void)? + var onTap: ((String) -> Void)? - func makeUIView(context: Context) -> UICollectionView { - let collectionView = context.coordinator as UICollectionViewController - collectionView.collectionView.register(PlainEmojiCollectionViewCell.self, forCellWithReuseIdentifier: "plain") - collectionView.collectionView.register(EmojiCollectionViewCell.self, forCellWithReuseIdentifier: "full") - collectionView.collectionView.delegate = context.coordinator - return collectionView.collectionView - } + var dataSource: UICollectionViewDiffableDataSource! - func updateUIView(_ uiView: UICollectionView, context: Context) { - context.coordinator.hoarder = hoarder - context.coordinator.onRemove = onRemoveSUI - context.coordinator.onTap = onTapCallback + // [width: [label: height]] + static var labelSizeDict: [CGFloat: [String: CGFloat]] = [:] + + let initDate = Date.now + var layout = UICollectionViewFlowLayout() + var displayLink: CADisplayLink! + + init( + hoarder: EmojiHoarder, + items: [String], + width: CGFloat, + style: EmojiCollectionView.Style, + ) { + self.hoarder = hoarder + self.items = items + self.width = width + self.style = style - context.coordinator.edit = edit - if edit ?? false { - context.coordinator.startAnimating() + super.init(collectionViewLayout: layout) + + self.dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in + self.collectionView(collectionView, cellForItemAt: indexPath) + } + collectionView.dataSource = dataSource + + if self.style == .jumboMoji { + self.layout.minimumInteritemSpacing = 0 + self.layout.minimumLineSpacing = 0 + collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) } else { - context.coordinator.stopAnimating() + self.layout.minimumInteritemSpacing = 8 + collectionView.contentInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) } + layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize - for cell in uiView.visibleCells { - if let cell = cell as? EmojiCollectionViewCell { - cell.setEdit(to: edit) - } - } - -// if items != context.coordinator.items { -// context.coordinator.items = items -// uiView.reloadData() -// } - let itemsBefore = context.coordinator.items - let itemsAfter = items - context.coordinator.items = items - Task.detached { - //if its being cleared or adding 10k+ - guard !itemsAfter.isEmpty && itemsAfter.count-itemsBefore.count < 10_000 else { - await context.coordinator.instantApplySnapshot() - return - } - await context.coordinator.applySnapshot(animated: true) - } + refreshUI(edit: false, with: items) } - func makeCoordinator() -> Coordinator { - Coordinator( - hoarder: hoarder, - items: items, - width: width, - style: style - ) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") } enum Style { @@ -79,197 +70,176 @@ struct EmojiCollectionView: UIViewRepresentable { case jumboMoji } - final class Coordinator: UICollectionViewController, UICollectionViewDelegateFlowLayout { - var hoarder: EmojiHoarder - var items: [String] - var width: CGFloat - var style: EmojiCollectionView.Style - var edit: Bool? = false - var onRemove: ((String) -> Void)? - var onTap: ((String) -> Void)? - - var dataSource: UICollectionViewDiffableDataSource! - - // [width: [label: height]] - static var labelSizeDict: [CGFloat: [String: CGFloat]] = [:] - - let initDate = Date.now - var layout = UICollectionViewFlowLayout() - var displayLink: CADisplayLink! - - init( - hoarder: EmojiHoarder, - items: [String], - width: CGFloat, - style: EmojiCollectionView.Style, - ) { - self.hoarder = hoarder - self.items = items - self.width = width - self.style = style - - super.init(collectionViewLayout: layout) - - self.dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in - self.collectionView(collectionView, cellForItemAt: indexPath) - } - collectionView.dataSource = dataSource - - if self.style == .jumboMoji { - self.layout.minimumInteritemSpacing = 0 - self.layout.minimumLineSpacing = 0 - collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) - } else { - self.layout.minimumInteritemSpacing = 8 - collectionView.contentInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) - } - layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize + override func viewWillLayoutSubviews() { + self.refreshUI(edit: edit, with: items) + } + + func refreshUI(edit: Bool?, with items: [String]) { + self.edit = edit + if edit ?? false { + self.startAnimating() + } else { + self.stopAnimating() } - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func makeSnapshot() -> NSDiffableDataSourceSnapshot { - var snapshot = NSDiffableDataSourceSnapshot() - snapshot.appendSections([0]) - snapshot.appendItems(items, toSection: 0) - return snapshot - } - func applySnapshot(animated: Bool) async { - let snapshot = makeSnapshot() - await (self.collectionView.dataSource as! UICollectionViewDiffableDataSource).apply(snapshot, animatingDifferences: animated) - } - func instantApplySnapshot() async { - let snapshot = makeSnapshot() - await (self.collectionView.dataSource as! UICollectionViewDiffableDataSource).applySnapshotUsingReloadData(snapshot) - } - - override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return items.count - } - - override func collectionView( - _ collectionView: UICollectionView, - cellForItemAt indexPath: IndexPath - ) -> UICollectionViewCell { - let cell: PlainEmojiCollectionViewCell - guard !hoarder.trie.dict.isEmpty else { return UICollectionViewCell() } - let emojiName = items[indexPath.item] - - switch style { - case .plain, .plainWithMenu, .jumboMoji: - cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell - case .full, .plainWithLabel: - cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell - (cell as! EmojiCollectionViewCell).setEdit(to: edit) - (cell as! EmojiCollectionViewCell).onRemove = { - guard let index = self.items.firstIndex(of: $0) else { return } - self.items.remove(at: index) - Task.detached { - await self.applySnapshot(animated: true) - } - self.onRemove?($0) - } - } - guard let emoji = hoarder.trie.dict[emojiName] else { return cell } - cell.width = width - cell.style = style - cell.onTap = { self.onTap?(emojiName) } - cell.configure(with: hoarder, emoji: emoji) - return cell - } - - func startAnimating() { - displayLink = CADisplayLink(target: self, selector: #selector(updateAnimation)) - displayLink.add(to: .main, forMode: .common) - } - func stopAnimating() { - displayLink?.remove(from: .main, forMode: .common) - displayLink?.invalidate() - UIView.animate(withDuration: 0.2) { - for cell in self.collectionView.visibleCells { - cell.transform = CGAffineTransform.identity - } - } - } - @objc - func updateAnimation() { - let t = Date().timeIntervalSince(initDate) - let angle = ((sin(t*20)*4)/360)*2*CGFloat.pi - - for cell in collectionView.visibleCells { - cell.transform = CGAffineTransform(rotationAngle: angle) + for cell in collectionView.visibleCells { + if let cell = cell as? EmojiCollectionViewCell { + cell.setEdit(to: edit) } } - override func collectionView( - _ collectionView: UICollectionView, - contextMenuConfigurationForItemAt indexPath: IndexPath, - point: CGPoint - ) -> UIContextMenuConfiguration? { - guard self.style == .plainWithMenu else { return nil } - - var menuChildrem: [UIMenuElement] = [] - let emojiName = self.items[indexPath.row] - - let packMenuItem: (EmojiHoarder, Int) -> UIAction = { hoarder, packIndex in - let pack = hoarder.emojiPacks[packIndex] - return UIAction( - title: pack.name, - subtitle: "\(pack.items.count) item\(pack.items.count.plural)", - image: pack.items.contains(emojiName) ? UIImage(systemName: "checkmark") : nil - ) { action in - hoarder.emojiPacks[packIndex].addRemove(emojiName) - hoarder.saveEmojiPacks() - } + let itemsBefore = self.items + let itemsAfter = items + self.items = items + Task.detached { + //if its being cleared or adding 10k+ + guard !itemsAfter.isEmpty && itemsAfter.count-itemsBefore.count < 10_000 else { + await self.instantApplySnapshot() + return } - var packMenuItems: [UIMenuElement] = [] - for i in self.hoarder.emojiPacks.indices { - packMenuItems.append(packMenuItem(self.hoarder, i)) - } - let createNewPackMenu = UIMenu( - options: .displayInline, - children: [ - UIAction(title: "Create New", image: UIImage(systemName: "plus")) { action in - self.hoarder.newEmojiPack(withItems: [emojiName]) - } - ] - ) - packMenuItems.append(createNewPackMenu) - menuChildrem.append(UIMenu(title: "Add to Pack", image: UIImage(systemName: "square.stack.3d.up.fill"), children: packMenuItems)) - - let copyName = UIAction(title: "Copy Name", image: UIImage(systemName: "doc.on.clipboard")) { action in - UIPasteboard.general.string = emojiName - Haptic.success.trigger() - } - let copyImage = UIAction(title: "Copy Image", image: UIImage(systemName: "photo.fill.on.rectangle.fill")) { action in - UIPasteboard.general.image = self.hoarder.trie.dict[emojiName]?.image - Haptic.success.trigger() - } - let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in - - } - menuChildrem.append(UIMenu(options: .displayInline, children: [copyName, copyImage, share])) - - let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash")) { action in - Task.detached { - await self.hoarder.delete(emoji: self.hoarder.trie.dict[emojiName]) - } - self.items.remove(at: indexPath.row) + await self.applySnapshot(animated: true) + } + } + + func makeSnapshot() -> NSDiffableDataSourceSnapshot { + var snapshot = NSDiffableDataSourceSnapshot() + snapshot.appendSections([0]) + snapshot.appendItems(items, toSection: 0) + return snapshot + } + func applySnapshot(animated: Bool) async { + let snapshot = makeSnapshot() + await (self.collectionView.dataSource as! UICollectionViewDiffableDataSource).apply(snapshot, animatingDifferences: animated) + } + func instantApplySnapshot() async { + let snapshot = makeSnapshot() + await (self.collectionView.dataSource as! UICollectionViewDiffableDataSource).applySnapshotUsingReloadData(snapshot) + } + + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return items.count + } + + override func collectionView( + _ collectionView: UICollectionView, + cellForItemAt indexPath: IndexPath + ) -> UICollectionViewCell { + let cell: PlainEmojiCollectionViewCell + guard !hoarder.trie.dict.isEmpty else { return UICollectionViewCell() } + let emojiName = items[indexPath.item] + + switch style { + case .plain, .plainWithMenu, .jumboMoji: + cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell + case .full, .plainWithLabel: + cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell + (cell as! EmojiCollectionViewCell).setEdit(to: edit) + (cell as! EmojiCollectionViewCell).onRemove = { + guard let index = self.items.firstIndex(of: $0) else { return } + self.items.remove(at: index) Task.detached { await self.applySnapshot(animated: true) } + self.onRemove?($0) + } + } + guard let emoji = hoarder.trie.dict[emojiName] else { return cell } + cell.width = width + cell.style = style + cell.onTap = { self.onTap?(emojiName) } + cell.configure(with: hoarder, emoji: emoji) + return cell + } + + func startAnimating() { + displayLink = CADisplayLink(target: self, selector: #selector(updateAnimation)) + displayLink.add(to: .main, forMode: .common) + } + func stopAnimating() { + displayLink?.remove(from: .main, forMode: .common) + displayLink?.invalidate() + UIView.animate(withDuration: 0.2) { + for cell in self.collectionView.visibleCells { + cell.transform = CGAffineTransform.identity } - delete.attributes.update(with: .destructive) - menuChildrem.append(UIMenu(options: .displayInline, children: [delete])) - - let menu = UIMenu(title: emojiName, children: menuChildrem) - return UIContextMenuConfiguration( - identifier: nil, - previewProvider: nil) { suggestedActions in - return menu - } } } + @objc + func updateAnimation() { + let t = Date().timeIntervalSince(initDate) + let angle = ((sin(t*20)*4)/360)*2*CGFloat.pi + + for cell in collectionView.visibleCells { + cell.transform = CGAffineTransform(rotationAngle: angle) + } + } + + override func collectionView( + _ collectionView: UICollectionView, + contextMenuConfigurationForItemAt indexPath: IndexPath, + point: CGPoint + ) -> UIContextMenuConfiguration? { + guard self.style == .plainWithMenu else { return nil } + + var menuChildrem: [UIMenuElement] = [] + let emojiName = self.items[indexPath.row] + + let packMenuItem: (EmojiHoarder, Int) -> UIAction = { hoarder, packIndex in + let pack = hoarder.emojiPacks[packIndex] + return UIAction( + title: pack.name, + subtitle: "\(pack.items.count) item\(pack.items.count.plural)", + image: pack.items.contains(emojiName) ? UIImage(systemName: "checkmark") : nil + ) { action in + hoarder.emojiPacks[packIndex].addRemove(emojiName) + hoarder.saveEmojiPacks() + } + } + var packMenuItems: [UIMenuElement] = [] + for i in self.hoarder.emojiPacks.indices { + packMenuItems.append(packMenuItem(self.hoarder, i)) + } + let createNewPackMenu = UIMenu( + options: .displayInline, + children: [ + UIAction(title: "Create New", image: UIImage(systemName: "plus")) { action in + self.hoarder.newEmojiPack(withItems: [emojiName]) + } + ] + ) + packMenuItems.append(createNewPackMenu) + menuChildrem.append(UIMenu(title: "Add to Pack", image: UIImage(systemName: "square.stack.3d.up.fill"), children: packMenuItems)) + + let copyName = UIAction(title: "Copy Name", image: UIImage(systemName: "doc.on.clipboard")) { action in + UIPasteboard.general.string = emojiName + Haptic.success.trigger() + } + let copyImage = UIAction(title: "Copy Image", image: UIImage(systemName: "photo.fill.on.rectangle.fill")) { action in + UIPasteboard.general.image = self.hoarder.trie.dict[emojiName]?.image + Haptic.success.trigger() + } + let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in + + } + menuChildrem.append(UIMenu(options: .displayInline, children: [copyName, copyImage, share])) + + let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash")) { action in + Task.detached { + await self.hoarder.delete(emoji: self.hoarder.trie.dict[emojiName]) + } + self.items.remove(at: indexPath.row) + Task.detached { + await self.applySnapshot(animated: true) + } + } + delete.attributes.update(with: .destructive) + menuChildrem.append(UIMenu(options: .displayInline, children: [delete])) + + let menu = UIMenu(title: emojiName, children: menuChildrem) + return UIContextMenuConfiguration( + identifier: nil, + previewProvider: nil) { suggestedActions in + return menu + } + } } diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewRepresentable.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewRepresentable.swift new file mode 100644 index 0000000..53a05f3 --- /dev/null +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewRepresentable.swift @@ -0,0 +1,48 @@ +// +// EmojiCollectionViewRepresentable.swift +// StickerSlack +// +// Created by neon443 on 30/06/2026. +// + +import Foundation +import UIKit +import SwiftUI +import Haptics + +struct EmojiCollectionViewRepresentable: UIViewRepresentable { + let hoarder: EmojiHoarder + let items: [String] + let width: CGFloat + let style: EmojiCollectionView.Style + var edit: Bool? + var onRemoveSUI: ((String) -> Void)? + var onTapCallback: ((String) -> Void)? + + func makeUIView(context: Context) -> UICollectionView { + let collectionView = context.coordinator as UICollectionViewController + collectionView.collectionView.register(PlainEmojiCollectionViewCell.self, forCellWithReuseIdentifier: "plain") + collectionView.collectionView.register(EmojiCollectionViewCell.self, forCellWithReuseIdentifier: "full") + collectionView.collectionView.delegate = context.coordinator + return collectionView.collectionView + } + + func updateUIView(_ uiView: UICollectionView, context: Context) { + context.coordinator.hoarder = hoarder + context.coordinator.items = items + context.coordinator.edit = edit + context.coordinator.onRemove = onRemoveSUI + context.coordinator.onTap = onTapCallback + uiView.setNeedsLayout() + context.coordinator.refreshUI(edit: edit, with: items) + } + + func makeCoordinator() -> EmojiCollectionView { + EmojiCollectionView( + hoarder: hoarder, + items: items, + width: width, + style: style + ) + } +} diff --git a/StickerSlack/UIKit/TabbedContentView.swift b/StickerSlack/UIKit/TabbedContentView.swift index 0242ccd..8af82f7 100644 --- a/StickerSlack/UIKit/TabbedContentView.swift +++ b/StickerSlack/UIKit/TabbedContentView.swift @@ -40,10 +40,21 @@ final class TabbedContentView: UITabBarController { let packs = UIHostingController(rootView: packsView) packs.tabBarItem = UITabBarItem(title: "Packs", image: UIImage(systemName: "square.stack.3d.up.fill"), tag: 1) - let downloadedView = DownloadedView(emojiHoarder: emojiHoarder, gifHoarder: gifHoarder) - let downloaded = UIHostingController(rootView: downloadedView) + + let downloadedView = EmojiCollectionView( + hoarder: emojiHoarder, + items: emojiHoarder.downloadedStickersArr, + width: 75, + style: .plainWithMenu + ) + let downloaded = UINavigationController(rootViewController: downloadedView) + downloadedView.navigationItem.title = "Downloaded" downloaded.tabBarItem = UITabBarItem(title: "Downloaded", image: UIImage(systemName: "arrow.down.circle.fill"), tag: 2) +// let downloadedView = DownloadedView(emojiHoarder: emojiHoarder, gifHoarder: gifHoarder) +// let downloaded = UIHostingController(rootView: downloadedView) +// downloaded.tabBarItem = UITabBarItem(title: "Downloaded", image: UIImage(systemName: "arrow.down.circle.fill"), tag: 2) + let settingsView = SettingsView(hoarder: emojiHoarder) let settings = UIHostingController(rootView: settingsView) settings.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(systemName: "gear"), tag: 3) diff --git a/StickerSlack/UIKit/TableView/EmojiTableView.swift b/StickerSlack/UIKit/TableView/EmojiTableView.swift index 0a8ec06..fb80f5a 100644 --- a/StickerSlack/UIKit/TableView/EmojiTableView.swift +++ b/StickerSlack/UIKit/TableView/EmojiTableView.swift @@ -2,7 +2,7 @@ // EmojiTableView.swift // StickerSlack // -// Created by neon443 on 30/06/2026. +// Created by neon443 on 03/11/2025. // import Foundation diff --git a/StickerSlack/UIKit/TableView/EmojiTableViewRepresentable.swift b/StickerSlack/UIKit/TableView/EmojiTableViewRepresentable.swift index f88268b..506ae75 100644 --- a/StickerSlack/UIKit/TableView/EmojiTableViewRepresentable.swift +++ b/StickerSlack/UIKit/TableView/EmojiTableViewRepresentable.swift @@ -1,8 +1,8 @@ // -// EmojiTableView.swift +// EmojiTableViewRepresentable.swift // StickerSlack // -// Created by neon443 on 03/11/2025. +// Created by neon443 on 30/06/2026. // import Foundation