Java Code Examples for com.facebook.react.bridge.WritableMap.merge()

The following are Jave code examples for showing how to use merge() of the com.facebook.react.bridge.WritableMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   Source Code and License Vote up 5 votes
public void testMapMerging() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapForMerge1();
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapForMerge2();
  waitForBridgeAndUIIdle();

  List<ReadableMap> maps = mRecordingTestModule.getMapCalls();
  assertEquals(2, maps.size());

  WritableMap dest = new WritableNativeMap();
  dest.merge(maps.get(0));
  dest.merge(maps.get(1));

  assertTrue(dest.hasKey("a"));
  assertTrue(dest.hasKey("b"));
  assertTrue(dest.hasKey("c"));
  assertTrue(dest.hasKey("d"));
  assertTrue(dest.hasKey("e"));
  assertTrue(dest.hasKey("f"));
  assertTrue(dest.hasKey("newkey"));

  assertEquals("overwrite", dest.getString("a"));
  assertEquals(41, dest.getInt("b"));
  assertEquals("string", dest.getString("c"));
  assertEquals(77, dest.getInt("d"));
  assertTrue(dest.isNull("e"));
  assertEquals(3, dest.getArray("f").size());
  assertEquals("newvalue", dest.getString("newkey"));
}
 
Example 2
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   Source Code and License Vote up 5 votes
public void testMapAccessibleAfterMerge() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapForMerge1();
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapForMerge2();
  waitForBridgeAndUIIdle();

  List<ReadableMap> maps = mRecordingTestModule.getMapCalls();
  assertEquals(2, maps.size());

  WritableMap dest = new WritableNativeMap();
  dest.merge(maps.get(0));
  dest.merge(maps.get(1));

  ReadableMap source = maps.get(1);

  assertTrue(source.hasKey("a"));
  assertTrue(source.hasKey("d"));
  assertTrue(source.hasKey("e"));
  assertTrue(source.hasKey("f"));
  assertTrue(source.hasKey("newkey"));

  assertFalse(source.hasKey("b"));
  assertFalse(source.hasKey("c"));

  assertEquals("overwrite", source.getString("a"));
  assertEquals(77, source.getInt("d"));
  assertTrue(source.isNull("e"));
  assertEquals(3, source.getArray("f").size());
  assertEquals("newvalue", source.getString("newkey"));
}
 
Example 3
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   Source Code and License Vote up 5 votes
public void testMapMerging() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapForMerge1();
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapForMerge2();
  waitForBridgeAndUIIdle();

  List<ReadableMap> maps = mRecordingTestModule.getMapCalls();
  assertEquals(2, maps.size());

  WritableMap dest = new WritableNativeMap();
  dest.merge(maps.get(0));
  dest.merge(maps.get(1));

  assertTrue(dest.hasKey("a"));
  assertTrue(dest.hasKey("b"));
  assertTrue(dest.hasKey("c"));
  assertTrue(dest.hasKey("d"));
  assertTrue(dest.hasKey("e"));
  assertTrue(dest.hasKey("f"));
  assertTrue(dest.hasKey("newkey"));

  assertEquals("overwrite", dest.getString("a"));
  assertEquals(41, dest.getInt("b"));
  assertEquals("string", dest.getString("c"));
  assertEquals(77, dest.getInt("d"));
  assertTrue(dest.isNull("e"));
  assertEquals(3, dest.getArray("f").size());
  assertEquals("newvalue", dest.getString("newkey"));
}
 
Example 4
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   Source Code and License Vote up 5 votes
public void testMapAccessibleAfterMerge() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapForMerge1();
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapForMerge2();
  waitForBridgeAndUIIdle();

  List<ReadableMap> maps = mRecordingTestModule.getMapCalls();
  assertEquals(2, maps.size());

  WritableMap dest = new WritableNativeMap();
  dest.merge(maps.get(0));
  dest.merge(maps.get(1));

  ReadableMap source = maps.get(1);

  assertTrue(source.hasKey("a"));
  assertTrue(source.hasKey("d"));
  assertTrue(source.hasKey("e"));
  assertTrue(source.hasKey("f"));
  assertTrue(source.hasKey("newkey"));

  assertFalse(source.hasKey("b"));
  assertFalse(source.hasKey("c"));

  assertEquals("overwrite", source.getString("a"));
  assertEquals(77, source.getInt("d"));
  assertTrue(source.isNull("e"));
  assertEquals(3, source.getArray("f").size());
  assertEquals("newvalue", source.getString("newkey"));
}
 
Example 5
Project: react-native-geo-fence   File: GeofenceTransitionsIntentService.java   Source Code and License Vote up 4 votes
/**
 * Handles incoming intents.
 * @param intent sent by Location Services. This Intent is provided to Location
 *               Services (inside a PendingIntent) when addGeofences() is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        String errorMessage = GeofenceErrorMessages.getErrorString(this,
                geofencingEvent.getErrorCode());
        Log.e(TAG, errorMessage);
        return;
    }

    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();

    // Test that the reported transition was of interest.
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
            geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {

        // Get the geofences that were triggered. A single event can trigger multiple geofences.
        List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
        WritableArray writableArray = new WritableNativeArray();

        for (int i = 0; i < triggeringGeofences.size(); i++) {
            Geofence geofence = triggeringGeofences.get(i);
            String key = geofence.getRequestId();
            ReadableMap geofenceMap = getGeofenceFromKey(key);
            WritableMap writableMap = new WritableNativeMap();
            writableMap.merge(geofenceMap);
            writableMap.putString("transition", getTransitionString(geofenceTransition));
            writableArray.pushMap(writableMap);
        }

        // create final event emitter object argument
        WritableMap finalEventEmitterObject = new WritableNativeMap();
        finalEventEmitterObject.putArray("data", writableArray);
        finalEventEmitterObject.putString("event", "geofenceTrigger");

        SReactApplicationContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit("GeofenceEvent", finalEventEmitterObject);
    } else {
        // Log the error.
        Log.e(TAG, "Geofence transition error: invalid transition type " + geofenceTransition);
    }
}