Java Code Examples for com.facebook.react.bridge.WritableArray#pushNull()
The following examples show how to use
com.facebook.react.bridge.WritableArray#pushNull() .
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: FabricTwitterKitUtils.java From react-native-fabric-twitterkit with MIT License | 6 votes |
private static WritableArray jsonToWritableArray(final JSONArray jsonArray) throws JSONException { final WritableArray writableArray = Arguments.createArray(); for (int i = 0; i < jsonArray.length(); i++) { final 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 Boolean) { writableArray.pushBoolean(jsonArray.getBoolean(i)); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToWritableMap(jsonArray.getJSONObject(i))); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonToWritableArray(jsonArray.getJSONArray(i))); } else if (value == JSONObject.NULL) { writableArray.pushNull(); } } return writableArray; }
Example 2
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 3
Source File: RNMEvaluator.java From react-native-eval with MIT License | 6 votes |
/** * Marshalls a function call to the javascript layer, via our NativeModule. * * @param context The context needed to execute this in. * @param name The function to execute. e.g. "Math.Pow" * @param args The arguments to pass to the function, or null. * @param cb The completion callback for the result, or null. * @param event The name of the event that our NativeModule is listening for. */ private static void callFunction(ReactContext context, String name, @Nullable Object[] args, @Nullable EvaluatorCallback cb, String event) { String callId = UUID.randomUUID().toString(); if (null != cb) { callbacks.put(callId, cb); } WritableArray arguments = args != null ? Arguments.fromJavaArgs(args) : Arguments.createArray(); if (arguments.size() == 0) { arguments.pushNull(); } WritableMap eventParams = Arguments.createMap(); eventParams.putString("name", name); eventParams.putArray("args", arguments); eventParams.putString("callId", callId); // TODO: move to AppEventEmitter once App events are supported on android. context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(event, eventParams); }
Example 4
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 5
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 6
Source File: ResponseUtil.java From react-native-GPay with MIT License | 5 votes |
public static void onRequestSuccess(RCTDeviceEventEmitter eventEmitter, int requestId) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushNull(); eventEmitter.emit("didCompleteNetworkResponse", args); }
Example 7
Source File: Utils.java From photo-viewer with Apache License 2.0 | 5 votes |
@Nullable public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) { WritableArray writableArray = new WritableNativeArray(); if (jsonArray == null) { return null; } if (jsonArray.length() <= 0) { return null; } for (int i = 0; i < jsonArray.length(); i++) { try { Object value = jsonArray.get(i); if (value == null) { writableArray.pushNull(); } else if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } else if (value instanceof Integer) { writableArray.pushInt((Integer) value); } else if (value instanceof Double) { writableArray.pushDouble((Double) value); } else if (value instanceof String) { writableArray.pushString((String) value); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToWritableMap((JSONObject) value)); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value)); } } catch (JSONException e) { // Do nothing and fail silently } } return writableArray; }
Example 8
Source File: RCTConvert.java From react-native-twilio-chat with MIT License | 5 votes |
public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) { WritableArray writableArray = new WritableNativeArray(); try { if (jsonArray == null) { return null; } if (jsonArray.length() <= 0) { return null; } for (int i = 0 ; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value == null) { writableArray.pushNull(); } else if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } else if (value instanceof Integer) { writableArray.pushInt((Integer) value); } else if (value instanceof Double) { writableArray.pushDouble((Double) value); } else if (value instanceof String) { writableArray.pushString((String) value); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToWritableMap((JSONObject) value)); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value)); } } } catch (JSONException e) { // Do nothing and fail silently } return writableArray; }
Example 9
Source File: Utils.java From magnet-client with Mozilla Public License 2.0 | 5 votes |
@Nullable public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) { WritableArray writableArray = new WritableNativeArray(); if (jsonArray == null) { return null; } if (jsonArray.length() <= 0) { return null; } for (int i = 0 ; i < jsonArray.length(); i++) { try { Object value = jsonArray.get(i); if (value == null) { writableArray.pushNull(); } else if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } else if (value instanceof Integer) { writableArray.pushInt((Integer) value); } else if (value instanceof Double) { writableArray.pushDouble((Double) value); } else if (value instanceof String) { writableArray.pushString((String) value); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToWritableMap((JSONObject) value)); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value)); } } catch (JSONException e) { // Do nothing and fail silently } } return writableArray; }
Example 10
Source File: RCTConvert.java From react-native-twilio-ip-messaging with MIT License | 5 votes |
public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) { WritableArray writableArray = new WritableNativeArray(); if (jsonArray == null) { return null; } if (jsonArray.length() <= 0) { return null; } for (int i = 0 ; i < jsonArray.length(); i++) { try { Object value = jsonArray.get(i); if (value == null) { writableArray.pushNull(); } else if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } else if (value instanceof Integer) { writableArray.pushInt((Integer) value); } else if (value instanceof Double) { writableArray.pushDouble((Double) value); } else if (value instanceof String) { writableArray.pushString((String) value); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToWritableMap((JSONObject) value)); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value)); } } catch (JSONException e) { // Do nothing and fail silently } } return writableArray; }
Example 11
Source File: ArrayUtil.java From vinci 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 12
Source File: ArgumentUtils.java From react-native-pjsip 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 13
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 14
Source File: ArrayUtil.java From Instabug-React-Native with MIT License | 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 15
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; }