mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
might have fixed the hitches on downloadedview
This commit is contained in:
6 files changed
+54
-22
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||