Java 类com.facebook.react.bridge.ReadableNativeMap 实例源码

项目:RNLearn_Project1    文件:CatalystNativeJSToJavaParametersTestCase.java   
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);
}
项目:RNLearn_Project1    文件:CatalystNativeJSToJavaParametersTestCase.java   
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));
}
项目:RNLearn_Project1    文件:CatalystNativeJSToJavaParametersTestCase.java   
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);
}
项目:RNLearn_Project1    文件:CatalystNativeJSToJavaParametersTestCase.java   
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));
}
项目:magnet-client    文件:ApiMagnetReact.java   
@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);
        }
    });
}
项目:Ironman    文件:CatalystNativeJSToJavaParametersTestCase.java   
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);
}
项目:Ironman    文件:CatalystNativeJSToJavaParametersTestCase.java   
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));
}
项目:react-native-sentry    文件:RNSentryModule.java   
@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());
}
项目:react-native-sentry    文件:RNSentryModule.java   
@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;
}
项目:react-native-sentry    文件:RNSentryModule.java   
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;
    }
}
项目:react-native-sentry    文件:RNSentryModule.java   
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;
    }
}
项目:RNLearn_Project1    文件:CatalystNativeJSToJavaParametersTestCase.java   
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);
}
项目:RNLearn_Project1    文件:CatalystNativeJSToJavaParametersTestCase.java   
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);
}
项目:react-native-apptentive-module    文件:RNApptentiveModule.java   
@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);
}
项目:Ironman    文件:CatalystNativeJSToJavaParametersTestCase.java   
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);
}
项目:rn-notification    文件:NotificationAttributes.java   
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;
}
项目:react-native-mopub    文件:MoPubBannerManager.java   
@ReactProp(name = "localExtras")
public void setLocalExtras(RNMoPubBanner view, @Nullable  ReadableMap localExtras){
    view.setLocalExtras(((ReadableNativeMap) localExtras).toHashMap());
}
项目:magnet-client    文件:ApiMagnetReact.java   
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;
}