-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix low-quality masks on iOS #1658
Fix low-quality masks on iOS #1658
Conversation
Do you plan a new release soon? I have great hopes that this PR could solve many issues in my app 🙏🏻 |
@@ -202,18 +202,23 @@ - (void)renderTo:(CGContextRef)context rect:(CGRect)rect | |||
CGSize boundsSize = bounds.size; | |||
CGFloat height = boundsSize.height; | |||
CGFloat width = boundsSize.width; | |||
CGFloat scale = [[UIScreen mainScreen] scale]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we want to support macOS
, you should not use UIScreen
, but rather add the option for both platforms analogous to how it is done e.g. with UIColor
, so just add new define #define RNSVGScreen UIScreen
here: https://github.com/react-native-svg/react-native-svg/blob/39c8332f4dac8acfe1c60338ad4a8f8231538c91/apple/RNSVGUIKit.h#L12 and #define RNSVGScreen NSScreen
here: https://github.com/react-native-svg/react-native-svg/blob/39c8332f4dac8acfe1c60338ad4a8f8231538c91/apple/RNSVGUIKit.h#L20 and then use RNSVGScreen
instead of UIScreen
in your PR.
Thanks for the feedback @WoLewicki ! I took it into account but I had to use a different approach as the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
Summary
This PR fixes low-quality masks on iOS, as reported in #1098.
This was caused by the bitmap for the mask being created with CGBitmapContextCreate() which does not take into account the device's pixel-density, unlike UIGraphicsBeginImageContextWithOptions().
To fix it, the pixel-density is retrieved using
[[UIScreen mainScreen] scale]
and it is used as a scale factor for the mask bitmap.Test Plan
I've tested using this sample:
Results: