diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index a75a024..21f6a18 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -153,6 +153,8 @@ A9EC46AE2F6D9E5800E066E6 /* StickerType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9BE30EB2F5AFE1E00A57668 /* StickerType.swift */; }; A9F7B3802F8951210071F198 /* EmojiPackImporterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9F7B37F2F8951210071F198 /* EmojiPackImporterView.swift */; }; A9F7B3812F8951210071F198 /* EmojiPackImporterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9F7B37F2F8951210071F198 /* EmojiPackImporterView.swift */; }; + A9FB3EE32FA7AB3A00030E2A /* UIKitGifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */; }; + A9FB3EE42FA7AB3A00030E2A /* UIKitGifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -258,6 +260,7 @@ 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 = ""; }; + A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitGifView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -366,6 +369,7 @@ A94F3E632F9E384D00FA6995 /* TableView */, A94F3E642F9E385300FA6995 /* CollectionView */, A9C52F712F89A85F00078588 /* ShareSheet.swift */, + A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */, ); path = UIKit; sourceTree = ""; @@ -696,6 +700,7 @@ files = ( A949B1F42EA04E8200215164 /* ContentView.swift in Sources */, A9CD6C382EDDE37500B7F421 /* EmojiPackManager.swift in Sources */, + A9FB3EE42FA7AB3A00030E2A /* UIKitGifView.swift in Sources */, A949B1F52EA04E8200215164 /* StickerSlackApp.swift in Sources */, A9A7A4452F68360900BB84C6 /* Pagination.swift in Sources */, A9104C802EB4022500D160EA /* MSSticker.swift in Sources */, @@ -815,6 +820,7 @@ A9EC46AD2F6D9E4600E066E6 /* Hoarder.swift in Sources */, A9A7A4682F6AA17C00BB84C6 /* Int.swift in Sources */, A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */, + A9FB3EE32FA7AB3A00030E2A /* UIKitGifView.swift in Sources */, A9C52F7A2F89BB0800078588 /* EmojiTableViewCell.swift in Sources */, A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */, A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */, diff --git a/StickerSlack/Emoji/EmojiHoarder.swift b/StickerSlack/Emoji/EmojiHoarder.swift index bbdea4e..f2736d3 100644 --- a/StickerSlack/Emoji/EmojiHoarder.swift +++ b/StickerSlack/Emoji/EmojiHoarder.swift @@ -209,6 +209,7 @@ class EmojiHoarder: BaseHoarder { override nonisolated func download(emoji: (any StickerProtocol)?, skipStoreIndex: Bool = false) async { guard let emoji else { return } + guard !downloadedStickers.contains(emoji.name) else { return } await super.download(emoji: emoji, skipStoreIndex: skipStoreIndex) await MainActor.run { diff --git a/StickerSlack/Emoji/GifView.swift b/StickerSlack/Emoji/GifView.swift index 2d31e01..6a4bbb7 100644 --- a/StickerSlack/Emoji/GifView.swift +++ b/StickerSlack/Emoji/GifView.swift @@ -11,6 +11,7 @@ import SwiftUI import WebKit struct GifView: View { + @State var sticker: StickerProtocol? @State var url: URL @State var gif: [(frame: CGImage, showFor: Double)] = [] @State var currentI: Int = 0 @@ -18,22 +19,24 @@ struct GifView: View { @State var timer: Timer? - nonisolated func run() async { - guard await url.pathExtension == "gif" else { - if let data = try? await URLSession.shared.data(from: url).0, - let uiImage = UIImage(data: data), - let cgImage = uiImage.cgImage { - withAnimation(.spring) { - self.gif = [(cgImage, 1)] + func run() async { + guard url.pathExtension == "gif" else { + Task.detached { + if let data = try? await URLSession.shared.data(from: url).0, + let uiImage = UIImage(data: data), + let cgImage = uiImage.cgImage { + withAnimation(.spring(duration: 0.2)) { + self.gif = [(cgImage, 1)] + } } } return } do { - if await gif.isEmpty { + if gif.isEmpty { let frames = try await GifManager.gifFrom(url: url) - withAnimation(.spring) { + withAnimation(.spring(duration: 0.2)) { self.gif = frames } } @@ -43,8 +46,8 @@ struct GifView: View { print("falied loading or empty gif") return } - if await timer != nil { - await timer!.invalidate() + if timer != nil { + timer!.invalidate() timer = nil } @@ -55,7 +58,7 @@ struct GifView: View { currentI += 1 } } - await RunLoop.main.add(timer!, forMode: .common) + RunLoop.main.add(timer!, forMode: .common) } var body: some View { @@ -65,15 +68,13 @@ struct GifView: View { ProgressView() .modifier(fadeIn()) } else if url.pathExtension == "gif" { - TimelineView(.animation) { tl in - if currentI < gif.count { - Image(uiImage: .init(cgImage: gif[currentI].frame)) - .resizable().scaledToFit() - } - } - .onDisappear { - timer?.invalidate() - timer = nil + if currentI < gif.count { + Image(uiImage: .init(cgImage: gif[currentI].frame)) + .resizable().scaledToFit() + .onDisappear { + timer?.invalidate() + timer = nil + } } } else { if let frame = gif.first { diff --git a/StickerSlack/Stickers/Sticker.swift b/StickerSlack/Stickers/Sticker.swift index 48f3d44..f93decb 100644 --- a/StickerSlack/Stickers/Sticker.swift +++ b/StickerSlack/Stickers/Sticker.swift @@ -38,6 +38,10 @@ extension StickerProtocol { return try? MSSticker(contentsOfFileURL: localImageURL, localizedDescription: name) } + var isLocal: Bool { + return FileManager.default.fileExists(atPath: localImageURLString) + } + var image: UIImage? { if FileManager.default.fileExists(atPath: localImageURLString), let data = try? Data(contentsOf: localImageURL), diff --git a/StickerSlack/SwiftUI/Shared/StickerPreview.swift b/StickerSlack/SwiftUI/Shared/StickerPreview.swift index d8331e4..5246c00 100644 --- a/StickerSlack/SwiftUI/Shared/StickerPreview.swift +++ b/StickerSlack/SwiftUI/Shared/StickerPreview.swift @@ -13,7 +13,7 @@ struct StickerPreview: View { @State var gifImage: Image? var body: some View { - if sticker.image != nil { + if sticker.isLocal { //local GifView(url: sticker.localImageURL) } else { diff --git a/StickerSlack/UIKit/UIKitGifView.swift b/StickerSlack/UIKit/UIKitGifView.swift new file mode 100644 index 0000000..416f567 --- /dev/null +++ b/StickerSlack/UIKit/UIKitGifView.swift @@ -0,0 +1,20 @@ +// +// UIKitGifView.swift +// StickerSlack +// +// Created by neon443 on 03/05/2026. +// + +import Foundation +import UIKit + +class UIKitGifView: UIImageView { + override init(image: UIImage?) { +// <#code#> + super.init(image: image) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +}