Add "newProps" map into ReactShadowNode

Reviewed By: achen1

Differential Revision: D7205127

fbshipit-source-id: 6c27070806de36cab7adf9c392a10c815aee90d4
This commit is contained in:
David Vacca 2018-03-09 09:39:42 -08:00 committed by Facebook Github Bot
parent e31781be61
commit c883d4e727
3 changed files with 39 additions and 5 deletions

View File

@ -140,8 +140,7 @@ public class FabricUIManager implements UIManager {
ReactShadowNode node,
@Nullable ReadableNativeMap newProps) {
try {
ReactShadowNode clone = node.mutableCopy();
updateProps(clone, newProps);
ReactShadowNode clone = node.mutableCopyWithNewProps(newProps == null ? null : new ReactStylesDiffMap(newProps));
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Throwable t) {
@ -161,8 +160,7 @@ public class FabricUIManager implements UIManager {
ReactShadowNode node,
ReadableNativeMap newProps) {
try {
ReactShadowNode clone = node.mutableCopyWithNewChildren();
updateProps(clone, newProps);
ReactShadowNode clone = node.mutableCopyWithNewChildrenAndProps(newProps == null ? null : new ReactStylesDiffMap(newProps));
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Throwable t) {

View File

@ -72,8 +72,12 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
*/
T mutableCopy();
T mutableCopyWithNewProps(@Nullable ReactStylesDiffMap newProps);
T mutableCopyWithNewChildren();
T mutableCopyWithNewChildrenAndProps(@Nullable ReactStylesDiffMap newProps);
String getViewClass();
boolean hasUpdates();
@ -100,6 +104,8 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
void removeAndDisposeAllChildren();
@Nullable ReactStylesDiffMap getNewProps();
/**
* This method will be called by {@link UIManagerModule} once per batch, before calculating
* layout. Will be only called for nodes that are marked as updated with {@link #markUpdated()} or

View File

@ -98,6 +98,8 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
private final boolean[] mPaddingIsPercent = new boolean[Spacing.ALL + 1];
private final YogaNode mYogaNode;
private @Nullable ReactStylesDiffMap mNewProps;
public ReactShadowNodeImpl() {
if (!isVirtual()) {
YogaNode node = YogaNodePool.get().acquire();
@ -119,7 +121,6 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
mShouldNotifyOnLayout = original.mShouldNotifyOnLayout;
mNodeUpdated = original.mNodeUpdated;
mChildren = original.mChildren == null ? null : new ArrayList<>(original.mChildren);
mParent = null;
mIsLayoutOnly = original.mIsLayoutOnly;
mTotalNativeChildren = original.mTotalNativeChildren;
mNativeParent = original.mNativeParent;
@ -133,6 +134,8 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length);
mYogaNode = original.mYogaNode.clone();
mYogaNode.setData(this);
mParent = null;
mNewProps = null;
} catch (CloneNotSupportedException e) {
// it should never happen
throw new IllegalArgumentException();
@ -152,6 +155,27 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
return copy;
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewProps(@Nullable ReactStylesDiffMap newProps) {
ReactShadowNodeImpl copy = mutableCopy();
if (newProps != null) {
copy.updateProperties(newProps);
copy.mNewProps = newProps;
}
return copy;
}
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildrenAndProps(@Nullable ReactStylesDiffMap newProps) {
ReactShadowNodeImpl copy = mutableCopyWithNewChildren();
if (newProps != null) {
copy.updateProperties(newProps);
copy.mNewProps = newProps;
}
return copy;
}
/**
* Nodes that return {@code true} will be treated as "virtual" nodes. That is, nodes that are not
* mapped into native views (e.g. nested text node). By default this method returns {@code false}.
@ -360,6 +384,12 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
// no-op
}
@Override
@Nullable
public ReactStylesDiffMap getNewProps() {
return mNewProps;
}
/**
* Called after layout step at the end of the UI batch from {@link UIManagerModule}. May be used
* to enqueue additional ui operations for the native view. Will only be called on nodes marked as