Skip to content

Commit

Permalink
Add "newProps" map into ReactShadowNode
Browse files Browse the repository at this point in the history
Reviewed By: achen1

Differential Revision: D7205127

fbshipit-source-id: 6c27070806de36cab7adf9c392a10c815aee90d4
  • Loading branch information
mdvacca authored and facebook-github-bot committed Mar 9, 2018
1 parent e31781b commit c883d4e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ public ReactShadowNode cloneNodeWithNewProps(
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) {
Expand All @@ -161,8 +160,7 @@ public ReactShadowNode cloneNodeWithNewChildrenAndProps(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public void onNodeCloned(YogaNode oldYogaNode,
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();
Expand All @@ -119,7 +121,6 @@ public ReactShadowNodeImpl(ReactShadowNodeImpl original) {
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;
Expand All @@ -133,6 +134,8 @@ public ReactShadowNodeImpl(ReactShadowNodeImpl original) {
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();
Expand All @@ -152,6 +155,27 @@ public ReactShadowNodeImpl mutableCopyWithNewChildren() {
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}.
Expand Down Expand Up @@ -360,6 +384,12 @@ public void onAfterUpdateTransaction() {
// 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
Expand Down

0 comments on commit c883d4e

Please sign in to comment.