use of com.facebook.react.bridge.JavaOnlyArray in project react-native-navigation by wix.
the class ColorParseTest method shouldParsePlatformColors.
@Test
public void shouldParsePlatformColors() throws JSONException {
JSONObject color = new JSONObject();
final JSONArray jsonArray = new JSONArray();
jsonArray.put("@color/colorPrimary");
color.put("resource_paths", jsonArray);
try (MockedStatic<Arguments> theMock = Mockito.mockStatic(Arguments.class)) {
theMock.when(Arguments::createMap).thenReturn(new JavaOnlyMap());
theMock.when(Arguments::createArray).thenReturn(new JavaOnlyArray());
assertThat(ColorParser.parse(activity, color, "color")).isInstanceOf(ReactPlatformColor.class);
}
}
use of com.facebook.react.bridge.JavaOnlyArray in project react-native-navigation by wix.
the class JSONParserTest method parsesMap.
@Test
public void parsesMap() throws Exception {
JavaOnlyMap input = new JavaOnlyMap();
input.putString("keyString", "stringValue");
input.putInt("keyInt", 123);
input.putDouble("keyDouble", 123.456);
input.putBoolean("keyBoolean", true);
input.putArray("keyArray", new JavaOnlyArray());
input.putMap("keyMap", new JavaOnlyMap());
input.putNull("bla");
JSONObject result = new JSONParser().parse(input);
assertThat(result.keys()).containsOnly("keyString", "keyInt", "keyDouble", "keyBoolean", "keyMap", "keyArray");
assertThat(result.get("keyString")).isEqualTo("stringValue");
assertThat(result.get("keyInt")).isEqualTo(123);
assertThat(result.get("keyDouble")).isEqualTo(123.456);
assertThat(result.get("keyBoolean")).isEqualTo(true);
assertThat(result.getJSONObject("keyMap").keys()).isEmpty();
assertThat(result.getJSONArray("keyArray").length()).isZero();
}
use of com.facebook.react.bridge.JavaOnlyArray in project react-native-navigation by wix.
the class JSONParserTest method parsesArrays.
@Test
public void parsesArrays() throws Exception {
JavaOnlyArray input = new JavaOnlyArray();
input.pushString("Hello");
input.pushInt(123);
input.pushDouble(123.456);
input.pushBoolean(true);
input.pushArray(new JavaOnlyArray());
input.pushMap(new JavaOnlyMap());
input.pushNull();
JSONArray result = new JSONParser().parse(input);
assertThat(result.length()).isEqualTo(6);
assertThat(result.get(0)).isEqualTo("Hello");
assertThat(result.get(1)).isEqualTo(123);
assertThat(result.get(2)).isEqualTo(123.456);
assertThat(result.get(3)).isEqualTo(true);
assertThat(result.getJSONArray(4).length()).isZero();
assertThat(result.getJSONObject(5).keys()).isEmpty();
}
use of com.facebook.react.bridge.JavaOnlyArray in project react-native-image-picker by marcshilling.
the class ImagePickerModuleTest method nativeMock.
private void nativeMock() {
PowerMockito.mockStatic(Arguments.class);
when(Arguments.createArray()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return new JavaOnlyArray();
}
});
when(Arguments.createMap()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return new JavaOnlyMap();
}
});
}
use of com.facebook.react.bridge.JavaOnlyArray in project react-native-svg by react-native-svg.
the class RenderableView method setFill.
@ReactProp(name = "fill")
public void setFill(@Nullable Dynamic fill) {
if (fill == null || fill.isNull()) {
this.fill = null;
invalidate();
return;
}
ReadableType type = fill.getType();
if (type.equals(ReadableType.Number)) {
this.fill = JavaOnlyArray.of(0, fill.asInt());
} else if (type.equals(ReadableType.Array)) {
this.fill = fill.asArray();
} else {
JavaOnlyArray arr = new JavaOnlyArray();
arr.pushInt(0);
Matcher m = regex.matcher(fill.asString());
int i = 0;
while (m.find()) {
double parsed = Double.parseDouble(m.group());
arr.pushDouble(i++ < 3 ? parsed / 255 : parsed);
}
this.fill = arr;
}
invalidate();
}
Aggregations