From ccadff053e67fd4ead37ce9da6ecc06a6f2179ab Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 20 Nov 2025 20:19:13 +0000 Subject: [PATCH] using wkwebview - i dont like how it turned out... takes a second to load and has a white bg :( --- StickerSlack.xcodeproj/project.pbxproj | 8 ++++ StickerSlack/Emoji/GifView.swift | 33 ++++++++++++++ StickerSlack/SwiftUI/Emoji/EmojiPreview.swift | 43 ++++++++++--------- StickerSlack/SwiftUI/Emoji/EmojiRow.swift | 1 - 4 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 StickerSlack/Emoji/GifView.swift diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 1e4647e..bbaa64d 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -37,6 +37,9 @@ A957C17A2ECE542D00EA3EE9 /* GifManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C1792ECE542D00EA3EE9 /* GifManager.swift */; }; A957C17B2ECE542D00EA3EE9 /* GifManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C1792ECE542D00EA3EE9 /* GifManager.swift */; }; A957C17C2ECE542D00EA3EE9 /* GifManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C1792ECE542D00EA3EE9 /* GifManager.swift */; }; + A957C17E2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; }; + A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; }; + A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; }; A9773C2F2EA54AF000F3B753 /* EmojiPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* EmojiPreview.swift */; }; A986A6AE2EB658DF00B6E0FA /* Messages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A969D6932EA3E86500399C05 /* Messages.framework */; }; A986A6BA2EB658E100B6E0FA /* StickerSlackiMessageApp.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -121,6 +124,7 @@ A957C1732ECCE2CE00EA3EE9 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; A957C1762ECD008E00EA3EE9 /* Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = ""; }; A957C1792ECE542D00EA3EE9 /* GifManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifManager.swift; sourceTree = ""; }; + A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = ""; }; A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; }; A9773C2E2EA54AF000F3B753 /* EmojiPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPreview.swift; sourceTree = ""; }; A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = StickerSlackiMessageApp.appex; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -290,6 +294,7 @@ A91C098B2EBBD78700210C34 /* Categorisation */, A91C098A2EBBD77B00210C34 /* API */, A957C1792ECE542D00EA3EE9 /* GifManager.swift */, + A957C17D2ECFAA1100EA3EE9 /* GifView.swift */, ); path = Emoji; sourceTree = ""; @@ -477,6 +482,7 @@ A949B1F52EA04E8200215164 /* StickerSlackApp.swift in Sources */, A9104C802EB4022500D160EA /* MSSticker.swift in Sources */, A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */, + A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */, A957C1742ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */, A9EB72392EB93FDB00658CEB /* EmojiCollectionView.swift in Sources */, A955B3EE2EC22C4A00E1732D /* DownloadedView.swift in Sources */, @@ -505,6 +511,7 @@ A9EB724B2EB94A5700658CEB /* Trie.swift in Sources */, A986A6CD2EB659E000B6E0FA /* MessagesViewController.swift in Sources */, A986A6CE2EB659E000B6E0FA /* StickerBrowserDataSource.swift in Sources */, + A957C17E2ECFAA1100EA3EE9 /* GifView.swift in Sources */, A9BBC5192EB8FA4500FFE82F /* ViewModifiers.swift in Sources */, A986A6C42EB6598500B6E0FA /* SlackResponse.swift in Sources */, A986A6C22EB6597600B6E0FA /* Emoji.swift in Sources */, @@ -533,6 +540,7 @@ A957C1782ECD008E00EA3EE9 /* Bundle.swift in Sources */, A9B9A82E2EB2CCBE004C9245 /* StickerSlackTests.swift in Sources */, A9B9A8312EB2CD14004C9245 /* FilterCategory.swift in Sources */, + A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */, A9EB72502EB94FAD00658CEB /* EmojiPreview.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/StickerSlack/Emoji/GifView.swift b/StickerSlack/Emoji/GifView.swift new file mode 100644 index 0000000..99160e5 --- /dev/null +++ b/StickerSlack/Emoji/GifView.swift @@ -0,0 +1,33 @@ +// +// GifView.swift +// StickerSlack +// +// Created by neon443 on 20/11/2025. +// + +import Foundation +import UIKit +import SwiftUI +import WebKit + +struct GifView: UIViewRepresentable { + private let url: URL + + init(url: URL) { + self.url = url + } + + func makeUIView(context: Context) -> WKWebView { + let webview = WKWebView() + + webview.allowsLinkPreview = false + webview.allowsBackForwardNavigationGestures = false + + webview.load(URLRequest(url: url)) + return webview + } + + func updateUIView(_ uiView: WKWebView, context: Context) { + uiView.reload() + } +} diff --git a/StickerSlack/SwiftUI/Emoji/EmojiPreview.swift b/StickerSlack/SwiftUI/Emoji/EmojiPreview.swift index 02961bb..20a08d4 100644 --- a/StickerSlack/SwiftUI/Emoji/EmojiPreview.swift +++ b/StickerSlack/SwiftUI/Emoji/EmojiPreview.swift @@ -22,14 +22,15 @@ struct EmojiPreview: View { Group { if let image = emoji.image { if emoji.localImageURLString.contains(".gif") { - if let gifImage { - gifImage - .resizable().scaledToFit() - } else { - Text("uhhhh") - .foregroundStyle(.red) - .font(.largeTitle) - } + GifView(url: emoji.localImageURL) +// if let gifImage { +// gifImage +// .resizable().scaledToFit() +// } else { +// Text("uhhhh") +// .foregroundStyle(.red) +// .font(.largeTitle) +// } } else { Image(uiImage: image) .resizable().scaledToFit() @@ -57,19 +58,19 @@ struct EmojiPreview: View { } } } - .onAppear { - guard emoji.localImageURLString.contains(".gif") else { return } - gifImage = nil - guard let gifData = try? Data(contentsOf: emoji.localImageURL) as CFData else { return } - CGAnimateImageDataWithBlock(gifData, nil) { index, cgImage, stop in - if stopPointer != stop { - stopPointer?.pointee.toggle() - stopPointer = stop - } - guard !stop.pointee else { return } - gifImage = Image(uiImage: .init(cgImage: cgImage)) - } - } +// .onAppear { +// guard emoji.localImageURLString.contains(".gif") else { return } +// gifImage = nil +// guard let gifData = try? Data(contentsOf: emoji.localImageURL) as CFData else { return } +// CGAnimateImageDataWithBlock(gifData, nil) { index, cgImage, stop in +// if stopPointer != stop { +// stopPointer?.pointee.toggle() +// stopPointer = stop +// } +// guard !stop.pointee else { return } +// gifImage = Image(uiImage: .init(cgImage: cgImage)) +// } +// } .id(id) } } diff --git a/StickerSlack/SwiftUI/Emoji/EmojiRow.swift b/StickerSlack/SwiftUI/Emoji/EmojiRow.swift index 6856d68..bcffdcb 100644 --- a/StickerSlack/SwiftUI/Emoji/EmojiRow.swift +++ b/StickerSlack/SwiftUI/Emoji/EmojiRow.swift @@ -16,7 +16,6 @@ struct EmojiRow: View { HStack { VStack { HStack(spacing: .zero) { -// Text Text(emoji.name) } EmojiPreview(hoarder: hoarder, emoji: emoji)