SwiftUI show gif image

Pub Date: 2023-07-30

https://gitlink.org.cn/dnrops/swiftui-gif.git
import SwiftUIGIF
struct GIFImageShow: View {
@State private var imageData: Data? = nil

var body: some View {
VStack {
GIFImage(name: "preview") // load from assets
.frame(height: 300)
if let data = imageData {
GIFImage(data: data) // load from data
.frame(width: 300)
} else {
Text("Loading...")
.onAppear(perform: loadData)
}
}
}

private func loadData() {
let task = URLSession.shared.dataTask(with: URL(string: "https://github.com/globulus/swiftui-webview/raw/main/Images/preview_macos.gif?raw=true")!) { data, response, error in
imageData = data
}
task.resume()
}
}