Java Code Examples for com.facebook.react.bridge.WritableArray#pushArray()

The following examples show how to use com.facebook.react.bridge.WritableArray#pushArray() . 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: RNUtils.java    From react-native-batch-push with MIT License 6 votes vote down vote up
public static WritableArray convertArrayToWritableArray(Object[] input) {
    WritableArray output = new WritableNativeArray();

    for (int i = 0; i < input.length; i++) {
        Object value = input[i];
        if (value instanceof Map) {
            output.pushMap(convertMapToWritableMap((Map<String, Object>) value));
        } else if (value instanceof  JSONArray) {
            output.pushArray(convertArrayToWritableArray((Object[]) value));
        } else if (value instanceof  Boolean) {
            output.pushBoolean((Boolean) value);
        } else if (value instanceof  Integer) {
            output.pushInt((Integer) value);
        } else if (value instanceof  Double) {
            output.pushDouble((Double) value);
        } else if (value instanceof String)  {
            output.pushString((String) value);
        } else {
            output.pushString(value.toString());
        }
    }
    return output;
}
 
Example 2
Source File: JsonConvert.java    From react-native-cordova with MIT License 6 votes vote down vote up
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 3
Source File: ReactNativeJson.java    From react-native-couchbase-lite with MIT License 6 votes vote down vote up
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 4
Source File: RNInstabugReactnativeModule.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
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 5
Source File: ArrayUtil.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
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 6
Source File: RNSensitiveInfoModule.java    From react-native-sensitive-info with MIT License 6 votes vote down vote up
@ReactMethod
public void getAllItems(ReadableMap options, Promise pm) {

    String name = sharedPreferences(options);

    Map<String, ?> allEntries = prefs(name).getAll();
    WritableArray resultData = new WritableNativeArray();

    for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
        WritableMap entryMap = new WritableNativeMap();

        entryMap.putString("key", entry.getKey());
        entryMap.putString("value", entry.getValue().toString());
        entryMap.putString("service", name);
        resultData.pushMap(entryMap);
    }

    WritableArray resultWrapper = new WritableNativeArray();
    resultWrapper.pushArray(resultData);
    pm.resolve(resultWrapper);
}
 
Example 7
Source File: DataTypeUtils.java    From vinci with Apache License 2.0 6 votes vote down vote up
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 8
Source File: FabricTwitterKitUtils.java    From react-native-fabric-twitterkit with MIT License 6 votes vote down vote up
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 9
Source File: ReactNativeJson.java    From react-native-fcm with MIT License 6 votes vote down vote up
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 10
Source File: RCTConvert.java    From react-native-twilio-ip-messaging with MIT License 5 votes vote down vote up
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: Utils.java    From magnet-client with Mozilla Public License 2.0 5 votes vote down vote up
@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 12
Source File: ArrayUtil.java    From vinci with Apache License 2.0 5 votes vote down vote up
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 13
Source File: ArgumentUtils.java    From react-native-pjsip with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: ArrayUtil.java    From react-native-background-geolocation with Apache License 2.0 5 votes vote down vote up
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: ArrayUtil.java    From Instabug-React-Native with MIT License 5 votes vote down vote up
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 16
Source File: RCTConvert.java    From react-native-twilio-chat with MIT License 5 votes vote down vote up
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 17
Source File: Utils.java    From photo-viewer with Apache License 2.0 5 votes vote down vote up
@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 18
Source File: Utils.java    From react-native-update with MIT License 5 votes vote down vote up
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: ArgumentUtils.java    From react-native-sip with GNU General Public License v3.0 5 votes vote down vote up
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;
}