Java Code Examples for com.facebook.react.bridge.WritableArray#pushInt()
The following examples show how to use
com.facebook.react.bridge.WritableArray#pushInt() .
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: JsonConvert.java From react-native-cordova with MIT License | 6 votes |
public static WritableArray jsonToReact(JSONArray jsonArray) throws JSONException { WritableArray writableArray = Arguments.createArray(); for(int i=0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value instanceof Float || value instanceof Double) { writableArray.pushDouble(jsonArray.getDouble(i)); } else if (value instanceof Number) { writableArray.pushInt(jsonArray.getInt(i)); } else if (value instanceof String) { writableArray.pushString(jsonArray.getString(i)); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToReact(jsonArray.getJSONObject(i))); } else if (value instanceof JSONArray){ writableArray.pushArray(jsonToReact(jsonArray.getJSONArray(i))); } else if (value == JSONObject.NULL){ writableArray.pushNull(); } } return writableArray; }
Example 2
Source File: ArrayUtil.java From Instabug-React-Native with MIT License | 6 votes |
public static WritableArray convertJsonToWritableArray(JSONArray jsonArray) throws JSONException { WritableArray array = Arguments.createArray(); for (int i = 0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value instanceof JSONObject) { array.pushMap(MapUtil.convertJsonToWritableMap((JSONObject) value)); } else if (value instanceof JSONArray) { array.pushArray(convertJsonToWritableArray((JSONArray) value)); } else if (value instanceof Boolean) { array.pushBoolean((Boolean) value); } else if (value instanceof Integer) { array.pushInt((Integer) value); } else if (value instanceof Double) { array.pushDouble((Double) value); } else if (value instanceof String) { array.pushString((String) value); } } return array; }
Example 3
Source File: DataTypeUtils.java From vinci with Apache License 2.0 | 6 votes |
private static void putIntoArray(WritableArray writableArray, Object value) { if (value instanceof String) { writableArray.pushString((String) value); } else if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } else if (value instanceof Double) { writableArray.pushDouble((Double) value); } else if (value instanceof Integer) { writableArray.pushInt((Integer) value); } else if (value == null) { writableArray.pushNull(); } else if (value.getClass().isArray()) { WritableArray array = Arguments.createArray(); for (int i = 0, size = Array.getLength(value); i < size; ++i) { putIntoArray(array, Array.get(value, i)); } writableArray.pushArray(array); } else if (value instanceof Collection) { writableArray.pushArray(toWritableArray((Collection<?>) value)); } else if (value instanceof Map) { //noinspection unchecked writableArray.pushMap(toWritableMap((Map<String, ?>) value)); } else { throw new IllegalArgumentException(); } }
Example 4
Source File: ReactNativeJson.java From react-native-fcm with MIT License | 6 votes |
public static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException { WritableArray array = new WritableNativeArray(); for (int i = 0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value instanceof JSONObject) { array.pushMap(convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { array.pushArray(convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { array.pushBoolean((Boolean) value); } else if (value instanceof Integer) { array.pushInt((Integer) value); } else if (value instanceof Double) { array.pushDouble((Double) value); } else if (value instanceof String) { array.pushString((String) value); } else { array.pushString(value.toString()); } } return array; }
Example 5
Source File: RNInstabugReactnativeModule.java From Instabug-React-Native with MIT License | 6 votes |
private static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException { WritableArray array = Arguments.createArray(); for (int i = 0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value instanceof JSONObject) { array.pushMap(convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { array.pushArray(convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { array.pushBoolean((Boolean) value); } else if (value instanceof Integer) { array.pushInt((Integer) value); } else if (value instanceof Double) { array.pushDouble((Double) value); } else if (value instanceof String) { array.pushString((String) value); } } return array; }
Example 6
Source File: ArrayConverter.java From react-native-tensorflow with Apache License 2.0 | 5 votes |
public static ReadableArray intArrayToReadableArray(int[] arr) { WritableArray writableArray = new WritableNativeArray(); for (int i : arr) { writableArray.pushInt(i); } return writableArray; }
Example 7
Source File: ArgumentUtils.java From react-native-sip with GNU General Public License v3.0 | 5 votes |
private static WritableArray fromJsonArray(JsonArray arr) { WritableArray result = new WritableNativeArray(); for (JsonElement el : arr) { Object item = fromJson(el); if (item instanceof WritableMap) { result.pushMap((WritableMap) item); } else if (item instanceof WritableArray) { result.pushArray((WritableArray) item); } else if (item instanceof String) { result.pushString((String) item); } else if (item instanceof LazilyParsedNumber) { result.pushInt(((LazilyParsedNumber) item).intValue()); } else if (item instanceof Integer) { result.pushInt((Integer) item); } else if (item instanceof Double) { result.pushDouble((Double) item); } else if (item instanceof Boolean) { result.pushBoolean((Boolean) item); } else { Log.d("ArgumentUtils", "Unknown type: " + item.getClass().getName()); result.pushNull(); } } return result; }
Example 8
Source File: ArrayUtil.java From react-native-background-geolocation with Apache License 2.0 | 5 votes |
public static WritableArray toWritableArray(Object[] array) { WritableArray writableArray = Arguments.createArray(); for (int i = 0; i < array.length; i++) { Object value = array[i]; if (value == null) { writableArray.pushNull(); } if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } if (value instanceof Double) { writableArray.pushDouble((Double) value); } if (value instanceof Integer) { writableArray.pushInt((Integer) value); } if (value instanceof String) { writableArray.pushString((String) value); } if (value instanceof Map) { writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value)); } if (value.getClass().isArray()) { writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value)); } } return writableArray; }
Example 9
Source File: NetworkRecordingModuleMock.java From react-native-GPay with MIT License | 5 votes |
private void onResponseReceived(int requestId, int code, WritableMap headers) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushInt(code); args.pushMap(headers); getEventEmitter().emit("didReceiveNetworkResponse", args); }
Example 10
Source File: NetworkRecordingModuleMock.java From react-native-GPay with MIT License | 5 votes |
private void onRequestComplete(int requestId, @Nullable String error) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushString(error); getEventEmitter().emit("didCompleteNetworkResponse", args); }
Example 11
Source File: NetworkRecordingModuleMock.java From react-native-GPay with MIT License | 5 votes |
private void onDataReceived(int requestId, String data) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushString(data); getEventEmitter().emit("didReceiveNetworkData", args); }
Example 12
Source File: UIImplementation.java From react-native-GPay with MIT License | 5 votes |
/** * Method which takes a container tag and then releases all subviews for that container upon * receipt. * TODO: The method name is incorrect and will be renamed, #6033872 * @param containerTag the tag of the container for which the subviews must be removed */ public void removeSubviewsFromContainerWithID(int containerTag) { ReactShadowNode containerNode = mShadowNodeRegistry.getNode(containerTag); if (containerNode == null) { throw new IllegalViewOperationException( "Trying to remove subviews of an unknown view tag: " + containerTag); } WritableArray indicesToRemove = Arguments.createArray(); for (int childIndex = 0; childIndex < containerNode.getChildCount(); childIndex++) { indicesToRemove.pushInt(childIndex); } manageChildren(containerTag, null, null, null, null, indicesToRemove); }
Example 13
Source File: Timing.java From react-native-GPay with MIT License | 5 votes |
@ReactMethod public void createTimer( final int callbackID, final int duration, final double jsSchedulingTime, final boolean repeat) { long deviceTime = SystemClock.currentTimeMillis(); long remoteTime = (long) jsSchedulingTime; // If the times on the server and device have drifted throw an exception to warn the developer // that things might not work or results may not be accurate. This is required only for // developer builds. if (mDevSupportManager.getDevSupportEnabled()) { long driftTime = Math.abs(remoteTime - deviceTime); if (driftTime > 60000) { getReactApplicationContext().getJSModule(JSTimers.class) .emitTimeDriftWarning( "Debugger and device times have drifted by more than 60s. Please correct this by " + "running adb shell \"date `date +%m%d%H%M%Y.%S`\" on your debugger machine."); } } // Adjust for the amount of time it took for native to receive the timer registration call long adjustedDuration = Math.max(0, remoteTime - deviceTime + duration); if (duration == 0 && !repeat) { WritableArray timerToCall = Arguments.createArray(); timerToCall.pushInt(callbackID); getReactApplicationContext().getJSModule(JSTimers.class) .callTimers(timerToCall); return; } long initialTargetTime = SystemClock.nanoTime() / 1000000 + adjustedDuration; Timer timer = new Timer(callbackID, initialTargetTime, duration, repeat); synchronized (mTimerGuard) { mTimers.add(timer); mTimerIdsToTimers.put(callbackID, timer); } }
Example 14
Source File: ResponseUtil.java From react-native-GPay with MIT License | 5 votes |
public static void onResponseReceived( RCTDeviceEventEmitter eventEmitter, int requestId, int statusCode, WritableMap headers, String url) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushInt(statusCode); args.pushMap(headers); args.pushString(url); eventEmitter.emit("didReceiveNetworkResponse", args); }
Example 15
Source File: ResponseUtil.java From react-native-GPay with MIT License | 5 votes |
public static void onRequestError( RCTDeviceEventEmitter eventEmitter, int requestId, String error, IOException e) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushString(error); if ((e != null) && (e.getClass() == SocketTimeoutException.class)) { args.pushBoolean(true); // last argument is a time out boolean } eventEmitter.emit("didCompleteNetworkResponse", args); }
Example 16
Source File: ResponseUtil.java From react-native-GPay with MIT License | 5 votes |
public static void onDataReceived( RCTDeviceEventEmitter eventEmitter, int requestId, WritableMap data) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushMap(data); eventEmitter.emit("didReceiveNetworkData", args); }
Example 17
Source File: ResponseUtil.java From react-native-GPay with MIT License | 5 votes |
public static void onDataReceived( RCTDeviceEventEmitter eventEmitter, int requestId, String data) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushString(data); eventEmitter.emit("didReceiveNetworkData", args); }
Example 18
Source File: Utils.java From react-native-update with MIT License | 5 votes |
public static WritableArray convertJsonArrayToWriteable(JSONArray jsonArr) { WritableArray arr = Arguments.createArray(); for (int i=0; i<jsonArr.length(); i++) { Object obj = null; try { obj = jsonArr.get(i); } catch (JSONException jsonException) { // Should not happen. throw new RuntimeException(i + " should be within bounds of array " + jsonArr.toString(), jsonException); } if (obj instanceof JSONObject) arr.pushMap(convertJsonObjectToWriteable((JSONObject) obj)); else if (obj instanceof JSONArray) arr.pushArray(convertJsonArrayToWriteable((JSONArray) obj)); else if (obj instanceof String) arr.pushString((String) obj); else if (obj instanceof Double) arr.pushDouble((Double) obj); else if (obj instanceof Integer) arr.pushInt((Integer) obj); else if (obj instanceof Boolean) arr.pushBoolean((Boolean) obj); else if (obj == null) arr.pushNull(); else throw new RuntimeException("Unrecognized object: " + obj); } return arr; }
Example 19
Source File: ResponseUtil.java From react-native-GPay with MIT License | 5 votes |
public static void onDataSend( RCTDeviceEventEmitter eventEmitter, int requestId, long progress, long total) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushInt((int) progress); args.pushInt((int) total); eventEmitter.emit("didSendNetworkData", args); }
Example 20
Source File: BleManager.java From react-native-ble-manager with Apache License 2.0 | 4 votes |
public static WritableArray bytesToWritableArray(byte[] bytes) { WritableArray value = Arguments.createArray(); for (int i = 0; i < bytes.length; i++) value.pushInt((bytes[i] & 0xFF)); return value; }