Skip to content
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Animated Webp Image #3

Open
tanlucvo opened this issue Oct 19, 2022 · 7 comments
Open

Animated Webp Image #3

tanlucvo opened this issue Oct 19, 2022 · 7 comments

Comments

@tanlucvo
Copy link

tanlucvo commented Oct 19, 2022

No description provided.

@makleso6
Copy link
Owner

Hi! I will check soon

@tanlucvo
Copy link
Author

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

@tanlucvo
Copy link
Author

Hi! I will check soon

Thank you

@makleso6
Copy link
Owner

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

@makleso6
Copy link
Owner

Does it work with simple gif?

@makleso6
Copy link
Owner

wait for related task
kean/Nuke#615

@tanlucvo
Copy link
Author

tanlucvo commented Oct 22, 2022

@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
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants