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

The following examples show how to use com.facebook.react.bridge.WritableArray#pushBoolean() . 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: UserProfileBridge.java    From react-native-lock with MIT License 6 votes vote down vote up
private void put(String key, List<?> list, WritableMap into) {
    if (list == null || list.isEmpty()) {
        return;
    }

    final WritableArray array = Arguments.createArray();
    for (Object item: list) {
        if (item instanceof String) {
            array.pushString((String) item);
        }
        if (item instanceof Integer) {
            array.pushInt((Integer) item);
        }
        if (item instanceof Boolean) {
            array.pushBoolean((Boolean) item);
        }
        if (item instanceof Double) {
            array.pushDouble((Double) item);
        }
        if (item instanceof Date) {
            array.pushString(formatter.format(item));
        }
    }
    into.putArray(key, array);
}
 
Example 2
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 3
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 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: 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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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;
}
 
Example 15
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 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: ArrayConverter.java    From react-native-tensorflow with Apache License 2.0 5 votes vote down vote up
public static ReadableArray byteArrayToBoolReadableArray(byte[] arr) {
    WritableArray writableArray = new WritableNativeArray();
    byte[] pos = new byte[]{(byte)0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1};

    for(int i = 0; i < arr.length; i++){
        for(int k = 0; k < 8; k++){
            boolean res = (arr[i] & pos[k]) != 0;
            writableArray.pushBoolean(res);
        }
    }

    return writableArray;
}
 
Example 18
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 19
Source File: CatalystNativeJavaToJSReturnValuesTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactMethod(isBlockingSynchronousMethod = true)
WritableArray getArray() {
  WritableArray arr = new WritableNativeArray();
  arr.pushString("a");
  arr.pushBoolean(true);
  return arr;
}
 
Example 20
Source File: ResponseUtil.java    From react-native-GPay with MIT License 5 votes vote down vote up
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);
}