Java Code Examples for com.facebook.react.bridge.ReadableMapKeySetIterator

The following are top voted examples for showing how to use com.facebook.react.bridge.ReadableMapKeySetIterator. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 7 votes vote down vote up
public void testMapIterateOverNestedMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnNestedMap();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator firstLevelIterator = map.keySetIterator();
  String firstLevelKey = firstLevelIterator.nextKey();
  assertEquals(firstLevelKey, "weHaveToGoDeeper");

  ReadableNativeMap secondMap = map.getMap("weHaveToGoDeeper");
  ReadableMapKeySetIterator secondLevelIterator = secondMap.keySetIterator();
  String secondLevelKey = secondLevelIterator.nextKey();
  assertEquals(secondLevelKey, "inception");
  assertTrue(secondMap.getBoolean(secondLevelKey));
}
 
Example 2
Project: react-native-android-speech-recognizer   File: RNAndroidSpeechRecognizerModule.java   View source code 6 votes vote down vote up
private Intent createIntent(String action, ReadableMap extra) {
  final Intent intent = new Intent(action);
  for (
    ReadableMapKeySetIterator it = extra.keySetIterator();
    it.hasNextKey();
  ) {
    String key = it.nextKey();
    ReadableType type = extra.getType(key);
    switch(type) {
      case Null:
        break;
      case Boolean:
        intent.putExtra(key, extra.getBoolean(key));
        break;
      case Number:
        intent.putExtra(key, extra.getInt(key));
        break;
      case String:
        intent.putExtra(key, extra.getString(key));
        break;
      default:
        throw new IllegalArgumentException("Unsupported type " + type);
    }
  }
  return intent;
}
 
Example 3
Project: react-native-twilio-chat   File: RCTConvert.java   View source code 6 votes vote down vote up
public static HashMap<String, Object> readableMapToHashMap(ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }
    HashMap map = new HashMap<String, Object>();
    ReadableMapKeySetIterator keySetIterator = readableMap.keySetIterator();
    while (keySetIterator.hasNextKey()) {
        String key = keySetIterator.nextKey();
        ReadableType type = readableMap.getType(key);
        switch(type) {
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                HashMap<String, Object> attributes = new RCTConvert().readableMapToHashMap(readableMap.getMap(key));
                map.put(key, attributes);
                break;
            default:
                // do nothing
        }
    }
    return map;
}
 
Example 4
Project: RNLearn_Project1   File: NativeViewHierarchyOptimizer.java   View source code 6 votes vote down vote up
private static boolean isLayoutOnlyAndCollapsable(@Nullable ReactStylesDiffMap props) {
  if (props == null) {
    return true;
  }

  if (props.hasKey(ViewProps.COLLAPSABLE) && !props.getBoolean(ViewProps.COLLAPSABLE, true)) {
    return false;
  }

  ReadableMapKeySetIterator keyIterator = props.mBackingMap.keySetIterator();
  while (keyIterator.hasNextKey()) {
    if (!ViewProps.isLayoutOnly(props.mBackingMap, keyIterator.nextKey())) {
      return false;
    }
  }
  return true;
}
 
Example 5
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testMapIterateOverMapWithBasicTypes() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  Set<String> keys = new HashSet<String>();
  while (mapIterator.hasNextKey()) {
    keys.add(mapIterator.nextKey());
  }

  Set<String> expectedKeys = new HashSet<String>(
      Arrays.asList("stringKey", "doubleKey", "intKey", "booleanKey", "nullKey"));
  assertEquals(keys, expectedKeys);
}
 
Example 6
Project: RNLearn_Project1   File: NativeViewHierarchyOptimizer.java   View source code 6 votes vote down vote up
private static boolean isLayoutOnlyAndCollapsable(@Nullable ReactStylesDiffMap props) {
  if (props == null) {
    return true;
  }

  if (props.hasKey(ViewProps.COLLAPSABLE) && !props.getBoolean(ViewProps.COLLAPSABLE, true)) {
    return false;
  }

  ReadableMapKeySetIterator keyIterator = props.mBackingMap.keySetIterator();
  while (keyIterator.hasNextKey()) {
    if (!ViewProps.isLayoutOnly(props.mBackingMap, keyIterator.nextKey())) {
      return false;
    }
  }
  return true;
}
 
Example 7
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testMapIterateOverMapWithBasicTypes() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  Set<String> keys = new HashSet<String>();
  while (mapIterator.hasNextKey()) {
    keys.add(mapIterator.nextKey());
  }

  Set<String> expectedKeys = new HashSet<String>(
      Arrays.asList("stringKey", "doubleKey", "intKey", "booleanKey", "nullKey"));
  assertEquals(keys, expectedKeys);
}
 
Example 8
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testMapIterateOverNestedMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnNestedMap();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator firstLevelIterator = map.keySetIterator();
  String firstLevelKey = firstLevelIterator.nextKey();
  assertEquals(firstLevelKey, "weHaveToGoDeeper");

  ReadableNativeMap secondMap = map.getMap("weHaveToGoDeeper");
  ReadableMapKeySetIterator secondLevelIterator = secondMap.keySetIterator();
  String secondLevelKey = secondLevelIterator.nextKey();
  assertEquals(secondLevelKey, "inception");
  assertTrue(secondMap.getBoolean(secondLevelKey));
}
 
Example 9
Project: ReactNativeSignatureExample   File: NativeViewHierarchyOptimizer.java   View source code 6 votes vote down vote up
private static boolean isLayoutOnlyAndCollapsable(@Nullable ReactStylesDiffMap props) {
  if (props == null) {
    return true;
  }

  if (props.hasKey(ViewProps.COLLAPSABLE) && !props.getBoolean(ViewProps.COLLAPSABLE, true)) {
    return false;
  }

  ReadableMapKeySetIterator keyIterator = props.mBackingMap.keySetIterator();
  while (keyIterator.hasNextKey()) {
    if (!ViewProps.isLayoutOnly(keyIterator.nextKey())) {
      return false;
    }
  }
  return true;
}
 
Example 10
Project: react-native-ibeacon-android   File: NativeViewHierarchyOptimizer.java   View source code 6 votes vote down vote up
private static boolean isLayoutOnlyAndCollapsable(@Nullable ReactStylesDiffMap props) {
  if (props == null) {
    return true;
  }

  if (props.hasKey(ViewProps.COLLAPSABLE) && !props.getBoolean(ViewProps.COLLAPSABLE, true)) {
    return false;
  }

  ReadableMapKeySetIterator keyIterator = props.mBackingMap.keySetIterator();
  while (keyIterator.hasNextKey()) {
    if (!ViewProps.isLayoutOnly(keyIterator.nextKey())) {
      return false;
    }
  }
  return true;
}
 
Example 11
Project: react-native-twilio-ip-messaging   File: RCTConvert.java   View source code 6 votes vote down vote up
public static HashMap<String, Object> readableMapToHashMap(ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }
    HashMap map = new HashMap<String, Object>();
    ReadableMapKeySetIterator keySetIterator = readableMap.keySetIterator();
    while (keySetIterator.hasNextKey()) {
        String key = keySetIterator.nextKey();
        ReadableType type = readableMap.getType(key);
        switch(type) {
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                HashMap<String, Object> attributes = new RCTConvert().readableMapToHashMap(readableMap.getMap(key));
                map.put(key, attributes);
                break;
            default:
                // do nothing
        }
    }
    return map;
}
 
Example 12
Project: react-native-box-loaders   File: NativeViewHierarchyOptimizer.java   View source code 6 votes vote down vote up
private static boolean isLayoutOnlyAndCollapsable(@Nullable ReactStylesDiffMap props) {
  if (props == null) {
    return true;
  }

  if (props.hasKey(ViewProps.COLLAPSABLE) && !props.getBoolean(ViewProps.COLLAPSABLE, true)) {
    return false;
  }

  ReadableMapKeySetIterator keyIterator = props.mBackingMap.keySetIterator();
  while (keyIterator.hasNextKey()) {
    if (!ViewProps.isLayoutOnly(keyIterator.nextKey())) {
      return false;
    }
  }
  return true;
}
 
Example 13
Project: react-native-flurry-analytics   File: FlurryAnalyticsModule.java   View source code 6 votes vote down vote up
private static Map<String, String> toMap(@Nullable ReadableMap readableMap) {
  if (readableMap == null) {
    return null;
  }

  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
  if (!iterator.hasNextKey()) {
    return null;
  }

  Map<String, String> result = new HashMap<>();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    result.put(key, readableMap.getString(key));
  }

  return result;
}
 
Example 14
Project: Ironman   File: NativeViewHierarchyOptimizer.java   View source code 6 votes vote down vote up
private static boolean isLayoutOnlyAndCollapsable(@Nullable ReactStylesDiffMap props) {
  if (props == null) {
    return true;
  }

  if (props.hasKey(ViewProps.COLLAPSABLE) && !props.getBoolean(ViewProps.COLLAPSABLE, true)) {
    return false;
  }

  ReadableMapKeySetIterator keyIterator = props.mBackingMap.keySetIterator();
  while (keyIterator.hasNextKey()) {
    if (!ViewProps.isLayoutOnly(keyIterator.nextKey())) {
      return false;
    }
  }
  return true;
}
 
Example 15
Project: Ironman   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testMapIterateOverMapWithBasicTypes() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  Set<String> keys = new HashSet<String>();
  while (mapIterator.hasNextKey()) {
    keys.add(mapIterator.nextKey());
  }

  Set<String> expectedKeys = new HashSet<String>(
      Arrays.asList("stringKey", "doubleKey", "intKey", "booleanKey", "nullKey"));
  assertEquals(keys, expectedKeys);
}
 
Example 16
Project: Ironman   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testMapIterateOverNestedMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnNestedMap();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator firstLevelIterator = map.keySetIterator();
  String firstLevelKey = firstLevelIterator.nextKey();
  assertEquals(firstLevelKey, "weHaveToGoDeeper");

  ReadableNativeMap secondMap = map.getMap("weHaveToGoDeeper");
  ReadableMapKeySetIterator secondLevelIterator = secondMap.keySetIterator();
  String secondLevelKey = secondLevelIterator.nextKey();
  assertEquals(secondLevelKey, "inception");
  assertTrue(secondMap.getBoolean(secondLevelKey));
}
 
Example 17
Project: mia-tracking   File: MixpanelTrackerModule.java   View source code 6 votes vote down vote up
@NonNull
private JSONObject createJsonObject(final ReadableMap properties) throws JSONException {
    JSONObject jsonPayload = new JSONObject();
    for (final ReadableMapKeySetIterator iterator = properties.keySetIterator(); iterator.hasNextKey();) {
        final String key = iterator.nextKey();
        final ReadableType type = properties.getType(key);
        switch (type) {
            case String: jsonPayload.put(key, properties.getString(key)); break;
            case Array: jsonPayload.put(key, properties.getArray(key)); break;
            case Boolean: jsonPayload.put(key, properties.getBoolean(key)); break;
            case Number: jsonPayload.put(key, properties.getDouble(key)); break;
            case Map: jsonPayload.put(key, createJsonObject(properties.getMap(key))); break;
        }
        jsonPayload.put(key, type);
    }
    return jsonPayload;
}
 
Example 18
Project: react-native-oauth   File: OAuthManagerProviders.java   View source code 6 votes vote down vote up
static private OAuthRequest addParametersToRequest(
  OAuthRequest request,
  final String access_token,
  @Nullable final ReadableMap params
) {
  if (params != null && params.hasKey("params")) {
    ReadableMapKeySetIterator iterator = params.keySetIterator();
    while (iterator.hasNextKey()) {
      String key = iterator.nextKey();
      ReadableType readableType = params.getType(key);
      switch(readableType) {
        case String:
          String val = params.getString(key);
          // String escapedVal = Uri.encode(val);
          if (val.equals("access_token")) {
            val = access_token;
          }
          request.addParameter(key, val);
          break;
        default:
          throw new IllegalArgumentException("Could not read object with key: " + key);
      }
    }
  }
  return request;
}
 
Example 19
Project: react-native-smooch   File: ReactNativeSmooch.java   View source code 6 votes vote down vote up
private Map<String, Object> getUserProperties(ReadableMap properties) {
    ReadableMapKeySetIterator iterator = properties.keySetIterator();
    Map<String, Object> userProperties = new HashMap<>();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = properties.getType(key);
        if (type == ReadableType.Boolean) {
            userProperties.put(key, properties.getBoolean(key));
        } else if (type == ReadableType.Number) {
            userProperties.put(key, properties.getDouble(key));
        } else if (type == ReadableType.String) {
            userProperties.put(key, properties.getString(key));
        }
    }

    return userProperties;
}
 
Example 20
Project: react-native-webrtc   File: WebRTCModule.java   View source code 5 votes vote down vote up
/**
 * Parses a constraint set specified in the form of a JavaScript object into
 * a specific <tt>List</tt> of <tt>MediaConstraints.KeyValuePair</tt>s.
 *
 * @param src The constraint set in the form of a JavaScript object to
 * parse.
 * @param dst The <tt>List</tt> of <tt>MediaConstraints.KeyValuePair</tt>s
 * into which the specified <tt>src</tt> is to be parsed.
 */
private void parseConstraints(
        ReadableMap src,
        List<MediaConstraints.KeyValuePair> dst) {
    ReadableMapKeySetIterator keyIterator = src.keySetIterator();

    while (keyIterator.hasNextKey()) {
        String key = keyIterator.nextKey();
        String value = ReactBridgeUtil.getMapStrValue(src, key);

        dst.add(new MediaConstraints.KeyValuePair(key, value));
    }
}
 
Example 21
Project: react-native-mssql   File: MapUtil.java   View source code 5 votes vote down vote up
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
  JSONObject jsonObject = new JSONObject();

  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    ReadableType type = readableMap.getType(key);

    switch (type) {
      case Null:
        jsonObject.put(key, null);
        break;
      case Boolean:
        jsonObject.put(key, readableMap.getBoolean(key));
        break;
      case Number:
        jsonObject.put(key, readableMap.getDouble(key));
        break;
      case String:
        jsonObject.put(key, readableMap.getString(key));
        break;
      case Map:
        jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
        break;
      case Array:
        jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
        break;
    }
  }

  return jsonObject;
}
 
Example 22
Project: react-native-mssql   File: MapUtil.java   View source code 5 votes vote down vote up
public static Map<String, Object> toMap(ReadableMap readableMap) {
  Map<String, Object> map = new HashMap<>();
  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    ReadableType type = readableMap.getType(key);

    switch (type) {
      case Null:
        map.put(key, null);
        break;
      case Boolean:
        map.put(key, readableMap.getBoolean(key));
        break;
      case Number:
        map.put(key, readableMap.getDouble(key));
        break;
      case String:
        map.put(key, readableMap.getString(key));
        break;
      case Map:
        map.put(key, MapUtil.toMap(readableMap.getMap(key)));
        break;
      case Array:
        map.put(key, ArrayUtil.toArray(readableMap.getArray(key)));
        break;
    }
  }

  return map;
}
 
Example 23
Project: react-native-nfc-manager   File: JsonConvert.java   View source code 5 votes vote down vote up
public static JSONObject reactToJSON(ReadableMap readableMap) throws JSONException {
    JSONObject jsonObject = new JSONObject();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    while(iterator.hasNextKey()){
        String key = iterator.nextKey();
        ReadableType valueType = readableMap.getType(key);
        switch (valueType){
            case Null:
                jsonObject.put(key,JSONObject.NULL);
                break;
            case Boolean:
                jsonObject.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                try {
                    jsonObject.put(key, readableMap.getInt(key));
                } catch(Exception e) {
                    jsonObject.put(key, readableMap.getDouble(key));
                }
                break;
            case String:
                jsonObject.put(key, readableMap.getString(key));
                break;
            case Map:
                jsonObject.put(key, reactToJSON(readableMap.getMap(key)));
                break;
            case Array:
                jsonObject.put(key, reactToJSON(readableMap.getArray(key)));
                break;
        }
    }

    return jsonObject;
}
 
Example 24
Project: react-native-simple-download-manager   File: Downloader.java   View source code 5 votes vote down vote up
public DownloadManager.Request createRequest(String url, ReadableMap headers, ReadableMap requestConfig) {
    String downloadTitle = requestConfig.getString("downloadTitle");
    String downloadDescription = requestConfig.getString("downloadTitle");
    String saveAsName = requestConfig.getString("saveAsName");
    Boolean allowedInRoaming = requestConfig.getBoolean("allowedInRoaming");
    Boolean allowedInMetered = requestConfig.getBoolean("allowedInMetered");
    Boolean showInDownloads = requestConfig.getBoolean("showInDownloads");

    Uri downloadUri = Uri.parse(url);
    DownloadManager.Request request = new DownloadManager.Request(downloadUri);

    ReadableMapKeySetIterator iterator = headers.keySetIterator();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        request.addRequestHeader(key, headers.getString(key));
    }

    request.setTitle(downloadTitle);
    request.setDescription(downloadDescription);
    request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, saveAsName);
    request.setAllowedOverRoaming(allowedInRoaming);
    request.setAllowedOverMetered(allowedInMetered);
    request.setVisibleInDownloadsUi(showInDownloads);
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    return request;
}
 
Example 25
Project: react-native-batch   File: MapUtil.java   View source code 5 votes vote down vote up
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
    JSONObject jsonObject = new JSONObject();

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                jsonObject.put(key, null);
                break;
            case Boolean:
                jsonObject.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                jsonObject.put(key, readableMap.getDouble(key));
                break;
            case String:
                jsonObject.put(key, readableMap.getString(key));
                break;
            case Map:
                jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
                break;
            case Array:
                jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
                break;
        }
    }

    return jsonObject;
}
 
Example 26
Project: react-native-batch   File: MapUtil.java   View source code 5 votes vote down vote up
public static Map<String, Object> toMap(ReadableMap readableMap) {
    Map<String, Object> map = new HashMap<>();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                map.put(key, null);
                break;
            case Boolean:
                map.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                map.put(key, readableMap.getDouble(key));
                break;
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                map.put(key, MapUtil.toMap(readableMap.getMap(key)));
                break;
            case Array:
                map.put(key, ArrayUtil.toArray(readableMap.getArray(key)));
                break;
        }
    }

    return map;
}
 
Example 27
Project: RNNavitiaSDK   File: MapUtil.java   View source code 5 votes vote down vote up
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
    JSONObject jsonObject = new JSONObject();

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                jsonObject.put(key, null);
                break;
            case Boolean:
                jsonObject.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                jsonObject.put(key, readableMap.getDouble(key));
                break;
            case String:
                jsonObject.put(key, readableMap.getString(key));
                break;
            case Map:
                jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
                break;
            case Array:
                jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
                break;
        }
    }

    return jsonObject;
}
 
Example 28
Project: RNNavitiaSDK   File: MapUtil.java   View source code 5 votes vote down vote up
public static Map<String, Object> toMap(ReadableMap readableMap) {
    Map<String, Object> map = new HashMap<>();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                map.put(key, null);
                break;
            case Boolean:
                map.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                map.put(key, readableMap.getDouble(key));
                break;
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                map.put(key, MapUtil.toMap(readableMap.getMap(key)));
                break;
            case Array:
                map.put(key, ArrayUtil.toArray(readableMap.getArray(key)));
                break;
        }
    }

    return map;
}
 
Example 29
Project: rnrecord   File: SaveCommand.java   View source code 5 votes vote down vote up
private List<String> getPropKeys(ReadableMap props) {
    List<String> keys = new ArrayList<>();
    ReadableMapKeySetIterator iterator = props.keySetIterator();
    while(iterator.hasNextKey()) {
        keys.add(iterator.nextKey());
    }
    return keys;
}
 
Example 30
Project: rnrecord   File: FindCommand.java   View source code 5 votes vote down vote up
private List<String> getQueryKeys(ReadableMap query) {
    List<String> keys = new ArrayList<>();
    ReadableMapKeySetIterator iterator = query.keySetIterator();
    while(iterator.hasNextKey()) {
        keys.add(iterator.nextKey());
    }
    return keys;
}
 
Example 31
Project: rnrecord   File: UpdateCommand.java   View source code 5 votes vote down vote up
private List<String> getPropKeys(ReadableMap props) {
    List<String> keys = new ArrayList<>();
    ReadableMapKeySetIterator iterator = props.keySetIterator();
    while(iterator.hasNextKey()) {
        keys.add(iterator.nextKey());
    }
    return keys;
}
 
Example 32
Project: RNLearn_Project1   File: ReactWebViewManager.java   View source code 5 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
  if (source != null) {
    if (source.hasKey("html")) {
      String html = source.getString("html");
      if (source.hasKey("baseUrl")) {
        view.loadDataWithBaseURL(
            source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
      } else {
        view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
      }
      return;
    }
    if (source.hasKey("uri")) {
      String url = source.getString("uri");
      String previousUrl = view.getUrl();
      if (previousUrl != null && previousUrl.equals(url)) {
        return;
      }
      if (source.hasKey("method")) {
        String method = source.getString("method");
        if (method.equals(HTTP_METHOD_POST)) {
          byte[] postData = null;
          if (source.hasKey("body")) {
            String body = source.getString("body");
            try {
              postData = body.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
              postData = body.getBytes();
            }
          }
          if (postData == null) {
            postData = new byte[0];
          }
          view.postUrl(url, postData);
          return;
        }
      }
      HashMap<String, String> headerMap = new HashMap<>();
      if (source.hasKey("headers")) {
        ReadableMap headers = source.getMap("headers");
        ReadableMapKeySetIterator iter = headers.keySetIterator();
        while (iter.hasNextKey()) {
          String key = iter.nextKey();
          if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
            if (view.getSettings() != null) {
              view.getSettings().setUserAgentString(headers.getString(key));
            }
          } else {
            headerMap.put(key, headers.getString(key));
          }
        }
      }
      view.loadUrl(url, headerMap);
      return;
    }
  }
  view.loadUrl(BLANK_URL);
}
 
Example 33
Project: RNLearn_Project1   File: ReactOkHttpNetworkFetcher.java   View source code 5 votes vote down vote up
private Map<String, String> getHeaders(ReadableMap readableMap) {
  if (readableMap == null) {
      return null;
  }
  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
  Map<String, String> map = new HashMap<>();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    String value = readableMap.getString(key);
    map.put(key, value);
  }
  return map;
}
 
Example 34
Project: RNLearn_Project1   File: ViewManagerPropertyUpdater.java   View source code 5 votes vote down vote up
public static <T extends ViewManager, V extends View> void updateProps(
    T manager,
    V v,
    ReactStylesDiffMap props) {
  ViewManagerSetter<T, V> setter = findManagerSetter(manager.getClass());
  ReadableMap propMap = props.mBackingMap;
  ReadableMapKeySetIterator iterator = propMap.keySetIterator();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    setter.setProperty(manager, v, key, props);
  }
}
 
Example 35
Project: RNLearn_Project1   File: ViewManagerPropertyUpdater.java   View source code 5 votes vote down vote up
public static <T extends ReactShadowNode> void updateProps(T node, ReactStylesDiffMap props) {
  ShadowNodeSetter<T> setter = findNodeSetter(node.getClass());
  ReadableMap propMap = props.mBackingMap;
  ReadableMapKeySetIterator iterator = propMap.keySetIterator();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    setter.setProperty(node, key, props);
  }
}
 
Example 36
Project: RNLearn_Project1   File: StyleAnimatedNode.java   View source code 5 votes vote down vote up
StyleAnimatedNode(ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) {
  ReadableMap style = config.getMap("style");
  ReadableMapKeySetIterator iter = style.keySetIterator();
  mPropMapping = new HashMap<>();
  while (iter.hasNextKey()) {
    String propKey = iter.nextKey();
    int nodeIndex = style.getInt(propKey);
    mPropMapping.put(propKey, nodeIndex);
  }
  mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
}
 
Example 37
Project: RNLearn_Project1   File: PropsAnimatedNode.java   View source code 5 votes vote down vote up
PropsAnimatedNode(ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) {
  ReadableMap props = config.getMap("props");
  ReadableMapKeySetIterator iter = props.keySetIterator();
  mPropMapping = new HashMap<>();
  while (iter.hasNextKey()) {
    String propKey = iter.nextKey();
    int nodeIndex = props.getInt(propKey);
    mPropMapping.put(propKey, nodeIndex);
  }
  mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
}
 
Example 38
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 5 votes vote down vote up
public void testInvalidIteratorExceptionThrown() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  while (mapIterator.hasNextKey()) {
    mapIterator.nextKey();
  }
  assertInvalidIteratorExceptionThrown(mapIterator);
}
 
Example 39
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 5 votes vote down vote up
private static void assertInvalidIteratorExceptionThrown(
    ReadableMapKeySetIterator iterator) {
  boolean gotException = false;
  try {
    iterator.nextKey();
  } catch (InvalidIteratorException expected) {
    gotException = true;
  }

  assertTrue(gotException);
}
 
Example 40
Project: RNLearn_Project1   File: ReactOkHttpNetworkFetcher.java   View source code 5 votes vote down vote up
private Map<String, String> getHeaders(ReadableMap readableMap) {
  if (readableMap == null) {
      return null;
  }
  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
  Map<String, String> map = new HashMap<>();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    String value = readableMap.getString(key);
    map.put(key, value);
  }
  return map;
}