alexiscreuzot / SwiftyGif

High performance GIF engine
MIT License
1.97k stars 208 forks source link

MacOS/AppKit support? #206

Open nilekell opened 1 month ago

nilekell commented 1 month ago

Does this package support MacOS/AppKit apps that use SwiftUI?

I am using the following example code and getting some errors:

struct AnimatedGifView: UIViewRepresentable {
    @Binding var url: URL

    func makeUIView(context: Context) -> UIImageView {
        let imageView = UIImageView(gifURL: self.url)
        imageView.contentMode = .scaleAspectFit
        return imageView
    }

    func updateUIView(_ uiView: UIImageView, context: Context) {
        uiView.setGifFromURL(self.url)
    }
}
/Users.../Views/AnimatedGifView.swift:12:25 Cannot find type 'UIViewRepresentable' in scope

/Users/.../Views/AnimatedGifView.swift:15:30 Cannot find type 'Context' in scope

/Users/.../Views/AnimatedGifView.swift:15:42 Cannot find type 'UIImageView' in scope

/Users/.../Views/AnimatedGifView.swift:16:25 Cannot find 'UIImageView' in scope

/Users/.../Views/AnimatedGifView.swift:17:34 Cannot infer contextual base in reference to member 'scaleAspectFit'

/Users/.../Views/AnimatedGifView.swift:21:33 Cannot find type 'UIImageView' in scope

/Users/.../Views/AnimatedGifView.swift:21:55 Cannot find type 'Context' in scope
Kinark commented 1 week ago
struct GIFViewer: NSViewRepresentable {
    @Binding var url: URL

    func makeNSView(context: Context) -> NSImageView {
        let imageView = NSImageView(gifURL: self.url)
        imageView.imageScaling = .scaleProportionallyDown
        return imageView
    }

    func updateNSView(_ imageView: NSImageView, context: Context) {
        imageView.setGifFromURL(self.url)
    }
}