Java Code Examples for com.facebook.react.uimanager.ReactShadowNode#mutableCopy()

The following examples show how to use com.facebook.react.uimanager.ReactShadowNode#mutableCopy() . 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,
 *     including its children set (note that the children nodes will not be cloned).
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNode(ReactShadowNode node) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNode \n\tnode: " + node);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNode")
    .flush();
  try {
    ReactShadowNode clone = node.mutableCopy(node.getInstanceHandle());
    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
/**
 * Appends the child {@link ReactShadowNode} to the children set of the parent {@link
 * ReactShadowNode}.
 */
@Nullable
@DoNotStrip
public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
  if (DEBUG) {
    FLog.d(TAG, "appendChild \n\tparent: " + parent + "\n\tchild: " + child);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.appendChild")
    .flush();
  try {
    // If the child to append was already committed (child.isSealed()),
    // then we add a mutation of it. In the future this will be performed by FabricJS / Fiber.
    //TODO: T27926878 avoid cloning shared child
    if (child.isSealed()) {
      child = child.mutableCopy(child.getInstanceHandle());
    }
    parent.addChildAt(child, parent.getChildCount());
  } catch (Throwable t) {
    handleException(parent, t);
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 3
Source File: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Updates the root view size and re-render the RN surface.
 *
 * //TODO: change synchronization to integrate with new #render loop.
 */
private synchronized void updateRootSize(int rootTag, int newWidth, int newHeight) {
  ReactShadowNode rootNode = getRootNode(rootTag);
  if (rootNode == null) {
    FLog.w(
      ReactConstants.TAG,
      "Tried to update size of non-existent tag: " + rootTag);
    return;
  }

  ReactShadowNode newRootNode = rootNode.mutableCopy(rootNode.getInstanceHandle());
  int newWidthSpec = View.MeasureSpec.makeMeasureSpec(newWidth, View.MeasureSpec.EXACTLY);
  int newHeightSpec = View.MeasureSpec.makeMeasureSpec(newHeight, View.MeasureSpec.EXACTLY);
  updateRootView(newRootNode, newWidthSpec, newHeightSpec);

  completeRoot(rootTag, newRootNode.getChildrenList());
}
 
Example 4
Source File: FabricUIManagerTest.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Tests that cloned text nodes will not share measure functions
 */
@Test
public void testTextMutableClone() {
  ReactRootView rootView =
      new ReactRootView(RuntimeEnvironment.application.getApplicationContext());
  int rootTag = mFabricUIManager.addRootView(rootView);
  ReactShadowNode text =
      mFabricUIManager.createNode(0, ReactTextViewManager.REACT_CLASS, rootTag, null, randomInstanceHandle());
  assertThat(text.isMeasureDefined()).isTrue();

  ReactShadowNode textCopy = text.mutableCopy(randomInstanceHandle());
  assertThat(textCopy.isMeasureDefined()).isTrue();

  textCopy.setStyleWidth(200);
  text.onBeforeLayout();
  text.calculateLayout();
  textCopy.onBeforeLayout();
  textCopy.calculateLayout();

  assertThat(text.getLayoutWidth()).isNotEqualTo(textCopy.getLayoutWidth());
}
 
Example 5
Source File: FabricUIManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
@DoNotStrip
public synchronized void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec) {
  ReactShadowNode rootNode = getRootNode(rootViewTag);
  if (rootNode == null) {
    FLog.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag);
    return;
  }

  ReactShadowNode newRootNode = rootNode.mutableCopy(rootNode.getInstanceHandle());
  updateRootView(newRootNode, widthMeasureSpec, heightMeasureSpec);
  mRootShadowNodeRegistry.replaceNode(newRootNode);
}