@@ -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,9 +74,7 @@ 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);
8479 double r = std::clamp (array.getValueAtIndex (runtime, 0 ).getNumber (),
8580 0.0 , 255.0 );
@@ -90,9 +85,16 @@ class JsiSkColor : public RNJsi::JsiHostObject {
9085 double a = std::clamp (array.getValueAtIndex (runtime, 3 ).getNumber (),
9186 0.0 , 255.0 );
9287 return JsiSkColor::toValue (runtime, SkColorSetARGB (a, r, g, b));
88+ } else if (obj.hasProperty (runtime, " buffer" ) &&
89+ obj.getPropertyAsObject (runtime, " buffer" )
90+ .isArrayBuffer (runtime)) {
91+ return obj;
9392 }
9493 }
95- return jsi::Value::undefined ();
94+ throw jsi::JSError (runtime,
95+ " Skia.Color expected number, Float32Array, number[], "
96+ " or string and got: " +
97+ arguments[0 ].toString (runtime).utf8 (runtime));
9698 };
9799 }
98100};
0 commit comments