Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS/AppKit support? #206

Open
nilekell opened this issue Jun 12, 2024 · 1 comment
Open

MacOS/AppKit support? #206

nilekell opened this issue Jun 12, 2024 · 1 comment

Comments

@nilekell
Copy link

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
Copy link

Kinark commented Jul 7, 2024

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

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

No branches or pull requests

2 participants