Search in sources :

Example 1 with ReadableType

use of com.facebook.react.bridge.ReadableType in project lottie-react-native by airbnb.

the class JSONReadableArray method get.

@Override
public Object get(int index) throws JSONException {
    if (cache[index] != null) {
        return cache[index];
    }
    ReadableType type = array.getType(index);
    try {
        Object val;
        switch(type) {
            case Null:
                val = null;
                break;
            case Boolean:
                val = array.getBoolean(index);
                break;
            case Number:
                Double dbl = array.getDouble(index);
                cache[index] = dbl;
                if ((dbl == Math.floor(dbl)) && !Double.isInfinite(dbl)) {
                    // integral type
                    return dbl.intValue();
                } else {
                    return dbl;
                }
            case String:
                val = array.getString(index);
                break;
            case Map:
                val = new JSONReadableMap(array.getMap(index));
                break;
            case Array:
                val = new JSONReadableArray(array.getArray(index));
                break;
            default:
                throw new JSONException("Could not convert object");
        }
        cache[index] = val;
        return val;
    } catch (RuntimeException e) {
        throw new JSONException(e.getMessage());
    }
}
Also used : ReadableType(com.facebook.react.bridge.ReadableType) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject)

Example 2 with ReadableType

use of com.facebook.react.bridge.ReadableType in project native-navigation by airbnb.

the class DefaultNavigationImplementation method mapEqual.

private static boolean mapEqual(ReadableMap a, ReadableMap b) {
    ReadableMapKeySetIterator iterator = b.keySetIterator();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        if (!a.hasKey(key))
            return false;
        ReadableType type = b.getType(key);
        if (type != a.getType(key))
            return false;
        switch(type) {
            case Null:
                break;
            case Boolean:
                if (a.getBoolean(key) != b.getBoolean(key))
                    return false;
                break;
            case Number:
                if (a.getDouble(key) != b.getDouble(key))
                    return false;
                break;
            case String:
                if (!a.getString(key).equals(b.getString(key)))
                    return false;
                break;
            case Map:
                if (!mapEqual(a.getMap(key), b.getMap(key)))
                    return false;
                break;
            case Array:
                if (!arrayEqual(a.getArray(key), b.getArray(key)))
                    return false;
                break;
            default:
                Log.e(TAG, "Could not convert object with key: " + key + ".");
        }
    }
    return true;
}
Also used : ReadableMapKeySetIterator(com.facebook.react.bridge.ReadableMapKeySetIterator) ReadableType(com.facebook.react.bridge.ReadableType)

Aggregations

ReadableType (com.facebook.react.bridge.ReadableType)2 ReadableMapKeySetIterator (com.facebook.react.bridge.ReadableMapKeySetIterator)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1