animations in emojirow

animated deleting/downloading emojis
stopped it glitching when downloading/deleting an emoji
removed refresh() and uiID cos its not necessary sob
moved downloadImage() to stickerprotocol extension
bundled an image so test emoji loading is faster
This commit is contained in:
neon443
2026-03-08 22:38:14 +00:00
parent 7d83ae2101
commit ccaaa8e519
10 changed files with 77 additions and 65 deletions

View File

@@ -13,7 +13,6 @@ import UniformTypeIdentifiers
struct Emoji: StickerProtocol {
var id: UUID
var uiID: UUID
var name: String
var localImageURLString: String {
let urlString = remoteImageURL.absoluteString
@@ -32,7 +31,6 @@ struct Emoji: StickerProtocol {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(UUID.self, forKey: .id)
self.uiID = id
self.name = try container.decode(String.self, forKey: .name)
self.remoteImageURL = try container.decode(URL.self, forKey: .remoteImageURL)
}
@@ -43,37 +41,12 @@ struct Emoji: StickerProtocol {
id: UUID = UUID()
) {
self.id = id
self.uiID = id
self.name = name
self.remoteImageURL = url
}
nonisolated
func downloadImage() async throws {
if let data = try? await Data(contentsOf: localImageURL),
let _ = UIImage(data: data) {
return
}
var (data, _) = try await URLSession.shared.data(from: remoteImageURL)
if let uiImage = UIImage(data: data),
let cgImage = uiImage.cgImage,
await !self.localImageURLString.contains(".gif"),
cgImage.width < 300 || cgImage.height < 300 {
data = await resize(image: uiImage, to: CGSize(width: 300, height: 300)).pngData()!
}
try! await data.write(to: localImageURL)
return
}
@MainActor
mutating func refresh() {
withAnimation { self.uiID = UUID() }
}
static var test: Emoji = Emoji(
name: "s?",
url: URL(string: "https://files.catbox.moe/d8go4n.png")!
name: "a test slack emoji",
url: Bundle.main.url(forResource: "image", withExtension: "png")!
)
}

View File

@@ -37,7 +37,7 @@ class EmojiHoarder: ObservableObject {
self.showWelcome = !UserDefaults.standard.bool(forKey: "showWelcome")
let localDB = loadLocalDB()
withAnimation { self.emojis = localDB }
withAnimation(.snappy) { self.emojis = localDB }
loadTrie()
if !skipIndex { buildTrie() }
@@ -204,7 +204,7 @@ class EmojiHoarder: ObservableObject {
private func loadRemoteDB() async {
async let fetched = self.fetchRemoteDB()
if let fetched = await fetched {
withAnimation { self.emojis = fetched }
withAnimation(.snappy) { self.emojis = fetched }
}
}
@@ -232,7 +232,7 @@ class EmojiHoarder: ObservableObject {
return
}
await MainActor.run {
withAnimation { self.emojis = fetched }
withAnimation(.snappy) { self.emojis = fetched }
buildTrie()
}
}
@@ -241,11 +241,12 @@ class EmojiHoarder: ObservableObject {
try? await emoji.downloadImage()
await MainActor.run {
if !skipStoreIndex {
self.downloadedEmojis.insert(emoji.name)
self.downloadedEmojisArr.append(emoji.name)
withAnimation(.snappy) {
self.downloadedEmojis.insert(emoji.name)
self.downloadedEmojisArr.append(emoji.name)
}
self.storeDownloadedIndexes()
}
self.trie.dict[emoji.name]?.refresh()
if !skipStoreIndex { Haptic.success.trigger() }
}
}
@@ -254,11 +255,12 @@ class EmojiHoarder: ObservableObject {
func delete(emoji: Emoji, skipStoreIndex: Bool = false) {
emoji.deleteImage()
if !skipStoreIndex {
downloadedEmojis.remove(emoji.name)
downloadedEmojisArr.removeAll(where: { $0 == emoji.name })
withAnimation(.snappy) {
downloadedEmojis.remove(emoji.name)
downloadedEmojisArr.removeAll(where: { $0 == emoji.name })
}
storeDownloadedIndexes()
}
self.trie.dict[emoji.name]?.refresh()
if !skipStoreIndex { Haptic.heavy.trigger() }
}