Java Code Examples for com.facebook.react.bridge.ReadableMapKeySetIterator#hasNextKey()
The following examples show how to use
com.facebook.react.bridge.ReadableMapKeySetIterator#hasNextKey() .
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: CatalystNativeJSToJavaParametersTestCase.java From react-native-GPay with MIT License | 6 votes |
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 2
Source File: OAuthManagerProviders.java From react-native-oauth with MIT License | 6 votes |
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 3
Source File: NativeViewHierarchyOptimizer.java From react-native-GPay with MIT License | 6 votes |
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 4
Source File: FlurryModule.java From react-native-flurry-sdk with Apache License 2.0 | 6 votes |
private static Map<String, String> toMap(final 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 5
Source File: OAuthManagerModule.java From react-native-oauth with MIT License | 5 votes |
@ReactMethod public void configureProvider( final String providerName, final ReadableMap params, @Nullable final Callback onComplete ) { Log.i(TAG, "configureProvider for " + providerName); // Save callback url for later String callbackUrlStr = params.getString("callback_url"); _callbackUrls.add(callbackUrlStr); Log.d(TAG, "Added callback url " + callbackUrlStr + " for providler " + providerName); // Keep configuration map HashMap<String, Object> cfg = new HashMap<String,Object>(); 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); cfg.put(key, val); break; default: throw new IllegalArgumentException("Could not read object with key: " + key); } } _configuration.put(providerName, cfg); onComplete.invoke(null, true); }
Example 6
Source File: ReactNativeJson.java From react-native-fcm with MIT License | 5 votes |
public static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException { JSONObject object = new JSONObject(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); switch (readableMap.getType(key)) { case Null: object.put(key, JSONObject.NULL); break; case Boolean: object.put(key, readableMap.getBoolean(key)); break; case Number: object.put(key, readableMap.getDouble(key)); break; case String: object.put(key, readableMap.getString(key)); break; case Map: object.put(key, convertMapToJson(readableMap.getMap(key))); break; case Array: object.put(key, convertArrayToJson(readableMap.getArray(key))); break; } } return object; }
Example 7
Source File: RNDefaultPreferenceModule.java From react-native-default-preference with MIT License | 5 votes |
@ReactMethod public void setMultiple(ReadableMap data, Promise promise) { SharedPreferences.Editor editor = getEditor(); ReadableMapKeySetIterator iter = data.keySetIterator(); while(iter.hasNextKey()) { String key = iter.nextKey(); editor.putString(key, data.getString(key)).commit(); } promise.resolve(null); }
Example 8
Source File: ViewManagerPropertyUpdater.java From react-native-GPay with MIT License | 5 votes |
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 9
Source File: ViewManagerPropertyUpdater.java From react-native-GPay with MIT License | 5 votes |
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 10
Source File: DefaultNavigationImplementation.java From native-navigation with MIT License | 5 votes |
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; }
Example 11
Source File: IntercomModule.java From react-native-intercom with MIT License | 5 votes |
private Map<String, Object> recursivelyDeconstructReadableMap(ReadableMap readableMap) { ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); Map<String, Object> deconstructedMap = new HashMap<>(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType type = readableMap.getType(key); switch (type) { case Null: deconstructedMap.put(key, null); break; case Boolean: deconstructedMap.put(key, readableMap.getBoolean(key)); break; case Number: deconstructedMap.put(key, readableMap.getDouble(key)); break; case String: deconstructedMap.put(key, readableMap.getString(key)); break; case Map: deconstructedMap.put(key, recursivelyDeconstructReadableMap(readableMap.getMap(key))); break; case Array: deconstructedMap.put(key, recursivelyDeconstructReadableArray(readableMap.getArray(key))); break; default: throw new IllegalArgumentException("Could not convert object with key: " + key + "."); } } return deconstructedMap; }
Example 12
Source File: RNUtils.java From react-native-batch-push with MIT License | 5 votes |
@Nullable public static BatchEventData convertSerializedEventDataToEventData(@Nullable ReadableMap serializedEventData) { if (serializedEventData == null) { return null; } BatchEventData batchEventData = new BatchEventData(); ReadableArray tags = serializedEventData.getArray("tags"); for (int i = 0; i < tags.size(); i++) { batchEventData.addTag(tags.getString(i)); } ReadableMap attributes = serializedEventData.getMap("attributes"); ReadableMapKeySetIterator iterator = attributes.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableMap valueMap = attributes.getMap(key); String type = valueMap.getString("type"); if ("string".equals(type)) { batchEventData.put(key, valueMap.getString("value")); } else if ("boolean".equals(type)) { batchEventData.put(key, valueMap.getBoolean("value")); } else if ("integer".equals(type)) { batchEventData.put(key, valueMap.getDouble("value")); } else if ("float".equals(type)) { batchEventData.put(key, valueMap.getDouble("value")); } else { Log.e("RNBatchPush", "Invalid parameter : Unknown event_data.attributes type (" + type + ")"); } } return batchEventData; }
Example 13
Source File: PjActions.java From react-native-pjsip with GNU General Public License v3.0 | 5 votes |
private static Map<String, Object> formatMap(ReadableMap map) { Map<String, Object> value = new HashMap<>(); ReadableMapKeySetIterator mapIt = map.keySetIterator(); while (mapIt.hasNextKey()) { String mapKey = mapIt.nextKey(); switch (map.getType(mapKey)) { case Null: value.put(mapKey, null); break; case String: value.put(mapKey, map.getString(mapKey)); break; case Number: value.put(mapKey, map.getInt(mapKey)); break; case Boolean: value.put(mapKey, map.getBoolean(mapKey)); break; case Array: value.put(mapKey, map.getArray(mapKey).toArrayList()); break; case Map: value.put(mapKey, formatMap(map.getMap(mapKey))); break; default: Log.w(TAG, "Unable to put extra information for intent: unknown type \""+ map.getType(mapKey) +"\""); break; } } return value; }
Example 14
Source File: FIRMessagingModule.java From react-native-fcm with MIT License | 5 votes |
@ReactMethod public void send(String senderId, ReadableMap payload) throws Exception { FirebaseMessaging fm = FirebaseMessaging.getInstance(); RemoteMessage.Builder message = new RemoteMessage.Builder(senderId + "@gcm.googleapis.com") .setMessageId(UUID.randomUUID().toString()); ReadableMapKeySetIterator iterator = payload.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); String value = getStringFromReadableMap(payload, key); message.addData(key, value); } fm.send(message.build()); }
Example 15
Source File: MapUtil.java From Instabug-React-Native with MIT License | 5 votes |
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 16
Source File: MapUtil.java From vinci with Apache License 2.0 | 5 votes |
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 17
Source File: ReactWebViewManager.java From react-native-GPay with MIT License | 4 votes |
@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 18
Source File: RNPushNotificationAttributes.java From react-native-push-notification-CE with MIT License | 4 votes |
/** * User to find notifications: * <p> * https://github.com/facebook/react-native/blob/master/Libraries/PushNotificationIOS/RCTPushNotificationManager.m#L294 * * @param userInfo map of fields to match * @return true all fields in userInfo object match, false otherwise */ public boolean matches(ReadableMap userInfo) { Bundle bundle = toBundle(); ReadableMapKeySetIterator iterator = userInfo.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); if (!bundle.containsKey(key)) return false; switch (userInfo.getType(key)) { case Null: { if (bundle.get(key) != null) return false; break; } case Boolean: { if (userInfo.getBoolean(key) != bundle.getBoolean(key)) return false; break; } case Number: { if ((userInfo.getDouble(key) != bundle.getDouble(key)) && (userInfo.getInt(key) != bundle.getInt(key))) return false; break; } case String: { if (!userInfo.getString(key).equals(bundle.getString(key))) return false; break; } case Map: return false;//there are no maps in the bundle case Array: return false;//there are no arrays in the bundle } } return true; }
Example 19
Source File: RNPushNotificationAttributes.java From react-native-push-notification with MIT License | 4 votes |
/** * User to find notifications: * <p> * * @param userInfo map of fields to match * @return true all fields in userInfo object match, false otherwise */ public boolean matches(ReadableMap userInfo) { Bundle bundle = toBundle(); ReadableMapKeySetIterator iterator = userInfo.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); if (!bundle.containsKey(key)) return false; switch (userInfo.getType(key)) { case Null: { if (bundle.get(key) != null) return false; break; } case Boolean: { if (userInfo.getBoolean(key) != bundle.getBoolean(key)) return false; break; } case Number: { if ((userInfo.getDouble(key) != bundle.getDouble(key)) && (userInfo.getInt(key) != bundle.getInt(key))) return false; break; } case String: { if (!userInfo.getString(key).equals(bundle.getString(key))) return false; break; } case Map: return false;//there are no maps in the bundle case Array: return false;//there are no arrays in the bundle } } return true; }
Example 20
Source File: TwilioVoiceModule.java From react-native-twilio-programmable-voice with MIT License | 4 votes |
@ReactMethod public void connect(ReadableMap params) { if (BuildConfig.DEBUG) { Log.d(TAG, "connect params: "+params); } WritableMap errParams = Arguments.createMap(); if (accessToken == null) { errParams.putString("err", "Invalid access token"); eventManager.sendEvent(EVENT_DEVICE_NOT_READY, errParams); return; } if (params == null) { errParams.putString("err", "Invalid parameters"); eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams); return; } else if (!params.hasKey("To")) { errParams.putString("err", "Invalid To parameter"); eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams); return; } toNumber = params.getString("To"); if (params.hasKey("ToName")) { toName = params.getString("ToName"); } twiMLParams.clear(); ReadableMapKeySetIterator iterator = params.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType readableType = params.getType(key); switch (readableType) { case Null: twiMLParams.put(key, ""); break; case Boolean: twiMLParams.put(key, String.valueOf(params.getBoolean(key))); break; case Number: // Can be int or double. twiMLParams.put(key, String.valueOf(params.getDouble(key))); break; case String: twiMLParams.put(key, params.getString(key)); break; default: Log.d(TAG, "Could not convert with key: " + key + "."); break; } } activeCall = Voice.call(getReactApplicationContext(), accessToken, twiMLParams, callListener); }