mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 05:19:13 +00:00
okayokay fixed the gifs being too fast
giffrom url uses an async task to grab data it can kidna stop animating when spam switching views, other than that its fine yay ts a tomorrow problem
This commit is contained in:
@@ -10,11 +10,8 @@ import UIKit
|
||||
|
||||
class GifManager {
|
||||
static let defaultDuration: Double = 0.083333333333333329
|
||||
static func gifFrom(url: URL) -> [(frame: CGImage, showFor: Double)] {
|
||||
// let url = URL(string: "https://emoji.slack-edge.com/T0266FRGM/yay-bounce/046cfcc7ed81030f.gif")!
|
||||
// guard let source = CGImageSourceCreateWithURL(url as CFURL, nil) else { fatalError("couldnt create source") }
|
||||
|
||||
guard let data = try? Data(contentsOf: url) else { return [] }
|
||||
static func gifFrom(url: URL) async -> [(frame: CGImage, showFor: Double)] {
|
||||
guard let (data, _) = try? await URLSession.shared.data(from: url) else { return [] }
|
||||
|
||||
return gifFrom(data: data)
|
||||
}
|
||||
|
||||
@@ -37,8 +37,14 @@ struct GifView: View {
|
||||
go.toggle()
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
self.gif = GifManager.gifFrom(url: url)
|
||||
.onTapGesture {
|
||||
go.toggle()
|
||||
}
|
||||
.task {
|
||||
self.gif = await GifManager.gifFrom(url: url)
|
||||
guard gif.count > 0 else {
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+gif[0].showFor) {
|
||||
go.toggle()
|
||||
}
|
||||
|
||||
@@ -13,44 +13,13 @@ struct EmojiPreview: View {
|
||||
@State var emoji: Emoji
|
||||
|
||||
@State var gifImage: Image?
|
||||
@State var stopPointer: UnsafeMutablePointer<Bool>?
|
||||
|
||||
@State private var id: UUID = UUID()
|
||||
@State private var delay: TimeInterval = 0
|
||||
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if let image = emoji.image {
|
||||
if emoji.localImageURLString.contains(".gif") {
|
||||
GifView(url: emoji.localImageURL)
|
||||
} else {
|
||||
Image(uiImage: image)
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
} else {
|
||||
AsyncImage(url: emoji.remoteImageURL) { phase in
|
||||
if let image = phase.image {
|
||||
image
|
||||
.resizable().scaledToFit()
|
||||
} else if phase.error != nil {
|
||||
ImageErrorView()
|
||||
.onTapGesture {
|
||||
id = UUID()
|
||||
}
|
||||
.onAppear {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+delay) {
|
||||
id = UUID()
|
||||
delay+=0.1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ProgressView()
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
if let image = emoji.image {
|
||||
GifView(url: emoji.localImageURL)
|
||||
} else {
|
||||
GifView(url: emoji.remoteImageURL)
|
||||
}
|
||||
.id(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user