react-native-skia
react-native-skia copied to clipboard
Handle SkColor creation from rgba tuple
Skia.Color
accepts number[]
, but the native constructor doesn't actually account for it.
In JsiSkColor::createCtor, if argument[0].isObject()
(true for both Array
and Float32Array
), it's returned as is as the color value.
When the jsi::Value
is made into to an SkColor
in JsiSkColor::FromValue, the .buffer
property (which is of course is not there on an array -- thus undefined) is attempted to be accessed.
I've added support here.
Orthogonally, have you considered using [r: number, g: number, b: number, a: number]
instead of number[]
for extra type saftey?
Resolves #2113
I've signed the cla. Bit weird it asks for an address.
Thanks a lot I'm excited to sanitize the situation there. I added some tests for it at https://github.com/louix/react-native-skia/pull/1 but it seems to fail on Android. I will look into it.
You were correct about 0-1 vs 0-255!
I changed the JSI side slightly to mimic the web one (Array
The native side was just returning undefined if it wasn't sure how to handle the value, so you'd get an error where you tried to use the SkColor instead of when you created it. I added an throw at creation time (and an exhaustive one to the web side to match).
@louix please give me a bit of time to digest this. Recent work we've done may suggest we need to slightly change how colors are dealt with behind the scene.
but either way the tests you've written will be very useful.