Search in sources :

Example 6 with JavaOnlyArray

use of com.facebook.react.bridge.JavaOnlyArray in project react-native-svg by react-native-svg.

the class RenderableView method setStroke.

@ReactProp(name = "stroke")
public void setStroke(@Nullable Dynamic strokeColors) {
    if (strokeColors == null || strokeColors.isNull()) {
        stroke = null;
        invalidate();
        return;
    }
    ReadableType type = strokeColors.getType();
    if (type.equals(ReadableType.Number)) {
        stroke = JavaOnlyArray.of(0, strokeColors.asInt());
    } else if (type.equals(ReadableType.Array)) {
        stroke = strokeColors.asArray();
    } else {
        JavaOnlyArray arr = new JavaOnlyArray();
        arr.pushInt(0);
        Matcher m = regex.matcher(strokeColors.asString());
        int i = 0;
        while (m.find()) {
            double parsed = Double.parseDouble(m.group());
            arr.pushDouble(i++ < 3 ? parsed / 255 : parsed);
        }
        stroke = arr;
    }
    invalidate();
}
Also used : ReadableType(com.facebook.react.bridge.ReadableType) Matcher(java.util.regex.Matcher) JavaOnlyArray(com.facebook.react.bridge.JavaOnlyArray) ReactProp(com.facebook.react.uimanager.annotations.ReactProp)

Aggregations

JavaOnlyArray (com.facebook.react.bridge.JavaOnlyArray)6 JavaOnlyMap (com.facebook.react.bridge.JavaOnlyMap)4 BaseTest (com.reactnativenavigation.BaseTest)3 Test (org.junit.Test)3 ReadableType (com.facebook.react.bridge.ReadableType)2 ReactProp (com.facebook.react.uimanager.annotations.ReactProp)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Arguments (com.facebook.react.bridge.Arguments)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1