Include instanceHandle in cloning mechanism

Reviewed By: shergin, achen1

Differential Revision: D8072075

fbshipit-source-id: 2fcfdfa5116850ce0bac6c2c86d87e5bf00fd7f0
This commit is contained in:
David Vacca
2018-05-30 21:49:15 -07:00
committed by Facebook Github Bot
parent 40c7248345
commit 23fbd312aa
13 changed files with 126 additions and 73 deletions

View File

@@ -120,17 +120,20 @@ public class FabricReconciler {
int reactTag = node.getReactTag();
if (DEBUG) {
Log.d(
TAG,
"manageChildren.enqueueUpdateProperties " +
"\n\ttag: " + reactTag +
"\n\tviewClass: " + node.getViewClass() +
"\n\tnewProps: " + node.getNewProps());
TAG,
"manageChildren.enqueueUpdateProperties " +
"\n\ttag: " + reactTag +
"\n\tviewClass: " + node.getViewClass() +
"\n\tinstanceHandle: " + node.getInstanceHandle() +
"\n\tnewProps: " + node.getNewProps());
}
if (node.getNewProps() != null) {
uiViewOperationQueue.enqueueUpdateProperties(
reactTag, node.getViewClass(), node.getNewProps());
}
}
uiViewOperationQueue.enqueueUpdateInstanceHandle(
reactTag, node.getInstanceHandle());
}
}

View File

@@ -98,6 +98,7 @@ public class FabricUIManager implements UIManager, JSHandler {
ReactShadowNode rootNode = getRootNode(rootTag);
node.setRootTag(rootNode.getReactTag());
node.setViewClassName(viewName);
node.setInstanceHandle(instanceHandle);
node.setReactTag(reactTag);
node.setThemedContext(rootNode.getThemedContext());
@@ -139,8 +140,7 @@ public class FabricUIManager implements UIManager, JSHandler {
Log.d(TAG, "cloneNode \n\tnode: " + node);
}
try {
// TODO: Pass new instanceHandle
ReactShadowNode clone = node.mutableCopy();
ReactShadowNode clone = node.mutableCopy(instanceHandle);
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Throwable t) {
@@ -160,8 +160,7 @@ public class FabricUIManager implements UIManager, JSHandler {
Log.d(TAG, "cloneNodeWithNewChildren \n\tnode: " + node);
}
try {
// TODO: Pass new instanceHandle
ReactShadowNode clone = node.mutableCopyWithNewChildren();
ReactShadowNode clone = node.mutableCopyWithNewChildren(instanceHandle);
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Throwable t) {
@@ -182,9 +181,8 @@ public class FabricUIManager implements UIManager, JSHandler {
Log.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps);
}
try {
// TODO: Pass new instanceHandle
ReactShadowNode clone =
node.mutableCopyWithNewProps(newProps == null ? null : new ReactStylesDiffMap(newProps));
ReactShadowNode clone = node.mutableCopyWithNewProps(instanceHandle,
newProps == null ? null : new ReactStylesDiffMap(newProps));
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Throwable t) {
@@ -206,9 +204,8 @@ public class FabricUIManager implements UIManager, JSHandler {
Log.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps);
}
try {
// TODO: Pass new instanceHandle
ReactShadowNode clone =
node.mutableCopyWithNewChildrenAndProps(
node.mutableCopyWithNewChildrenAndProps(instanceHandle,
newProps == null ? null : new ReactStylesDiffMap(newProps));
assertReactShadowNodeCopy(node, clone);
return clone;
@@ -244,7 +241,7 @@ public class FabricUIManager implements UIManager, JSHandler {
// 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.getParent() != null) {
child = child.mutableCopy();
child = child.mutableCopy(child.getInstanceHandle());
}
parent.addChildAt(child, parent.getChildCount());
} catch (Throwable t) {
@@ -315,7 +312,7 @@ public class FabricUIManager implements UIManager, JSHandler {
private ReactShadowNode calculateDiffingAndCreateNewRootNode(
ReactShadowNode currentRootShadowNode, List<ReactShadowNode> newChildList) {
ReactShadowNode newRootShadowNode = currentRootShadowNode.mutableCopyWithNewChildren();
ReactShadowNode newRootShadowNode = currentRootShadowNode.mutableCopyWithNewChildren(currentRootShadowNode.getInstanceHandle());
for (ReactShadowNode child : newChildList) {
appendChild(newRootShadowNode, child);
}
@@ -489,10 +486,10 @@ public class FabricUIManager implements UIManager, JSHandler {
// -> call to C++
}
public long createEventTarget(int targetTag) throws IllegalStateException {
long instanceHandle = mNativeViewHierarchyManager.getInstanceHandle(targetTag);
public long createEventTarget(int reactTag) throws IllegalStateException {
long instanceHandle = mNativeViewHierarchyManager.getInstanceHandle(reactTag);
if (instanceHandle == 0) {
throw new IllegalStateException("View with targetTag " + targetTag + " does not exist.");
throw new IllegalStateException("View with reactTag " + reactTag + " does not exist.");
}
// TODO: uncomment after diff including Binding is landed

View File

@@ -221,16 +221,16 @@ public class NativeViewHierarchyManager {
@Nullable
@TargetApi(Build.VERSION_CODES.DONUT)
public long getInstanceHandle(int targetTag) {
public long getInstanceHandle(int reactTag) {
UiThreadUtil.assertOnUiThread();
View view = mTagsToViews.get(targetTag);
View view = mTagsToViews.get(reactTag);
if (view == null) {
throw new IllegalArgumentException("Unable to find view for tag: " + targetTag);
throw new IllegalArgumentException("Unable to find view for tag: " + reactTag);
}
Long tag = (Long) view.getTag(R.id.view_tag_instance_handle);
if (tag == null) {
throw new IllegalArgumentException("Unable to find instanceHandle for tag: " + targetTag);
throw new IllegalArgumentException("Unable to find instanceHandle for tag: " + reactTag);
}
return tag;
}

View File

@@ -71,13 +71,13 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
/**
* @return a mutable copy of the {@link ReactShadowNode}
*/
T mutableCopy();
T mutableCopy(long instanceHandle);
T mutableCopyWithNewProps(@Nullable ReactStylesDiffMap newProps);
T mutableCopyWithNewProps(long instanceHandle, @Nullable ReactStylesDiffMap newProps);
T mutableCopyWithNewChildren();
T mutableCopyWithNewChildren(long instanceHandle);
T mutableCopyWithNewChildrenAndProps(@Nullable ReactStylesDiffMap newProps);
T mutableCopyWithNewChildrenAndProps(long instanceHandle, @Nullable ReactStylesDiffMap newProps);
String getViewClass();
@@ -373,4 +373,8 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
@Nullable ReactShadowNode getOriginalReactShadowNode();
void setOriginalReactShadowNode(@Nullable ReactShadowNode node);
long getInstanceHandle();
void setInstanceHandle(long instanceHandle);
}

View File

@@ -81,7 +81,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
+ parentReactShadowNode + " index: " + childIndex);
}
ReactShadowNodeImpl newNode = oldReactShadowNode.mutableCopy();
ReactShadowNodeImpl newNode = oldReactShadowNode.mutableCopy(oldReactShadowNode.getInstanceHandle());
parentReactShadowNode.replaceChild(newNode, childIndex);
return newNode.mYogaNode;
}
@@ -114,6 +114,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
private ReactShadowNode mOriginalReactShadowNode = null;
private @Nullable ReactStylesDiffMap mNewProps;
private long mInstanceHandle;
public ReactShadowNodeImpl() {
mDefaultPadding = new Spacing(0);
@@ -166,11 +167,12 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
}
@Override
public ReactShadowNodeImpl mutableCopy() {
public ReactShadowNodeImpl mutableCopy(long instanceHandle) {
ReactShadowNodeImpl copy = copy();
Assertions.assertCondition(
getClass() == copy.getClass(),
"Copied shadow node must use the same class");
copy.mInstanceHandle = instanceHandle;
if (mYogaNode != null) {
copy.mYogaNode = mYogaNode.clone();
copy.mYogaNode.setData(copy);
@@ -185,8 +187,9 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
public ReactShadowNodeImpl mutableCopyWithNewChildren(long instanceHandle) {
ReactShadowNodeImpl copy = copy();
copy.mInstanceHandle = instanceHandle;
Assertions.assertCondition(
getClass() == copy.getClass(),
"Copied shadow node must use the same class");
@@ -204,8 +207,9 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewProps(@Nullable ReactStylesDiffMap newProps) {
ReactShadowNodeImpl copy = mutableCopy();
public ReactShadowNodeImpl mutableCopyWithNewProps(long instanceHandle,
@Nullable ReactStylesDiffMap newProps) {
ReactShadowNodeImpl copy = mutableCopy(instanceHandle);
if (newProps != null) {
copy.updateProperties(newProps);
copy.mNewProps = newProps;
@@ -214,8 +218,9 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildrenAndProps(@Nullable ReactStylesDiffMap newProps) {
ReactShadowNodeImpl copy = mutableCopyWithNewChildren();
public ReactShadowNodeImpl mutableCopyWithNewChildrenAndProps(long instanceHandle,
@Nullable ReactStylesDiffMap newProps) {
ReactShadowNodeImpl copy = mutableCopyWithNewChildren(instanceHandle);
if (newProps != null) {
copy.updateProperties(newProps);
copy.mNewProps = newProps;
@@ -1107,4 +1112,14 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
public void setOriginalReactShadowNode(ReactShadowNode node) {
mOriginalReactShadowNode = node;
}
@Override
public long getInstanceHandle() {
return mInstanceHandle;
}
@Override
public void setInstanceHandle(long instanceHandle) {
mInstanceHandle = instanceHandle;
}
}

View File

@@ -53,8 +53,8 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements YogaMeasu
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
ProgressBarShadowNode node = (ProgressBarShadowNode) super.mutableCopyWithNewChildren();
public ReactShadowNodeImpl mutableCopyWithNewChildren(long instanceHandle) {
ProgressBarShadowNode node = (ProgressBarShadowNode) super.mutableCopyWithNewChildren(instanceHandle);
node.initMeasureFunction();
return node;
}
@@ -64,8 +64,8 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements YogaMeasu
}
@Override
public ReactShadowNodeImpl mutableCopy() {
ProgressBarShadowNode node = (ProgressBarShadowNode) super.mutableCopy();
public ReactShadowNodeImpl mutableCopy(long instanceHandle) {
ProgressBarShadowNode node = (ProgressBarShadowNode) super.mutableCopy(instanceHandle);
node.initMeasureFunction();
return node;
}

View File

@@ -62,15 +62,15 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
}
@Override
public ReactShadowNodeImpl mutableCopy() {
ReactSliderShadowNode reactShadowNode = (ReactSliderShadowNode) super.mutableCopy();
public ReactShadowNodeImpl mutableCopy(long instanceHandle) {
ReactSliderShadowNode reactShadowNode = (ReactSliderShadowNode) super.mutableCopy(instanceHandle);
reactShadowNode.initMeasureFunction();
return reactShadowNode;
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
ReactSliderShadowNode reactShadowNode = (ReactSliderShadowNode) super.mutableCopyWithNewChildren();
public ReactShadowNodeImpl mutableCopyWithNewChildren(long instanceHandle) {
ReactSliderShadowNode reactShadowNode = (ReactSliderShadowNode) super.mutableCopyWithNewChildren(instanceHandle);
reactShadowNode.initMeasureFunction();
return reactShadowNode;
}

View File

@@ -55,15 +55,15 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
}
@Override
public ReactShadowNodeImpl mutableCopy() {
ReactSwitchShadowNode reactShadowNode = (ReactSwitchShadowNode) super.mutableCopy();
public ReactShadowNodeImpl mutableCopy(long instanceHandle) {
ReactSwitchShadowNode reactShadowNode = (ReactSwitchShadowNode) super.mutableCopy(instanceHandle);
reactShadowNode.initMeasureFunction();
return reactShadowNode;
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
ReactSwitchShadowNode reactShadowNode = (ReactSwitchShadowNode) super.mutableCopyWithNewChildren();
public ReactShadowNodeImpl mutableCopyWithNewChildren(long instanceHandle) {
ReactSwitchShadowNode reactShadowNode = (ReactSwitchShadowNode) super.mutableCopyWithNewChildren(instanceHandle);
reactShadowNode.initMeasureFunction();
return reactShadowNode;
}

View File

@@ -159,15 +159,15 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
}
@Override
public ReactShadowNodeImpl mutableCopy() {
ReactTextShadowNode copy = (ReactTextShadowNode) super.mutableCopy();
public ReactShadowNodeImpl mutableCopy(long instanceHandle) {
ReactTextShadowNode copy = (ReactTextShadowNode) super.mutableCopy(instanceHandle);
copy.initMeasureFunction();
return copy;
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
ReactTextShadowNode copy = (ReactTextShadowNode) super.mutableCopyWithNewChildren();
public ReactShadowNodeImpl mutableCopyWithNewChildren(long instanceHandle) {
ReactTextShadowNode copy = (ReactTextShadowNode) super.mutableCopyWithNewChildren(instanceHandle);
copy.initMeasureFunction();
return copy;
}

View File

@@ -65,8 +65,8 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
}
@Override
public ReactTextInputShadowNode mutableCopy() {
ReactTextInputShadowNode node = (ReactTextInputShadowNode) super.mutableCopy();
public ReactTextInputShadowNode mutableCopy(long instanceHandle) {
ReactTextInputShadowNode node = (ReactTextInputShadowNode) super.mutableCopy(instanceHandle);
node.initMeasureFunction();
ThemedReactContext themedContext = getThemedContext();
if (themedContext != null) {
@@ -80,8 +80,8 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
}
@Override
public ReactTextInputShadowNode mutableCopyWithNewChildren() {
ReactTextInputShadowNode node = (ReactTextInputShadowNode) super.mutableCopyWithNewChildren();
public ReactTextInputShadowNode mutableCopyWithNewChildren(long instanceHandle) {
ReactTextInputShadowNode node = (ReactTextInputShadowNode) super.mutableCopyWithNewChildren(instanceHandle);
node.initMeasureFunction();
ThemedReactContext themedContext = getThemedContext();
if (themedContext != null) {