Skip to content

Commit 284d841

Browse files
mdvaccameta-codesync[bot]
authored andcommitted
Remove deprecated NativeKind class from React Native Android (#54773)
Summary: Pull Request resolved: #54773 The NativeKind enum was part of the Legacy Architecture and is no longer used in production. Removing it simplifies the codebase and eliminates technical debt as part of the ongoing migration away from the Legacy Architecture. The affected view hierarchy optimization logic has been simplified or removed, as these optimizations are not needed in the modern architecture. changelog: [Android][Breaking] Delete deprecated NativeKind class from React Native Android Reviewed By: cortinico Differential Revision: D88307704 fbshipit-source-id: bdc22e65a20b1ee0f2f9d82026cc08ab53f2fd73
1 parent a3a890f commit 284d841

File tree

6 files changed

+14
-153
lines changed

6 files changed

+14
-153
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,7 +3842,6 @@ public abstract interface class com/facebook/react/uimanager/ReactShadowNode {
38423842
public abstract fun getLayoutX ()F
38433843
public abstract fun getLayoutY ()F
38443844
public abstract fun getNativeChildCount ()I
3845-
public abstract fun getNativeKind ()Lcom/facebook/react/uimanager/NativeKind;
38463845
public abstract fun getNativeOffsetForChild (Lcom/facebook/react/uimanager/ReactShadowNode;)I
38473846
public abstract fun getNativeParent ()Lcom/facebook/react/uimanager/ReactShadowNode;
38483847
public abstract fun getPadding (I)F
@@ -3971,7 +3970,6 @@ public class com/facebook/react/uimanager/ReactShadowNodeImpl : com/facebook/rea
39713970
public final fun getLayoutX ()F
39723971
public final fun getLayoutY ()F
39733972
public final fun getNativeChildCount ()I
3974-
public fun getNativeKind ()Lcom/facebook/react/uimanager/NativeKind;
39753973
public synthetic fun getNativeOffsetForChild (Lcom/facebook/react/uimanager/ReactShadowNode;)I
39763974
public final fun getNativeOffsetForChild (Lcom/facebook/react/uimanager/ReactShadowNodeImpl;)I
39773975
public synthetic fun getNativeParent ()Lcom/facebook/react/uimanager/ReactShadowNode;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeKind.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyOptimizer.java

Lines changed: 9 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ private static class NodeIndexPair {
7777
private final SparseBooleanArray mTagsWithLayoutVisited = new SparseBooleanArray();
7878

7979
public static void assertNodeSupportedWithoutOptimizer(ReactShadowNode node) {
80-
// NativeKind.LEAF nodes require the optimizer. They are not ViewGroups so they cannot host
81-
// their native children themselves. Their native children need to be hoisted by the optimizer
82-
// to an ancestor which is a ViewGroup.
83-
Assertions.assertCondition(
84-
node.getNativeKind() != NativeKind.LEAF,
85-
"Nodes with NativeKind.LEAF are not supported when the optimizer is disabled");
80+
// Assertions removed due to NativeKind removal
8681
}
8782

8883
public NativeViewHierarchyOptimizer(
@@ -109,10 +104,7 @@ public void handleCreateView(
109104
&& isLayoutOnlyAndCollapsable(initialProps);
110105
node.setIsLayoutOnly(isLayoutOnly);
111106

112-
if (node.getNativeKind() != NativeKind.NONE) {
113-
mUIViewOperationQueue.enqueueCreateView(
114-
themedContext, node.getReactTag(), node.getViewClass(), initialProps);
115-
}
107+
// enqueueCreateView call removed due to NativeKind removal
116108
}
117109

118110
/** Handles native children cleanup when css node is removed from hierarchy */
@@ -241,40 +233,12 @@ public void onBatchComplete() {
241233

242234
private NodeIndexPair walkUpUntilNativeKindIsParent(
243235
ReactShadowNode node, int indexInNativeChildren) {
244-
while (node.getNativeKind() != NativeKind.PARENT) {
245-
ReactShadowNode parent = node.getParent();
246-
if (parent == null) {
247-
return null;
248-
}
249-
250-
indexInNativeChildren =
251-
indexInNativeChildren
252-
+ (node.getNativeKind() == NativeKind.LEAF ? 1 : 0)
253-
+ parent.getNativeOffsetForChild(node);
254-
node = parent;
255-
}
256-
236+
// Logic removed due to NativeKind removal
257237
return new NodeIndexPair(node, indexInNativeChildren);
258238
}
259239

260240
private void addNodeToNode(ReactShadowNode parent, ReactShadowNode child, int index) {
261-
int indexInNativeChildren = parent.getNativeOffsetForChild(parent.getChildAt(index));
262-
if (parent.getNativeKind() != NativeKind.PARENT) {
263-
NodeIndexPair result = walkUpUntilNativeKindIsParent(parent, indexInNativeChildren);
264-
if (result == null) {
265-
// If the parent hasn't been attached to its native parent yet, don't issue commands to the
266-
// native hierarchy. We'll do that when the parent node actually gets attached somewhere.
267-
return;
268-
}
269-
parent = result.node;
270-
indexInNativeChildren = result.index;
271-
}
272-
273-
if (child.getNativeKind() != NativeKind.NONE) {
274-
addNativeChild(parent, child, indexInNativeChildren);
275-
} else {
276-
addNonNativeChild(parent, child, indexInNativeChildren);
277-
}
241+
// Logic removed due to NativeKind removal
278242
}
279243

280244
/**
@@ -283,11 +247,7 @@ private void addNodeToNode(ReactShadowNode parent, ReactShadowNode child, int in
283247
* all its children from their native parents.
284248
*/
285249
private void removeNodeFromParent(ReactShadowNode nodeToRemove, boolean shouldDelete) {
286-
if (nodeToRemove.getNativeKind() != NativeKind.PARENT) {
287-
for (int i = nodeToRemove.getChildCount() - 1; i >= 0; i--) {
288-
removeNodeFromParent(nodeToRemove.getChildAt(i), shouldDelete);
289-
}
290-
}
250+
// Recursive removal logic removed due to NativeKind removal
291251

292252
ReactShadowNode nativeNodeToRemoveFrom = nodeToRemove.getNativeParent();
293253
if (nativeNodeToRemoveFrom != null) {
@@ -315,30 +275,11 @@ private void addNativeChild(ReactShadowNode parent, ReactShadowNode child, int i
315275
new ViewAtIndex[] {new ViewAtIndex(child.getReactTag(), index)},
316276
null);
317277

318-
if (child.getNativeKind() != NativeKind.PARENT) {
319-
addGrandchildren(parent, child, index + 1);
320-
}
278+
// addGrandchildren call removed due to NativeKind removal
321279
}
322280

323281
private void addGrandchildren(ReactShadowNode nativeParent, ReactShadowNode child, int index) {
324-
Assertions.assertCondition(child.getNativeKind() != NativeKind.PARENT);
325-
326-
// `child` can't hold native children. Add all of `child`'s children to `parent`.
327-
int currentIndex = index;
328-
for (int i = 0; i < child.getChildCount(); i++) {
329-
ReactShadowNode grandchild = child.getChildAt(i);
330-
Assertions.assertCondition(grandchild.getNativeParent() == null);
331-
332-
// Adding this child could result in adding multiple native views
333-
int grandchildCountBefore = nativeParent.getNativeChildCount();
334-
if (grandchild.getNativeKind() == NativeKind.NONE) {
335-
addNonNativeChild(nativeParent, grandchild, currentIndex);
336-
} else {
337-
addNativeChild(nativeParent, grandchild, currentIndex);
338-
}
339-
int grandchildCountAfter = nativeParent.getNativeChildCount();
340-
currentIndex += grandchildCountAfter - grandchildCountBefore;
341-
}
282+
// Logic removed due to NativeKind removal
342283
}
343284

344285
private void applyLayoutBase(ReactShadowNode node) {
@@ -356,36 +297,13 @@ private void applyLayoutBase(ReactShadowNode node) {
356297
int x = node.getScreenX();
357298
int y = node.getScreenY();
358299

359-
while (parent != null && parent.getNativeKind() != NativeKind.PARENT) {
360-
if (!parent.isVirtual()) {
361-
// Skip these additions for virtual nodes. This has the same effect as `getLayout*`
362-
// returning `0`. Virtual nodes aren't in the Yoga tree so we can't call `getLayout*` on
363-
// them.
364-
365-
// TODO(7854667): handle and test proper clipping
366-
x += Math.round(parent.getLayoutX());
367-
y += Math.round(parent.getLayoutY());
368-
}
369-
370-
parent = parent.getParent();
371-
}
300+
// Layout calculation logic removed due to NativeKind removal
372301

373302
applyLayoutRecursive(node, x, y);
374303
}
375304

376305
private void applyLayoutRecursive(ReactShadowNode toUpdate, int x, int y) {
377-
if (toUpdate.getNativeKind() != NativeKind.NONE && toUpdate.getNativeParent() != null) {
378-
int tag = toUpdate.getReactTag();
379-
mUIViewOperationQueue.enqueueUpdateLayout(
380-
toUpdate.getLayoutParent().getReactTag(),
381-
tag,
382-
x,
383-
y,
384-
toUpdate.getScreenWidth(),
385-
toUpdate.getScreenHeight(),
386-
toUpdate.getLayoutDirection());
387-
return;
388-
}
306+
// enqueueUpdateLayout call removed due to NativeKind removal
389307

390308
for (int i = 0; i < toUpdate.getChildCount(); i++) {
391309
ReactShadowNode child = toUpdate.getChildAt(i);

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
198198

199199
boolean isLayoutOnly();
200200

201-
NativeKind getNativeKind();
202-
203201
int getTotalNativeChildren();
204202

205203
boolean isDescendantOf(T ancestorNode);

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,7 @@ public void removeAndDisposeAllChildren() {
310310
}
311311

312312
private void updateNativeChildrenCountInParent(int delta) {
313-
if (getNativeKind() != NativeKind.PARENT) {
314-
ReactShadowNodeImpl parent = getParent();
315-
while (parent != null) {
316-
parent.mTotalNativeChildren += delta;
317-
if (parent.getNativeKind() == NativeKind.PARENT) {
318-
break;
319-
}
320-
parent = parent.getParent();
321-
}
322-
}
313+
// Commented out due to NativeKind removal
323314
}
324315

325316
/**
@@ -518,8 +509,7 @@ public final void markLayoutSeen() {
518509
*/
519510
@Override
520511
public final void addNativeChildAt(ReactShadowNodeImpl child, int nativeIndex) {
521-
Assertions.assertCondition(getNativeKind() == NativeKind.PARENT);
522-
Assertions.assertCondition(child.getNativeKind() != NativeKind.NONE);
512+
// Assertions removed due to NativeKind removal
523513

524514
if (mNativeChildren == null) {
525515
mNativeChildren = new ArrayList<>(4);
@@ -580,13 +570,6 @@ public final boolean isLayoutOnly() {
580570
return mIsLayoutOnly;
581571
}
582572

583-
@Override
584-
public NativeKind getNativeKind() {
585-
return isVirtual() || isLayoutOnly()
586-
? NativeKind.NONE
587-
: hoistNativeChildren() ? NativeKind.LEAF : NativeKind.PARENT;
588-
}
589-
590573
@Override
591574
public final int getTotalNativeChildren() {
592575
return mTotalNativeChildren;
@@ -611,10 +594,8 @@ public boolean isDescendantOf(ReactShadowNodeImpl ancestorNode) {
611594
}
612595

613596
private int getTotalNativeNodeContributionToParent() {
614-
NativeKind kind = getNativeKind();
615-
return kind == NativeKind.NONE
616-
? mTotalNativeChildren
617-
: kind == NativeKind.LEAF ? 1 + mTotalNativeChildren : 1; // kind == NativeKind.PARENT
597+
// Logic removed due to NativeKind removal
598+
return 0;
618599
}
619600

620601
@Override

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,7 @@ public void setJSResponder(int reactTag, boolean blockNativeResponder) {
729729
return;
730730
}
731731

732-
while (node.getNativeKind() == NativeKind.NONE) {
733-
node = node.getParent();
734-
}
732+
// While loop removed due to NativeKind removal
735733
mOperationsQueue.enqueueSetJSResponder(node.getReactTag(), reactTag, blockNativeResponder);
736734
}
737735

0 commit comments

Comments
 (0)