Java Code Examples for com.facebook.react.bridge.ReadableArray#getArray()
The following examples show how to use
com.facebook.react.bridge.ReadableArray#getArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatalystNativeJSToJavaParametersTestCase.java From react-native-GPay with MIT License | 6 votes |
private void arrayGetByType(ReadableArray array, int index, String typeToAskFor) { if (typeToAskFor.equals("double")) { array.getDouble(index); } else if (typeToAskFor.equals("int")) { array.getInt(index); } else if (typeToAskFor.equals("string")) { array.getString(index); } else if (typeToAskFor.equals("array")) { array.getArray(index); } else if (typeToAskFor.equals("map")) { array.getMap(index); } else if (typeToAskFor.equals("boolean")) { array.getBoolean(index); } else { throw new RuntimeException("Unknown type: " + typeToAskFor); } }
Example 2
Source File: BaiduMapViewManager.java From BaiduMapKit with MIT License | 6 votes |
/** * 显示地理标记 * * @param mapView * @param array */ @ReactProp(name="marker") public void setMarker(MapView mapView, ReadableArray array) { Log.d(TAG, "marker:" + array); if (array != null) { for (int i = 0; i < array.size(); i++) { ReadableArray sub = array.getArray(i); //定义Maker坐标点 LatLng point = new LatLng(sub.getDouble(0), sub.getDouble(1)); //构建Marker图标 BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding); //构建MarkerOption,用于在地图上添加Marker OverlayOptions option = new MarkerOptions() .position(point) .icon(bitmap) .draggable(true); //在地图上添加Marker,并显示 mapView.getMap().addOverlay(option); } } }
Example 3
Source File: NetworkingModule.java From react-native-GPay with MIT License | 5 votes |
/** * Extracts the headers from the Array. If the format is invalid, this method will return null. */ private @Nullable Headers extractHeaders( @Nullable ReadableArray headersArray, @Nullable ReadableMap requestData) { if (headersArray == null) { return null; } Headers.Builder headersBuilder = new Headers.Builder(); for (int headersIdx = 0, size = headersArray.size(); headersIdx < size; headersIdx++) { ReadableArray header = headersArray.getArray(headersIdx); if (header == null || header.size() != 2) { return null; } String headerName = header.getString(0); String headerValue = header.getString(1); if (headerName == null || headerValue == null) { return null; } headersBuilder.add(headerName, headerValue); } if (headersBuilder.get(USER_AGENT_HEADER_NAME) == null && mDefaultUserAgent != null) { headersBuilder.add(USER_AGENT_HEADER_NAME, mDefaultUserAgent); } // Sanitize content encoding header, supported only when request specify payload as string boolean isGzipSupported = requestData != null && requestData.hasKey(REQUEST_BODY_KEY_STRING); if (!isGzipSupported) { headersBuilder.removeAll(CONTENT_ENCODING_HEADER_NAME); } return headersBuilder.build(); }
Example 4
Source File: CatalystNativeJSToJavaParametersTestCase.java From react-native-GPay with MIT License | 5 votes |
public void testNestedArray() { mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnNestedArray(); waitForBridgeAndUIIdle(); List<ReadableArray> calls = mRecordingTestModule.getArrayCalls(); assertEquals(1, calls.size()); ReadableArray array = calls.get(0); assertNotNull(array); assertEquals(2, array.size()); assertEquals("we", array.getString(0)); assertFalse(array.isNull(1)); ReadableArray subArray = array.getArray(1); assertEquals(2, subArray.size()); assertEquals("have", subArray.getString(0)); subArray = subArray.getArray(1); assertEquals(2, subArray.size()); assertEquals("to", subArray.getString(0)); subArray = subArray.getArray(1); assertEquals(2, subArray.size()); assertEquals("go", subArray.getString(0)); subArray = subArray.getArray(1); assertEquals(1, subArray.size()); assertEquals("deeper", subArray.getString(0)); }
Example 5
Source File: CatalystNativeJSToJavaParametersTestCase.java From react-native-GPay with MIT License | 5 votes |
public void testMapParameterWithArrays() throws InterruptedException { mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithArrays(); waitForBridgeAndUIIdle(); List<ReadableMap> calls = mRecordingTestModule.getMapCalls(); assertEquals(1, calls.size()); ReadableMap map = calls.get(0); assertNotNull(map); ReadableArray arrayParameter; assertTrue(map.hasKey("empty")); arrayParameter = map.getArray("empty"); assertNotNull(arrayParameter); assertEquals(0, arrayParameter.size()); assertTrue(map.hasKey("ints")); assertFalse(map.isNull("ints")); arrayParameter = map.getArray("ints"); assertNotNull(arrayParameter); assertEquals(2, arrayParameter.size()); assertEquals(43, arrayParameter.getInt(0)); assertEquals(44, arrayParameter.getInt(1)); assertTrue(map.hasKey("mixed")); arrayParameter = map.getArray("mixed"); assertNotNull(arrayParameter); assertEquals(3, arrayParameter.size()); assertEquals(77, arrayParameter.getInt(0)); assertEquals("string", arrayParameter.getString(1)); ReadableArray nestedArray = arrayParameter.getArray(2); assertEquals(2, nestedArray.size()); }
Example 6
Source File: TabLayoutManager.java From react-native-android-kit with MIT License | 5 votes |
@Override public void receiveCommand(TabLayoutView root, int commandId, @Nullable ReadableArray args) { Assertions.assertNotNull(root); Assertions.assertNotNull(args); switch (commandId) { case COMMAND_SETUPWITHVIEWPAGER: ViewPager viewPager = (ViewPager) root.getRootView().findViewById(args.getInt(0)); if (viewPager != null) { root.setupWithViewPager(viewPager); ReadableArray tabsSettingsArray = args.getArray(1); if (!this.addTabs(root, tabsSettingsArray)) { throw new IllegalViewOperationException( "One or more tabs was/were not created: an error occurred (ReadableArray null and/or TabLayoutView null) in " + getClass().getSimpleName() ); } } else { throw new IllegalViewOperationException( "Nonexistent ViewPager instance. Null value received by " + getClass().getSimpleName() ); } break; default: throw new IllegalArgumentException( String.format( "Unsupported command %d received by %s.", commandId, getClass().getSimpleName() ) ); } }
Example 7
Source File: TabLayoutManager.java From react-native-android-kit with MIT License | 5 votes |
@Override public void receiveCommand(TabLayoutView root, int commandId, @Nullable ReadableArray args) { Assertions.assertNotNull(root); Assertions.assertNotNull(args); switch (commandId) { case COMMAND_SETUPWITHVIEWPAGER: ViewPager viewPager = (ViewPager) root.getRootView().findViewById(args.getInt(0)); if (viewPager != null) { root.setupWithViewPager(viewPager); ReadableArray tabsSettingsArray = args.getArray(1); if (!this.addTabs(root, tabsSettingsArray)) { throw new IllegalViewOperationException( "One or more tabs was/were not created: an error occurred (ReadableArray null and/or TabLayoutView null) in " + getClass().getSimpleName() ); } } else { throw new IllegalViewOperationException( "Nonexistent ViewPager instance. Null value received by " + getClass().getSimpleName() ); } break; default: throw new IllegalArgumentException( String.format( "Unsupported command %d received by %s.", commandId, getClass().getSimpleName() ) ); } }
Example 8
Source File: SQLitePluginConverter.java From react-native-sqlite-storage with MIT License | 5 votes |
static Object get(ReadableArray array,int index,Object defaultValue){ if (array == null){ return defaultValue; } try { Object value = null; ReadableType type = array.getType(index); switch(type){ case Boolean: value = array.getBoolean(index); break; case Number: value = array.getDouble(index); break; case String: value = array.getString(index); break; case Map: value = array.getMap(index); break; case Array: value = array.getArray(index); break; case Null: break; } return value; } catch (NoSuchKeyException ex){ return defaultValue; } }
Example 9
Source File: SQLitePluginConverter.java From react-native-sqlite-storage with MIT License | 5 votes |
static Object get(ReadableArray array,int index,Object defaultValue){ if (array == null){ return defaultValue; } try { Object value = null; ReadableType type = array.getType(index); switch(type){ case Boolean: value = array.getBoolean(index); break; case Number: value = array.getDouble(index); break; case String: value = array.getString(index); break; case Map: value = array.getMap(index); break; case Array: value = array.getArray(index); break; case Null: break; } return value; } catch (NoSuchKeyException ex){ return defaultValue; } }