diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index b596196..969e324 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -70,6 +70,8 @@ A986A6CE2EB659E000B6E0FA /* StickerBrowserDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = A986A6CB2EB659E000B6E0FA /* StickerBrowserDataSource.swift */; }; A986A6CF2EB659E000B6E0FA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A986A6C62EB659E000B6E0FA /* Assets.xcassets */; }; 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 */; }; 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 */; }; @@ -146,10 +148,10 @@ A9CD6C3B2EDDE6B500B7F421 /* EmojiPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D15B892EB1142C00404792 /* EmojiPack.swift */; }; A9D15B8B2EB1142C00404792 /* EmojiPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D15B892EB1142C00404792 /* EmojiPack.swift */; }; A9D6A8212F7014AE00F198FB /* TestStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = A995D95A2F6EBBDD0043E5F5 /* TestStructures.swift */; }; - A9EB72392EB93FDB00658CEB /* EmojiTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72382EB93FDB00658CEB /* EmojiTableView.swift */; }; + A9EB72392EB93FDB00658CEB /* EmojiTableViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */; }; A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* StickerRow.swift */; }; A9EB72492EB948C400658CEB /* StickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* StickerRow.swift */; }; - A9EB724A2EB948E000658CEB /* EmojiTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72382EB93FDB00658CEB /* EmojiTableView.swift */; }; + A9EB724A2EB948E000658CEB /* EmojiTableViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */; }; A9EB724B2EB94A5700658CEB /* Trie.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C172DB2EB8C9AC008A7885 /* Trie.swift */; }; A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */; }; A9EB724F2EB94A6B00658CEB /* TrieTestingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */; }; @@ -233,6 +235,7 @@ A986A6C82EB659E000B6E0FA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; @@ -263,7 +266,7 @@ A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackManager.swift; sourceTree = ""; }; A9D15B892EB1142C00404792 /* EmojiPack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPack.swift; sourceTree = ""; }; A9E2ECD72EB74CE00038B2D6 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; }; - A9EB72382EB93FDB00658CEB /* EmojiTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiTableView.swift; sourceTree = ""; }; + A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiTableViewRepresentable.swift; sourceTree = ""; }; A9EB72462EB948C400658CEB /* StickerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerRow.swift; sourceTree = ""; }; A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrieTestingView.swift; sourceTree = ""; }; A9F7B37F2F8951210071F198 /* EmojiPackImporterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackImporterView.swift; sourceTree = ""; }; @@ -442,8 +445,9 @@ A94F3E632F9E384D00FA6995 /* TableView */ = { isa = PBXGroup; children = ( - A9EB72382EB93FDB00658CEB /* EmojiTableView.swift */, + A98FA65A2FF3B29700D50212 /* EmojiTableView.swift */, A9C52F782F89BB0800078588 /* EmojiTableViewCell.swift */, + A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */, ); path = TableView; sourceTree = ""; @@ -713,6 +717,7 @@ A949B1F52EA04E8200215164 /* StickerSlackApp.swift in Sources */, A9A7A4452F68360900BB84C6 /* Pagination.swift in Sources */, A9104C802EB4022500D160EA /* MSSticker.swift in Sources */, + A98FA65C2FF3B29700D50212 /* EmojiTableView.swift in Sources */, A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */, A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */, A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */, @@ -722,7 +727,7 @@ A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */, A957C1742ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */, A9A7A44B2F6837A800BB84C6 /* GiphyUser.swift in Sources */, - A9EB72392EB93FDB00658CEB /* EmojiTableView.swift in Sources */, + A9EB72392EB93FDB00658CEB /* EmojiTableViewRepresentable.swift in Sources */, A955B3EE2EC22C4A00E1732D /* DownloadedView.swift in Sources */, A949B1FB2EA0518800215164 /* SlackResponse.swift in Sources */, A957C17A2ECE542D00EA3EE9 /* GifManager.swift in Sources */, @@ -824,7 +829,7 @@ A9CD6C3B2EDDE6B500B7F421 /* EmojiPack.swift in Sources */, A9BE30EF2F5B004800A57668 /* GifHoarder.swift in Sources */, A9A7A4492F68361200BB84C6 /* Meta.swift in Sources */, - A9EB724A2EB948E000658CEB /* EmojiTableView.swift in Sources */, + A9EB724A2EB948E000658CEB /* EmojiTableViewRepresentable.swift in Sources */, A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */, A9BBC51A2EB8FA4500FFE82F /* ViewModifiers.swift in Sources */, A995D95B2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */, @@ -833,6 +838,7 @@ A9A7A4682F6AA17C00BB84C6 /* Int.swift in Sources */, A97322A22FA7B9C8004B657D /* JumboMoji.swift in Sources */, A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */, + A98FA65B2FF3B29700D50212 /* EmojiTableView.swift in Sources */, A9FB3EE32FA7AB3A00030E2A /* UIKitGifView.swift in Sources */, A9C52F7A2F89BB0800078588 /* EmojiTableViewCell.swift in Sources */, A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */, diff --git a/StickerSlack/StickerSlackApp.swift b/StickerSlack/StickerSlackApp.swift index 8252dbc..eb9614a 100644 --- a/StickerSlack/StickerSlackApp.swift +++ b/StickerSlack/StickerSlackApp.swift @@ -7,26 +7,38 @@ import SwiftUI +//@main +//struct StickerSlackApp: App { +// @ObservedObject var emojiHoarder: EmojiHoarder = EmojiHoarder() +// @ObservedObject var gifhoarder: GifHoarder = GifHoarder() +// +// @State var importingEmojiPack: Bool = false +// @State var pack: EmojiPack = .new() +// +// var body: some Scene { +// WindowGroup { +// ContentView(emojiHoarder: emojiHoarder, gifhoarder: gifhoarder) +// .onOpenURL { url in +// if let imported = EmojiPack(fromShareLink: url) { +// importingEmojiPack = true +// pack = imported +// } +// } +// .sheet(isPresented: $importingEmojiPack) { +// EmojiPackImporterView(emojiHoarder: emojiHoarder, pack: $pack) +// } +// } +// } +//} + @main -struct StickerSlackApp: App { - @ObservedObject var emojiHoarder: EmojiHoarder = EmojiHoarder() - @ObservedObject var gifhoarder: GifHoarder = GifHoarder() +class AirAPApp: UIResponder, UIApplicationDelegate { + var window: UIWindow? - @State var importingEmojiPack: Bool = false - @State var pack: EmojiPack = .new() - - var body: some Scene { - WindowGroup { - ContentView(emojiHoarder: emojiHoarder, gifhoarder: gifhoarder) - .onOpenURL { url in - if let imported = EmojiPack(fromShareLink: url) { - importingEmojiPack = true - pack = imported - } - } - .sheet(isPresented: $importingEmojiPack) { - EmojiPackImporterView(emojiHoarder: emojiHoarder, pack: $pack) - } - } + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { + window = UIWindow(frame: UIScreen.main.bounds) + window?.rootViewController = TabbedContentView() + window?.makeKeyAndVisible() + return true } } diff --git a/StickerSlack/SwiftUI/BrowseView.swift b/StickerSlack/SwiftUI/BrowseView.swift index d54970b..021860d 100644 --- a/StickerSlack/SwiftUI/BrowseView.swift +++ b/StickerSlack/SwiftUI/BrowseView.swift @@ -25,7 +25,7 @@ struct BrowseView: View { Group { switch browseWhat { case .slackEmoji: - EmojiTableView( + EmojiTableViewRepresentable( hoarder: emojiHoarder, items: emojiHoarder.emojis.map { $0.name } ) diff --git a/StickerSlack/SwiftUI/ContentView.swift b/StickerSlack/SwiftUI/ContentView.swift index 98ae4aa..f0a88e1 100644 --- a/StickerSlack/SwiftUI/ContentView.swift +++ b/StickerSlack/SwiftUI/ContentView.swift @@ -45,17 +45,10 @@ struct ContentView: View { Tab(value: AppTab.search, role: .search) { NavigationStack { - SearchView(hoarder: emojiHoarder, searchTerm: $searchTerm) + SearchView(hoarder: emojiHoarder) } } } -// .tabViewBottomAccessorySafe() { -// HStack { -// Image(systemName: "magnifyingglass") -// TextField("", text: $searchTerm, prompt: Text("Search")) -// } -// .padding(.horizontal) -// } } else { TabView(selection: $tabSelection) { BrowseView(emojiHoarder: emojiHoarder, gifHoarder: gifhoarder) @@ -79,7 +72,7 @@ struct ContentView: View { Label("Setings", systemImage: "gear") } NavigationView2 { - SearchView(hoarder: emojiHoarder, searchTerm: $searchTerm) + SearchView(hoarder: emojiHoarder) } .tag(AppTab.search) .tabItem { diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift index b388670..200245b 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift @@ -12,8 +12,6 @@ struct EmojiPackDetailView: View { @ObservedObject var hoarder: EmojiHoarder @Binding var pack: EmojiPack - @State var searchTerm: String = "" - @State var edit: Bool = false @State var editName: Bool = false @State var editDescription: Bool = false @@ -111,7 +109,6 @@ struct EmojiPackDetailView: View { NavigationView2 { SearchView( hoarder: hoarder, - searchTerm: $searchTerm, fromPackEditor: true, callback: { pack.add($0) diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackGridView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackGridView.swift index e2a2b6a..e232706 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackGridView.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackGridView.swift @@ -15,7 +15,6 @@ struct EmojiPackGridView: View { @State var initDate: Date = .now @State var showAdder: Bool = false - @State var searchTerm: String = "" @State var showNotFoundAlert: Bool = false @@ -109,7 +108,7 @@ struct EmojiPackGridView: View { } .sheet(isPresented: $showAdder) { NavigationView2 { - SearchView(hoarder: hoarder, searchTerm: $searchTerm, fromPackEditor: true) { selection in + SearchView(hoarder: hoarder, fromPackEditor: true) { selection in withAnimation(.spring) { pack.add(selection) } diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift index 6023203..833f6f8 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift @@ -29,6 +29,12 @@ struct EmojiPackManager: View { 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 { @@ -41,12 +47,6 @@ struct EmojiPackManager: View { ShareSheet(activityItems: [pack.shareLink()]) } } - Button { - hoarder.removeEmojiPack(pack) - } label: { - Label("Delete", systemImage: "trash") - } - .tint(.red) } } } diff --git a/StickerSlack/SwiftUI/SearchView.swift b/StickerSlack/SwiftUI/SearchView.swift index b2447e1..4008614 100644 --- a/StickerSlack/SwiftUI/SearchView.swift +++ b/StickerSlack/SwiftUI/SearchView.swift @@ -12,7 +12,7 @@ struct SearchView: View { @FocusState private var searchFocused: Bool @State private var currentSearch: Task? - @Binding var searchTerm: String + @State var searchTerm: String = "" @State var previousSearches: [String] = [] @State var searchResult: [String] = [] @@ -69,7 +69,7 @@ struct SearchView: View { switch stickerType { case .slackEmoji: Text("\(searchResult.count)") - EmojiTableView(hoarder: hoarder, items: searchResult) + EmojiTableViewRepresentable(hoarder: hoarder, items: searchResult) .padding(.bottom, 10) case .giphyGifs: Text("uhh") @@ -100,7 +100,6 @@ struct SearchView: View { SearchView( hoarder: EmojiHoarder(localOnly: true), - searchTerm: $searchTerm, fromPackEditor: true ) { print($0) diff --git a/StickerSlack/Trie/TrieTestingView.swift b/StickerSlack/Trie/TrieTestingView.swift index c55766e..56cbcd4 100644 --- a/StickerSlack/Trie/TrieTestingView.swift +++ b/StickerSlack/Trie/TrieTestingView.swift @@ -116,7 +116,7 @@ struct TrieTestingView: View { } if uikit { - EmojiTableView(hoarder: hoarder, items: searchResults) + EmojiTableViewRepresentable(hoarder: hoarder, items: searchResults) .animation(.snappy, value: searchResults) } else { List(searchResults, id: \.self) { item in diff --git a/StickerSlack/UIKit/TabbedContentView.swift b/StickerSlack/UIKit/TabbedContentView.swift index 09dbfb7..0242ccd 100644 --- a/StickerSlack/UIKit/TabbedContentView.swift +++ b/StickerSlack/UIKit/TabbedContentView.swift @@ -12,6 +12,18 @@ import SwiftUI final class TabbedContentView: UITabBarController { override func viewDidLoad() { super.viewDidLoad() + + self.edgesForExtendedLayout = .bottom + self.extendedLayoutIncludesOpaqueBars = false + + if #available(iOS 26, *) { + let appearance = UITabBarAppearance() + appearance.configureWithDefaultBackground() + tabBar.standardAppearance = appearance + tabBar.scrollEdgeAppearance = appearance + } else { + self.tabBarController?.tabBar.isTranslucent = false + } setupTabs() } @@ -19,30 +31,27 @@ final class TabbedContentView: UITabBarController { let emojiHoarder = EmojiHoarder() let gifHoarder = GifHoarder() - let browseView = BrowseView(emojiHoarder: emojiHoarder, gifHoarder: gifHoarder) - let browse = UIHostingController(rootView: browseView) - browse.tabBarItem = UITabBarItem(title: "Home", image: UIImage(systemName: "house"), tag: 0) + let browseView = EmojiTableView(hoarder: emojiHoarder, items: emojiHoarder.emojis.map { $0.name }) + let browse = UINavigationController(rootViewController: browseView) + browseView.navigationItem.title = "Browse" + browse.tabBarItem = UITabBarItem(title: "Browse", image: UIImage(systemName: "square.grid.2x2.fill"), tag: 0) let packsView = EmojiPackManager(hoarder: emojiHoarder) let packs = UIHostingController(rootView: packsView) - packs.tabBarItem = UITabBarItem(title: "Packs", image: UIImage(systemName: "house"), tag: 1) + 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) - downloaded.tabBarItem = UITabBarItem(title: "Downloaded", image: UIImage(systemName: "house"), tag: 2) + 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: "Home", image: UIImage(systemName: "house"), tag: 3) + settings.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(systemName: "gear"), tag: 3) - self.setViewControllers([browse], animated: true) - selectedIndex = 0 + let searchView = SearchView(hoarder: emojiHoarder) + let search = UIHostingController(rootView: searchView) + search.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 4) + self.setViewControllers([browse, packs, downloaded, settings, search], animated: false) } } - -@available(iOS 17, *) -#Preview { - let view2 = TabbedContentView() - return view2.view -} diff --git a/StickerSlack/UIKit/TableView/EmojiTableView.swift b/StickerSlack/UIKit/TableView/EmojiTableView.swift index 4ad599e..0a8ec06 100644 --- a/StickerSlack/UIKit/TableView/EmojiTableView.swift +++ b/StickerSlack/UIKit/TableView/EmojiTableView.swift @@ -2,125 +2,108 @@ // EmojiTableView.swift // StickerSlack // -// Created by neon443 on 03/11/2025. +// Created by neon443 on 30/06/2026. // import Foundation import UIKit -import SwiftUI -import Haptics -struct EmojiTableView: UIViewRepresentable { - let hoarder: EmojiHoarder - let items: [String] +final class EmojiTableView: UITableViewController { + var dataSource: UITableViewDiffableDataSource! + var hoarder: EmojiHoarder + var items: [String] - func makeUIView(context: Context) -> UITableView { - let tableView = context.coordinator as UITableViewController - tableView.tableView.register(EmojiTableViewCell.self, forCellReuseIdentifier: "cell") - return tableView.tableView + init(hoarder: EmojiHoarder, items: [String]) { + self.hoarder = hoarder + self.items = items + super.init(style: .plain) + self.dataSource = UITableViewDiffableDataSource(tableView: tableView) { (tableView: UITableView, indexPath: IndexPath, itemIdentifier: String) -> UITableViewCell? in + return self.cell(tableView, indexPath: indexPath, forItemIdentifier: itemIdentifier) + } + tableView.dataSource = dataSource + tableView.register(EmojiTableViewCell.self, forCellReuseIdentifier: "cell") + self.refreshUI(with: items) } - func updateUIView(_ uiView: UITableView, context: Context) { - context.coordinator.hoarder = hoarder - - let itemsBefore = context.coordinator.items - let itemsAfter = items - context.coordinator.items = items + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func refreshUI(with newItems: [String]) { + let itemsBefore = self.items + let itemsAfter = newItems + self.items = newItems Task.detached { //if its being cleared or removign 10k+ guard !itemsAfter.isEmpty && itemsBefore.count-itemsAfter.count < 10_000 else { - await context.coordinator.instantApplySnapshot() + await self.instantApplySnapshot() return } - await context.coordinator.applySnapshot(animated: true) + await self.applySnapshot(animated: true) } } - func makeCoordinator() -> Coordinator { - Coordinator(hoarder: hoarder, items: items) + 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.tableView.dataSource as! UITableViewDiffableDataSource).apply(snapshot, animatingDifferences: animated) + } + func instantApplySnapshot() async { + let snapshot = makeSnapshot() + await (self.tableView.dataSource as! UITableViewDiffableDataSource).applySnapshotUsingReloadData(snapshot) } - final class Coordinator: UITableViewController { - var dataSource: UITableViewDiffableDataSource! - var hoarder: EmojiHoarder - var items: [String] + func cell( + _ tableView: UITableView, + indexPath: IndexPath, + forItemIdentifier itemIdentifier: String + ) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EmojiTableViewCell + cell.selectionStyle = .none - init(hoarder: EmojiHoarder, items: [String]) { - self.hoarder = hoarder - self.items = items - super.init(style: .plain) - self.dataSource = UITableViewDiffableDataSource(tableView: tableView) { (tableView: UITableView, indexPath: IndexPath, itemIdentifier: String) -> UITableViewCell? in - return self.cell(tableView, indexPath: indexPath, forItemIdentifier: itemIdentifier) - } - tableView.dataSource = dataSource - } + guard !hoarder.trie.dict.isEmpty else { return cell } - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } + guard let emoji = hoarder.trie.dict[itemIdentifier] else { return cell } - 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.tableView.dataSource as! UITableViewDiffableDataSource).apply(snapshot, animatingDifferences: animated) - } - func instantApplySnapshot() async { - let snapshot = makeSnapshot() - await (self.tableView.dataSource as! UITableViewDiffableDataSource).applySnapshotUsingReloadData(snapshot) + cell.configure(with: hoarder, emoji: emoji) + return cell + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return items.count + } + + override func viewDidLoad() { + super.viewDidLoad() + let refreshControl = UIRefreshControl() + refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged) + if #available(iOS 10, *) { + tableView.refreshControl = refreshControl + } else { + tableView.backgroundView = refreshControl } + } + + @objc func refresh(_ refreshControl: UIRefreshControl) { + hoarder.startLoading(localOnly: false, skipIndex: false) + refreshControl.endRefreshing() - func cell( - _ tableView: UITableView, - indexPath: IndexPath, - forItemIdentifier itemIdentifier: String - ) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EmojiTableViewCell - cell.selectionStyle = .none - - guard !hoarder.trie.dict.isEmpty else { return cell } - - guard let emoji = hoarder.trie.dict[itemIdentifier] else { return cell } - - cell.configure(with: hoarder, emoji: emoji) - return cell - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return items.count - } - - override func viewDidLoad() { - super.viewDidLoad() - let refreshControl = UIRefreshControl() - refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged) - if #available(iOS 10, *) { - tableView.refreshControl = refreshControl - } else { - tableView.backgroundView = refreshControl - } - } - - @objc func refresh(_ refreshControl: UIRefreshControl) { - hoarder.startLoading(localOnly: false, skipIndex: false) - refreshControl.endRefreshing() - - } - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { // <#code#> - } - - override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) { + } + + override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) { // <#code#> - } - - override func tableView(_ tableView: UITableView, shouldBeginMultipleSelectionInteractionAt indexPath: IndexPath) -> Bool { - return true - } + } + + override func tableView(_ tableView: UITableView, shouldBeginMultipleSelectionInteractionAt indexPath: IndexPath) -> Bool { + return true } } diff --git a/StickerSlack/UIKit/TableView/EmojiTableViewRepresentable.swift b/StickerSlack/UIKit/TableView/EmojiTableViewRepresentable.swift new file mode 100644 index 0000000..f88268b --- /dev/null +++ b/StickerSlack/UIKit/TableView/EmojiTableViewRepresentable.swift @@ -0,0 +1,30 @@ +// +// EmojiTableView.swift +// StickerSlack +// +// Created by neon443 on 03/11/2025. +// + +import Foundation +import UIKit +import SwiftUI +import Haptics + +struct EmojiTableViewRepresentable: UIViewRepresentable { + let hoarder: EmojiHoarder + let items: [String] + + func makeUIView(context: Context) -> UITableView { + let tableView = context.coordinator as UITableViewController + return tableView.tableView + } + + func updateUIView(_ uiView: UITableView, context: Context) { + context.coordinator.hoarder = hoarder + context.coordinator.refreshUI(with: items) + } + + func makeCoordinator() -> EmojiTableView { + return EmojiTableView(hoarder: hoarder, items: items) + } +}