makleso6 / NukeWebP

MIT License
16 stars 10 forks source link

Animated Webp Image #3

Open tanlucvo opened 2 years ago

makleso6 commented 2 years ago

Hi! I will check soon

tanlucvo commented 2 years ago

I try with this image https://ibb.co/bBjrHtG

tanlucvo commented 2 years ago

Hi! I will check soon

Thank you

makleso6 commented 2 years ago

@tanlucvo show how u use Nuke and NukeWebP to download and show image

makleso6 commented 2 years ago

Does it work with simple gif?

makleso6 commented 2 years ago

wait for related task https://github.com/kean/Nuke/pull/615

tanlucvo commented 2 years ago

@tanlucvo show how u use Nuke and NukeWebP to download and show image

Yupp, here is my code. It seem not working with GIF

import UIKit
import Nuke

class ViewController: UIViewController {

    override func viewDidLoad() {

        super.viewDidLoad()
        WebPImageDecoder.enable(closure: {
          var options = WebPDecoderOptions()
          options.useThreads = true
          return AdvancedWebPDecoder(options: options)
        })
        let view = AsyncImageView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        self.view.addSubview(view)
    }
}

final class AsyncImageView: UIImageView, ImageTaskDelegate {
    private var imageTask: ImageTask?
    private var pipeline: ImagePipeline = ImagePipeline {
        $0.dataCache = try? DataCache(name: "com.myapp.datacache")
        $0.dataCachePolicy = .automatic
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        Task{
           try? await loadImage()
        }

    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    func loadImage() async throws {
        self.image = try await pipeline.image(for: URL(string: "https://i.ibb.co/7SPsJNB/usagyuuun-tang-dong-8.gif")!, delegate: self).image
    }

    func imageTaskCreated(_ task: ImageTask) {
        self.imageTask = task
    }
}