might have fixed the hitches on downloadedview

This commit is contained in:
neon443 committed 2026-05-03 17:46:59 +01:00
1 parent ba09d82aec
commit 0294e4b60b
6 files changed
+54 -22

No files matched your search

+1
View File
@@ -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 {
+22 -21
View File
@@ -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 {
+4
View File
@@ -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),
@@ -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 {
+20
View File
@@ -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")
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.