mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
redid search in uikit
This commit is contained in:
7 files changed
+109
-12
No files matched your search
@@ -162,6 +162,8 @@
|
|||||||
A9E8C7A32FF7B815009A38B5 /* EmojiPackDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */; };
|
A9E8C7A32FF7B815009A38B5 /* EmojiPackDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */; };
|
||||||
A9E8C7A52FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */; };
|
A9E8C7A52FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */; };
|
||||||
A9E8C7A62FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */; };
|
A9E8C7A62FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */; };
|
||||||
|
A9E8C7A82FF95FEC009A38B5 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7A72FF95FEC009A38B5 /* SearchViewController.swift */; };
|
||||||
|
A9E8C7A92FF95FEC009A38B5 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7A72FF95FEC009A38B5 /* SearchViewController.swift */; };
|
||||||
A9EB72392EB93FDB00658CEB /* EmojiTableViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */; };
|
A9EB72392EB93FDB00658CEB /* EmojiTableViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */; };
|
||||||
A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* StickerRow.swift */; };
|
A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* StickerRow.swift */; };
|
||||||
A9EB72492EB948C400658CEB /* StickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* StickerRow.swift */; };
|
A9EB72492EB948C400658CEB /* StickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* StickerRow.swift */; };
|
||||||
@@ -286,6 +288,7 @@
|
|||||||
A9E8C79D2FF726D4009A38B5 /* EmojiHoarder.LetterStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiHoarder.LetterStats.swift; sourceTree = "<group>"; };
|
A9E8C79D2FF726D4009A38B5 /* EmojiHoarder.LetterStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiHoarder.LetterStats.swift; sourceTree = "<group>"; };
|
||||||
A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackDetailViewController.swift; sourceTree = "<group>"; };
|
A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackDetailViewController.swift; sourceTree = "<group>"; };
|
||||||
A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackDetailViewRepresentable.swift; sourceTree = "<group>"; };
|
A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackDetailViewRepresentable.swift; sourceTree = "<group>"; };
|
||||||
|
A9E8C7A72FF95FEC009A38B5 /* SearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = "<group>"; };
|
||||||
A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiTableViewRepresentable.swift; sourceTree = "<group>"; };
|
A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiTableViewRepresentable.swift; sourceTree = "<group>"; };
|
||||||
A9EB72462EB948C400658CEB /* StickerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerRow.swift; sourceTree = "<group>"; };
|
A9EB72462EB948C400658CEB /* StickerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerRow.swift; sourceTree = "<group>"; };
|
||||||
A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrieTestingView.swift; sourceTree = "<group>"; };
|
A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrieTestingView.swift; sourceTree = "<group>"; };
|
||||||
@@ -406,6 +409,7 @@
|
|||||||
A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */,
|
A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */,
|
||||||
A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */,
|
A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */,
|
||||||
A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */,
|
A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */,
|
||||||
|
A9E8C7A72FF95FEC009A38B5 /* SearchViewController.swift */,
|
||||||
);
|
);
|
||||||
path = UIKit;
|
path = UIKit;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -802,6 +806,7 @@
|
|||||||
A9BE30EC2F5AFE1E00A57668 /* StickerType.swift in Sources */,
|
A9BE30EC2F5AFE1E00A57668 /* StickerType.swift in Sources */,
|
||||||
A9A7A4482F68361200BB84C6 /* Meta.swift in Sources */,
|
A9A7A4482F68361200BB84C6 /* Meta.swift in Sources */,
|
||||||
A995D95C2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */,
|
A995D95C2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */,
|
||||||
|
A9E8C7A92FF95FEC009A38B5 /* SearchViewController.swift in Sources */,
|
||||||
A9BE30FE2F5FA47100A57668 /* Hoarder.swift in Sources */,
|
A9BE30FE2F5FA47100A57668 /* Hoarder.swift in Sources */,
|
||||||
A97322A32FA7B9C8004B657D /* JumboMoji.swift in Sources */,
|
A97322A32FA7B9C8004B657D /* JumboMoji.swift in Sources */,
|
||||||
A97BFFBF2F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */,
|
A97BFFBF2F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */,
|
||||||
@@ -889,6 +894,7 @@
|
|||||||
A9C52F7A2F89BB0800078588 /* EmojiTableViewCell.swift in Sources */,
|
A9C52F7A2F89BB0800078588 /* EmojiTableViewCell.swift in Sources */,
|
||||||
A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */,
|
A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */,
|
||||||
A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */,
|
A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */,
|
||||||
|
A9E8C7A82FF95FEC009A38B5 /* SearchViewController.swift in Sources */,
|
||||||
A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */,
|
A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */,
|
||||||
A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */,
|
A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */,
|
||||||
A9E8C7902FF71D8C009A38B5 /* DownloadedViewController.swift in Sources */,
|
A9E8C7902FF71D8C009A38B5 /* DownloadedViewController.swift in Sources */,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import SwiftUI
|
|||||||
|
|
||||||
struct EmptyCollectionView: View {
|
struct EmptyCollectionView: View {
|
||||||
@State var title: String
|
@State var title: String
|
||||||
@State var details: String
|
@State var details: String?
|
||||||
@State var systemImage: String
|
@State var systemImage: String
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -24,10 +24,10 @@ struct EmptyCollectionView: View {
|
|||||||
.bold()
|
.bold()
|
||||||
.font(.title3)
|
.font(.title3)
|
||||||
}
|
}
|
||||||
if !details.isEmpty {
|
if details != nil {
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
Text(details)
|
Text(details!)
|
||||||
.multilineTextAlignment(.center)
|
.multilineTextAlignment(.center)
|
||||||
.foregroundStyle(.gray)
|
.foregroundStyle(.gray)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ struct SearchView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
if searchTerm.isEmpty {
|
if searchTerm.isEmpty {
|
||||||
EmptyCollectionView(title: "Start a Search", details: "", systemImage: "magnifyingglass")
|
EmptyCollectionView(title: "Start a Search", details: nil, systemImage: "magnifyingglass")
|
||||||
.frame(maxHeight: 100)
|
.frame(maxHeight: 100)
|
||||||
Spacer()
|
Spacer()
|
||||||
} else if searchResult.isEmpty {
|
} else if searchResult.isEmpty {
|
||||||
|
|||||||
@@ -44,8 +44,12 @@ class Trie: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nonisolated func allNames() -> [String] {
|
||||||
|
return Array(self.dict.keys)
|
||||||
|
}
|
||||||
|
|
||||||
nonisolated func search(for query: String, previousQuery: String?, previousResult: Set<String>?) -> [String] {
|
nonisolated func search(for query: String, previousQuery: String?, previousResult: Set<String>?) -> [String] {
|
||||||
guard !query.isEmpty else { return [] }
|
guard !query.isEmpty else { return allNames() }
|
||||||
var result: Set<String> = wordlist
|
var result: Set<String> = wordlist
|
||||||
if let previousQuery,
|
if let previousQuery,
|
||||||
let previousResult,
|
let previousResult,
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
//
|
||||||
|
// SearchViewController.swift
|
||||||
|
// StickerSlack
|
||||||
|
//
|
||||||
|
// Created by neon443 on 04/07/2026.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import UIKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
class SearchViewController: UINavigationController, UISearchControllerDelegate, UISearchResultsUpdating, UISearchBarDelegate {
|
||||||
|
var emojiHoarder: EmojiHoarder
|
||||||
|
|
||||||
|
var resultsTable: EmojiTableView
|
||||||
|
var searchController: UISearchController
|
||||||
|
var previousQueries: [String] = []
|
||||||
|
|
||||||
|
init(emojiHoarder: EmojiHoarder) {
|
||||||
|
self.emojiHoarder = emojiHoarder
|
||||||
|
self.resultsTable = EmojiTableView(hoarder: emojiHoarder, items: emojiHoarder.trie.allNames())
|
||||||
|
self.searchController = UISearchController(searchResultsController: nil)
|
||||||
|
|
||||||
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
setViewControllers([resultsTable], animated: true)
|
||||||
|
|
||||||
|
resultsTable.navigationItem.title = "Search"
|
||||||
|
|
||||||
|
searchController.delegate = self
|
||||||
|
searchController.searchResultsUpdater = self
|
||||||
|
|
||||||
|
searchController.searchBar.autocapitalizationType = .none
|
||||||
|
searchController.searchBar.delegate = self
|
||||||
|
searchController.hidesNavigationBarDuringPresentation = false
|
||||||
|
resultsTable.navigationItem.hidesSearchBarWhenScrolling = false
|
||||||
|
|
||||||
|
resultsTable.navigationItem.searchController = searchController
|
||||||
|
resultsTable.navigationItem.hidesBackButton = false
|
||||||
|
definesPresentationContext = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateSearchResults(for searchController: UISearchController) {
|
||||||
|
guard let text = searchController.searchBar.text else { return }
|
||||||
|
guard !text.isEmpty else { return }
|
||||||
|
|
||||||
|
let previousQuery: String?
|
||||||
|
if previousQueries.count > 1 {
|
||||||
|
previousQuery = previousQueries[previousQueries.count-2]
|
||||||
|
} else { previousQuery = nil }
|
||||||
|
|
||||||
|
let results = emojiHoarder.trie.search(
|
||||||
|
for: text,
|
||||||
|
previousQuery: previousQuery,
|
||||||
|
previousResult: Set(resultsTable.items)
|
||||||
|
)
|
||||||
|
|
||||||
|
resultsTable.refreshUI(with: results)
|
||||||
|
}
|
||||||
|
|
||||||
|
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
|
||||||
|
guard !searchText.isEmpty else {
|
||||||
|
previousQueries = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
previousQueries.append(searchText)
|
||||||
|
print(previousQueries)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,14 +24,16 @@ final class TabbedContentView: UITabBarController {
|
|||||||
let downloaded = DownloadedViewController(emojiHoarder: emojiHoarder)
|
let downloaded = DownloadedViewController(emojiHoarder: emojiHoarder)
|
||||||
downloaded.tabBarItem = UITabBarItem(title: "Saved", image: UIImage(systemName: "arrow.down.circle.fill"), tag: 2)
|
downloaded.tabBarItem = UITabBarItem(title: "Saved", image: UIImage(systemName: "arrow.down.circle.fill"), tag: 2)
|
||||||
|
|
||||||
|
// let searchView = SearchView(hoarder: emojiHoarder)
|
||||||
|
// let search = UIHostingController(rootView: searchView)
|
||||||
|
let search = SearchViewController(emojiHoarder: emojiHoarder)
|
||||||
|
search.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 3)
|
||||||
|
|
||||||
|
|
||||||
let settingsView = SettingsView(hoarder: emojiHoarder)
|
let settingsView = SettingsView(hoarder: emojiHoarder)
|
||||||
let settings = UIHostingController(rootView: settingsView)
|
let settings = UIHostingController(rootView: settingsView)
|
||||||
settings.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(systemName: "gear"), tag: 3)
|
settings.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(systemName: "gear"), tag: 4)
|
||||||
|
|
||||||
let searchView = SearchView(hoarder: emojiHoarder)
|
self.setViewControllers([browse, packs, downloaded, search, settings], animated: false)
|
||||||
let search = UIHostingController(rootView: searchView)
|
|
||||||
search.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 4)
|
|
||||||
|
|
||||||
self.setViewControllers([browse, packs, downloaded, settings, search], animated: false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,10 +35,18 @@ final class EmojiTableView: UITableViewController {
|
|||||||
self.items = newItems
|
self.items = newItems
|
||||||
Task.detached {
|
Task.detached {
|
||||||
//if its being cleared or removign 10k+
|
//if its being cleared or removign 10k+
|
||||||
guard !itemsAfter.isEmpty && itemsBefore.count-itemsAfter.count < 10_000 else {
|
if itemsAfter.isEmpty {
|
||||||
await self.instantApplySnapshot()
|
await self.instantApplySnapshot()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if itemsAfter.count > 10_000 {
|
||||||
|
await self.instantApplySnapshot()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// guard !itemsAfter.isEmpty && itemsBefore.count-itemsAfter.count < 10_000 else {
|
||||||
|
// await self.instantApplySnapshot()
|
||||||
|
// return
|
||||||
|
// }
|
||||||
await self.applySnapshot(animated: true)
|
await self.applySnapshot(animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||