Skip to content

Commit c883d4e

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Add "newProps" map into ReactShadowNode
Reviewed By: achen1 Differential Revision: D7205127 fbshipit-source-id: 6c27070806de36cab7adf9c392a10c815aee90d4
1 parent e31781b commit c883d4e

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ public ReactShadowNode cloneNodeWithNewProps(
140140
ReactShadowNode node,
141141
@Nullable ReadableNativeMap newProps) {
142142
try {
143-
ReactShadowNode clone = node.mutableCopy();
144-
updateProps(clone, newProps);
143+
ReactShadowNode clone = node.mutableCopyWithNewProps(newProps == null ? null : new ReactStylesDiffMap(newProps));
145144
assertReactShadowNodeCopy(node, clone);
146145
return clone;
147146
} catch (Throwable t) {
@@ -161,8 +160,7 @@ public ReactShadowNode cloneNodeWithNewChildrenAndProps(
161160
ReactShadowNode node,
162161
ReadableNativeMap newProps) {
163162
try {
164-
ReactShadowNode clone = node.mutableCopyWithNewChildren();
165-
updateProps(clone, newProps);
163+
ReactShadowNode clone = node.mutableCopyWithNewChildrenAndProps(newProps == null ? null : new ReactStylesDiffMap(newProps));
166164
assertReactShadowNodeCopy(node, clone);
167165
return clone;
168166
} catch (Throwable t) {

ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java

+6
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
7272
*/
7373
T mutableCopy();
7474

75+
T mutableCopyWithNewProps(@Nullable ReactStylesDiffMap newProps);
76+
7577
T mutableCopyWithNewChildren();
7678

79+
T mutableCopyWithNewChildrenAndProps(@Nullable ReactStylesDiffMap newProps);
80+
7781
String getViewClass();
7882

7983
boolean hasUpdates();
@@ -100,6 +104,8 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
100104

101105
void removeAndDisposeAllChildren();
102106

107+
@Nullable ReactStylesDiffMap getNewProps();
108+
103109
/**
104110
* This method will be called by {@link UIManagerModule} once per batch, before calculating
105111
* layout. Will be only called for nodes that are marked as updated with {@link #markUpdated()} or

ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public void onNodeCloned(YogaNode oldYogaNode,
9898
private final boolean[] mPaddingIsPercent = new boolean[Spacing.ALL + 1];
9999
private final YogaNode mYogaNode;
100100

101+
private @Nullable ReactStylesDiffMap mNewProps;
102+
101103
public ReactShadowNodeImpl() {
102104
if (!isVirtual()) {
103105
YogaNode node = YogaNodePool.get().acquire();
@@ -119,7 +121,6 @@ public ReactShadowNodeImpl(ReactShadowNodeImpl original) {
119121
mShouldNotifyOnLayout = original.mShouldNotifyOnLayout;
120122
mNodeUpdated = original.mNodeUpdated;
121123
mChildren = original.mChildren == null ? null : new ArrayList<>(original.mChildren);
122-
mParent = null;
123124
mIsLayoutOnly = original.mIsLayoutOnly;
124125
mTotalNativeChildren = original.mTotalNativeChildren;
125126
mNativeParent = original.mNativeParent;
@@ -133,6 +134,8 @@ public ReactShadowNodeImpl(ReactShadowNodeImpl original) {
133134
arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length);
134135
mYogaNode = original.mYogaNode.clone();
135136
mYogaNode.setData(this);
137+
mParent = null;
138+
mNewProps = null;
136139
} catch (CloneNotSupportedException e) {
137140
// it should never happen
138141
throw new IllegalArgumentException();
@@ -152,6 +155,27 @@ public ReactShadowNodeImpl mutableCopyWithNewChildren() {
152155
return copy;
153156
}
154157

158+
@Override
159+
public ReactShadowNodeImpl mutableCopyWithNewProps(@Nullable ReactStylesDiffMap newProps) {
160+
ReactShadowNodeImpl copy = mutableCopy();
161+
if (newProps != null) {
162+
copy.updateProperties(newProps);
163+
copy.mNewProps = newProps;
164+
}
165+
return copy;
166+
}
167+
168+
@Override
169+
public ReactShadowNodeImpl mutableCopyWithNewChildrenAndProps(@Nullable ReactStylesDiffMap newProps) {
170+
ReactShadowNodeImpl copy = mutableCopyWithNewChildren();
171+
if (newProps != null) {
172+
copy.updateProperties(newProps);
173+
copy.mNewProps = newProps;
174+
}
175+
return copy;
176+
}
177+
178+
155179
/**
156180
* Nodes that return {@code true} will be treated as "virtual" nodes. That is, nodes that are not
157181
* mapped into native views (e.g. nested text node). By default this method returns {@code false}.
@@ -360,6 +384,12 @@ public void onAfterUpdateTransaction() {
360384
// no-op
361385
}
362386

387+
@Override
388+
@Nullable
389+
public ReactStylesDiffMap getNewProps() {
390+
return mNewProps;
391+
}
392+
363393
/**
364394
* Called after layout step at the end of the UI batch from {@link UIManagerModule}. May be used
365395
* to enqueue additional ui operations for the native view. Will only be called on nodes marked as

0 commit comments

Comments
 (0)