Skip to content

Commit 354dab9

Browse files
committed
Handle SkColor creation from rgba tuple
1 parent 71161bd commit 354dab9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

package/cpp/api/JsiSkColor.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,21 @@ class JsiSkColor : public RNJsi::JsiHostObject {
7676
return JsiSkColor::toValue(
7777
runtime, SkColorSetARGB(color.a * 255, color.r, color.g, color.b));
7878
} else if (arguments[0].isObject()) {
79-
return arguments[0].getObject(runtime);
79+
auto obj = arguments[0].getObject(runtime);
80+
if (obj.isArrayBuffer(runtime)) {
81+
return obj;
82+
} else if (obj.isArray(runtime)) {
83+
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));
93+
}
8094
}
8195
return jsi::Value::undefined();
8296
};

0 commit comments

Comments
 (0)