-
Notifications
You must be signed in to change notification settings - Fork 36
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
Unable to render SVG image on watchOS #24
Comments
watchOS have no UIImageView. So, you can not show true vector SVG, PDF, etc on watchOS. You can only use bitmap rendering. Which means WebImage. See more about this: SDWebImage/SDWebImageSwiftUI#50. |
Download your example. Seems currently for watchOS user, you, as a user, should add the code to use bitmap rendering. Use code The framework does not have a special check for watchOS because watchOS does not support UIImageView (Though there is UIImageView in watchOS system framework, not public). |
Ah, thanks for the clarification! In some testing, I had seen that using bitmap rendering was working, but I wasn't sure exactly how to enable it. I also found that the code didn't work exactly as you have it in your comment. In case this helps anybody in the future, here is the SwiftUI code that I was able to use in order to get it working.
This didn't maintain the image aspect ratio though. In my case, I needed the aspect ratio to remain, so I found it best to just pass in the
Thank you so much! |
The CGSize.zero, should use SVG's canvas size to render the bitmap version. You means this contains bug ? |
Oh, is that not expected behavior? Yeah, that's what I'm seeing. If I specify Here's some example SwiftUI code that I've put together. It uses an SVG image that is taller than it is wide:
And here's what it looks like for me on watchOS 6.2: |
Start debugging. |
@loganrockmore Try fix at #25. Use the branch dependency to have a test. |
Seems...even I use the old version of SVGCoder, the SVG render still works well 😅 You have wrong code for You should change your code into WebImage(url: URL(string: "https://www.mlbstatic.com/team-logos/team-cap-on-light/137.svg"),
context: [.imageThumbnailPixelSize : CGSize.zero])
.resizable()
.scaledToFit() // important
.frame(width: 70, height: 35)
.background(Color.gray)
Text("CGSize.zero") |
Ah, yes, when I test that out by including |
For SVG bitmap image (such as watchOS), new version available in 1.6.0 If you want to keep aspect ratio, and does not know about See more complicated rules in README-Render SVG as bitmap image |
@loganrockmore Hi. If you still facing this issue. You can have a try with new version. |
Hello! I'm having an issue rendering SVG images on watchOS and I'm wondering if you can help me out.
I'm using
SDWebImageSVGCoder
along withSDWebImageSwiftUI
to try and show SVG images in a watchOS app. I've created an example project that uses Cocoapods to pull in version 1.5.0 ofSDWebImageSVGCoder
. In that app, I'm doing the following:The top image is an SVG and the bottom in a PNG. This is what the app looks like:
As you can see, the SVG here didn't load. What's interesting is that if I set a breakpoint in
SDImageSVGCoder.m
at line124
, which is the very end of thedecodedImageWithData:options:
function, I can see in the debugger that an image is created:The interesting thing is that it is the proper size of the SVG at the URL that I'm passing in, but doing a quicklook of the image in the debugger shows that it's a transparent image:
Am I doing something incorrect here? Or is there a bug with rendering these SVG images on watchOS? Thanks so much for the help!
The text was updated successfully, but these errors were encountered: