com.facebook.react.bridge.ReadableNativeMap Java Examples

The following examples show how to use com.facebook.react.bridge.ReadableNativeMap. 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: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node, but its
 *     props will be overridden with the {@link ReadableMap} received by parameter.
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNodeWithNewProps(
    ReactShadowNode node, @Nullable ReadableNativeMap newProps) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNodeWithNewProps")
    .flush();
  try {
    ReactShadowNode clone = node.mutableCopyWithNewProps(node.getInstanceHandle(),
          newProps == null ? null : new ReactStylesDiffMap(newProps));
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example #2
Source File: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node, but its
 *     props will be overridden with the {@link ReadableMap} received by parameter and its
 *     children set will be empty.
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNodeWithNewChildrenAndProps(
    ReactShadowNode node, ReadableNativeMap newProps) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNodeWithNewChildrenAndProps")
    .flush();
  try {
    ReactShadowNode clone =
        node.mutableCopyWithNewChildrenAndProps(node.getInstanceHandle(),
            newProps == null ? null : new ReactStylesDiffMap(newProps));
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example #3
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 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
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 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
Source File: ApiMagnetReact.java    From magnet-client with Mozilla Public License 2.0 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
Source File: FabricUIManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
/** Creates a new {@link ReactShadowNode} */
@Nullable
@DoNotStrip
public ReactShadowNode createNode(
    int reactTag, String viewName, int rootTag, ReadableNativeMap props, long eventTarget) {
  if (DEBUG) {
    FLog.d(TAG, "createNode \n\ttag: " + reactTag +
        "\n\tviewName: " + viewName +
        "\n\trootTag: " + rootTag +
        "\n\tprops: " + props);
  }
  try {
    ViewManager viewManager = mViewManagerRegistry.get(viewName);
    ReactShadowNode node = viewManager.createShadowNodeInstance(mReactApplicationContext);
    ReactShadowNode rootNode = getRootNode(rootTag);
    node.setRootTag(rootNode.getReactTag());
    node.setViewClassName(viewName);
    node.setInstanceHandle(eventTarget);
    node.setReactTag(reactTag);
    node.setThemedContext(rootNode.getThemedContext());

    ReactStylesDiffMap styles = updateProps(node, props);

    if (!node.isVirtual()) {
      mUIViewOperationQueue.enqueueCreateView(
          rootNode.getThemedContext(), reactTag, viewName, styles);
    }
    return node;
  } catch (Throwable t) {
    handleException(getRootNode(rootTag), t);
    return null;
  }
}
 
Example #7
Source File: FabricUIManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
private ReactStylesDiffMap updateProps(ReactShadowNode node, @Nullable ReadableNativeMap props) {
  ReactStylesDiffMap styles = null;
  if (props != null) {
    styles = new ReactStylesDiffMap(props);
    node.updateProperties(styles);
  }
  return styles;
}
 
Example #8
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 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 #9
Source File: FabricUIManagerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Test
public void testCloneNodeWithNewProps() {
  ReactShadowNode node = createViewNode();
  ReadableNativeMap props = null; // TODO(ayc): Figure out how to create a Native map from tests.

  ReactShadowNode clonedNode = mFabricUIManager.cloneNodeWithNewProps(node, props);
}
 
Example #10
Source File: FabricUIManagerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Test
public void testCloneNodeWithNewChildrenAndProps() {
  ReactShadowNode node = createViewNode();
  ReadableNativeMap props = null;

  ReactShadowNode clonedNode = mFabricUIManager.cloneNodeWithNewChildrenAndProps(node, props);

  assertThat(clonedNode.getChildCount()).isZero();
}
 
Example #11
Source File: ApiMagnetReact.java    From magnet-client with Mozilla Public License 2.0 5 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;
}