Go to file
Gordan Glavaš 89af6b7e04
Merge pull request #1 from metinn/main
Fix fps drops from image processing work on main thread
2023-01-27 08:37:59 +01:00
.swiftpm/xcode/package.xcworkspace v.1.0.0 2021-08-16 18:18:24 +02:00
Images v.1.0.0 2021-08-16 18:18:24 +02:00
Sources/SwiftUIGIF use DispatchQueue to support iOS 13&14 2023-01-11 18:22:02 +01:00
.gitignore Initial commit 2021-08-16 18:07:21 +02:00
LICENSE Initial commit 2021-08-16 18:07:21 +02:00
Package.swift v.1.0.0 2021-08-16 18:18:24 +02:00
README.md v.1.0.0 2021-08-16 18:18:24 +02:00

README.md

SwiftUI GIF

Lightweight SwiftUI component for rendering GIFs from data or assets, with no external dependencies. As a bonus, there's an extension that loads GIFs into UIImages, as well as a UIKIt-compatible UIGIFImage class.

Preview

Installation

This component is distributed as a Swift package.

Sample usage

import SwiftUIGIF

struct GIFImageTest: 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()
    }
}

Recipe

For a more detailed description of the code, visit this recipe. Check out SwiftUIRecipes.com for more SwiftUI recipes!