@@ -45,10 +45,7 @@ class JsiSkColor : public RNJsi::JsiHostObject {
4545 static SkColor fromValue (jsi::Runtime &runtime, const jsi::Value &obj) {
4646 const auto &object = obj.asObject (runtime);
4747 jsi::ArrayBuffer buffer =
48- object
49- .getProperty (runtime, jsi::PropNameID::forAscii (runtime, " buffer" ))
50- .asObject (runtime)
51- .getArrayBuffer (runtime);
48+ object.getPropertyAsObject (runtime, " buffer" ).getArrayBuffer (runtime);
5249 auto bfrPtr = reinterpret_cast <float *>(buffer.data (runtime));
5350 if (bfrPtr[0 ] > 1 || bfrPtr[1 ] > 1 || bfrPtr[2 ] > 1 || bfrPtr[3 ] > 1 ) {
5451 return SK_ColorBLACK;
@@ -77,22 +74,23 @@ class JsiSkColor : public RNJsi::JsiHostObject {
7774 runtime, SkColorSetARGB (color.a * 255 , color.r , color.g , color.b ));
7875 } else if (arguments[0 ].isObject ()) {
7976 auto obj = arguments[0 ].getObject (runtime);
80- if (obj.isArrayBuffer (runtime)) {
81- return obj;
82- } else if (obj.isArray (runtime)) {
77+ if (obj.isArray (runtime)) {
8378 auto array = obj.asArray (runtime);
84- double r = std::clamp ( array. getValueAtIndex (runtime, 0 ). getNumber (),
85- 0.0 , 255.0 );
86- double g = std::clamp (array. getValueAtIndex (runtime, 1 ). getNumber (),
87- 0.0 , 255.0 );
88- double b = std::clamp (array. getValueAtIndex (runtime, 2 ). getNumber (),
89- 0.0 , 255.0 );
90- double a = std::clamp (array. getValueAtIndex (runtime, 3 ). getNumber (),
91- 0.0 , 255.0 );
92- return JsiSkColor::toValue (runtime, SkColorSetARGB (a, r, g, b)) ;
79+ // turn the array into a Float32Array
80+ return runtime. global ()
81+ . getPropertyAsFunction (runtime, " Float32Array " )
82+ . callAsConstructor (runtime, array)
83+ . getObject (runtime);
84+ } else if (obj. hasProperty (runtime, " buffer " ) &&
85+ obj. getPropertyAsObject (runtime, " buffer " )
86+ . isArrayBuffer (runtime)) {
87+ return obj ;
9388 }
9489 }
95- return jsi::Value::undefined ();
90+ throw jsi::JSError (runtime,
91+ " Skia.Color expected number, Float32Array, number[], "
92+ " or string and got: " +
93+ arguments[0 ].toString (runtime).utf8 (runtime));
9694 };
9795 }
9896};
0 commit comments