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

The following are top voted examples for showing how to use com.facebook.react.bridge.ReadableNativeMap. 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: 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 3
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 4
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 5
Project: magnet-client   File: ApiMagnetReact.java   View source code 6 votes vote down vote up
@ReactMethod
public void delete(String path, ReadableMap data, final Promise promise) {
    Log.d(TAG, "delete: " + path);
    HashMap<String,Object> map = ((ReadableNativeMap) data).toHashMap();

    mApiMagnet.delete(path, map, new Api.Callback() {
        @Override
        public void resolve(Object result) {
            promise.resolve(toReactArgument(result));
        }

        @Override
        public void reject(String error) {
            promise.reject(error, error);
        }
    });
}
 
Example 6
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 7
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 8
Project: react-native-sentry   File: RNSentryModule.java   View source code 6 votes vote down vote up
@ReactMethod
public void captureBreadcrumb(ReadableMap breadcrumb) {
    logger.info(String.format("captureEvent '%s'", breadcrumb));

    BreadcrumbBuilder breadcrumbBuilder = new BreadcrumbBuilder();
    if (breadcrumb.hasKey("category")) {
        breadcrumbBuilder.setCategory(breadcrumb.getString("category"));
    }
    if (breadcrumb.hasKey("data") && breadcrumb.getMap("data") != null) {
        Map<String, String> newData = new HashMap<>();
        for (Map.Entry<String, Object> data : ((ReadableNativeMap)breadcrumb.getMap("data")).toHashMap().entrySet()) {
            newData.put(data.getKey(), data.getValue() != null ? data.getValue().toString() : null);
        }
        breadcrumbBuilder.setData(newData);
    }
    breadcrumbBuilder.setLevel(breadcrumbLevel((ReadableNativeMap)breadcrumb));

    if (breadcrumb.hasKey("message")) {
        breadcrumbBuilder.setMessage(breadcrumb.getString("message"));
    }
    Sentry.record(breadcrumbBuilder.build());
}
 
Example 9
Project: react-native-sentry   File: RNSentryModule.java   View source code 6 votes vote down vote up
@NonNull
private UserBuilder getUserBuilder(ReadableMap user) {
    UserBuilder userBuilder = new UserBuilder();
    if (user.hasKey("email")) {
        userBuilder.setEmail(user.getString("email"));
    }
    if (user.hasKey("userID")) {
        userBuilder.setId(user.getString("userID"));
    } else if (user.hasKey("userId")) {
        userBuilder.setId(user.getString("userId"));
    } else if (user.hasKey("id")) {
        userBuilder.setId(user.getString("id"));
    }
    if (user.hasKey("username")) {
        userBuilder.setUsername(user.getString("username"));
    }
    if (user.hasKey("extra")) {
        userBuilder.setData(((ReadableNativeMap)user.getMap("extra")).toHashMap());
    }
    return userBuilder;
}
 
Example 10
Project: react-native-sentry   File: RNSentryModule.java   View source code 6 votes vote down vote up
private Breadcrumb.Level breadcrumbLevel(ReadableNativeMap breadcrumb) {
    String level = "";
    if (breadcrumb.hasKey("level")) {
        level = breadcrumb.getString("level");
    }
    switch (level) {
        case "critical":
            return Breadcrumb.Level.CRITICAL;
        case "warning":
            return Breadcrumb.Level.WARNING;
        case "info":
            return Breadcrumb.Level.INFO;
        case "debug":
            return Breadcrumb.Level.DEBUG;
        default:
            return Breadcrumb.Level.ERROR;
    }
}
 
Example 11
Project: react-native-sentry   File: RNSentryModule.java   View source code 6 votes vote down vote up
private Event.Level eventLevel(ReadableNativeMap event) {
    String level = "";
    if (event.hasKey("level")) {
        level = event.getString("level");
    }
    switch (level) {
        case "fatal":
            return Event.Level.FATAL;
        case "warning":
            return Event.Level.WARNING;
        case "info":
            return Event.Level.INFO;
        case "debug":
            return Event.Level.DEBUG;
        default:
            return Event.Level.ERROR;
    }
}
 
Example 12
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 13
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 14
Project: react-native-apptentive-module   File: RNApptentiveModule.java   View source code 5 votes vote down vote up
@ReactMethod
public void presentMessageCenterWithCustomData(ReadableMap customData, final Promise promise)
{
	if (customData == null)
	{
		this.presentMessageCenter(promise);
		return;
	}
	if (!_initialised)
	{
		promise.reject(APPTENTIVE, "Apptentive is not initialised");
		return;
	}
	if (!Apptentive.canShowMessageCenter())
	{
		promise.reject(APPTENTIVE, "Apptentive message center can't be shown");
		return;
	}
	if (!(customData instanceof ReadableNativeMap))
	{
		promise.reject(APPTENTIVE, "Apptentive can't handle this customData");
		return;
	}

	ReadableNativeMap nativeMap = (ReadableNativeMap) customData;
	final HashMap<String, Object> hashMap = nativeMap.toHashMap();

	Handler handler = new Handler(_application.getMainLooper());
	Runnable runnable = new Runnable()
	{
		@Override
		public void run()
		{
			boolean shown = Apptentive.showMessageCenter(getReactApplicationContext(), hashMap);
			promise.resolve(shown);
		}
	};
	handler.post(runnable);
}
 
Example 15
Project: Ironman   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 16
Project: rn-notification   File: NotificationAttributes.java   View source code 5 votes vote down vote up
public static NotificationAttributes fromReadableMap(ReadableMap m) {
    NotificationAttributes r = new NotificationAttributes();

    if (m.hasKey("subject")) r.subject = m.getString("subject");
    if (m.hasKey("message")) r.message = m.getString("message");
    if (m.hasKey("smallIcon")) r.smallIcon = m.getString("smallIcon");
    if (m.hasKey("priority")) r.priority = m.getString("priority");
    if (m.hasKey("sound")) r.sound = m.getString("sound");
    if (m.hasKey("vibrate")) r.vibrate = m.getString("vibrate");
    if (m.hasKey("lights")) r.lights = m.getString("lights");
    if (m.hasKey("color")) r.color = m.getString("color");

    if (m.hasKey("payload")) {
        if (m.getType("payload") == ReadableType.Map) {
            // Serialize payload as JSON
            ReadableMap payloadRM = m.getMap("payload");
            HashMap<String, Object> payloadM = ((ReadableNativeMap)payloadRM).toHashMap();
            JSONObject payloadJson = new JSONObject(payloadM);

            r.payload = payloadJson.toString();
        } else {
            r.payload = m.getString("payload");
        }
    }

    return r;
}
 
Example 17
Project: react-native-mopub   File: MoPubBannerManager.java   View source code 4 votes vote down vote up
@ReactProp(name = "localExtras")
public void setLocalExtras(RNMoPubBanner view, @Nullable  ReadableMap localExtras){
    view.setLocalExtras(((ReadableNativeMap) localExtras).toHashMap());
}
 
Example 18
Project: magnet-client   File: ApiMagnetReact.java   View source code 4 votes vote down vote up
static private Object fromReactArgument(Object object) {
    if (object instanceof ReadableNativeArray) return ((ReadableNativeArray) object).toArrayList();
    else if (object instanceof ReadableNativeMap) return ((ReadableNativeMap) object).toHashMap();
    else return null;
}