-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: remove extractColor in favor of RN impl #1726
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
Conversation
|
cc @Saadnajmi I think it should work OK on |
Thanks for the feature! I believe this should work, and I'll do my best to test this =). I'll explain the platform differences here since it's not very well documented: The main difference color-wise between React Native & React Native macOS is we have two different PlatformColors:
To support these types, I actually didn't have to change So, |
| if (typeof processedColor === 'object' && processedColor !== null) { | ||
| // if we got an object, it should be `PlatformColor` or `DynamicColorIOS`, | ||
| // so we pass it as an array with `0` value as first item, which is interpreted | ||
| // on the native side as color to be managed by `RCTConvert`. | ||
| return [0, processedColor]; |
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.
How did you find that passing 0 means RCTConvert handles the color?
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.
I went through the native code and here is the code:
- on
iOSwe go here https://github.com/react-native-svg/react-native-svg/blob/82f0f3a9858de718f831fa41ca670f1e8e2777e7/apple/Utils/RCTConvert%2BRNSVG.m#L64 which invokes this: https://github.com/react-native-svg/react-native-svg/blob/82f0f3a9858de718f831fa41ca670f1e8e2777e7/apple/Brushes/RNSVGSolidColorBrush.m#L23, which goes to this: https://github.com/react-native-svg/react-native-svg/blob/82f0f3a9858de718f831fa41ca670f1e8e2777e7/apple/Utils/RCTConvert%2BRNSVG.m#L137, which is thereact-native'sRCTConvertfor color, so should correctly resolve onmacOStoo if the implementation forNSColoris there. - on
Androidit lands here and is also resolved byreact-native'sColorPropConverter
As seen in the flow of passing the color, it is not passed directly as color through the bridge, but platform-specific |
Yep, working on that. I couldn't get the test app working yesterday, so I'll give it another shot today! |
|
An update, I've still been having issues running the macOS test app locally. I scheduled dedicated time this week for this PR specifically, but I may have to resort to making my own test app locally and running this PR's version of react-native-svg on it. Sorry for the delay! |
|
OK, I got the existing test app working on macOS with a caveat: The existing test app makes heavy use of Luckily, we do have a bunch of SVG tests in the other repo I help maintain: FluentUI React Native. So instead, I ran I replaced one color usage with |

Summary
PR removing
extractColor.tsin favor of using theprocessColorimplementation straight fromreact-native. It should handle all the cases from the previous implementation and the cases withPlatformColorandDynamicColorIOS. Normally we would just send the returned value to the native side, but inreact-native-svg, e.g.fillprop can have more values than just color, e.g.currentColor. Because of it, we cannot useUIColoroniOS,NSColoronmacOSandcustomType="Color"onAndroidas a prop type there and therefore we need to prepare the custom values on the JS side. It is done by passing the prop as an array with specific first element. In case of colors, it is0. (hopefully I understood the code right).Test Plan
ColorTest.tsxinTestsExample.What's required for testing (prerequisites)?
What are the steps to reproduce (after prerequisites)?
Compatibility
Checklist