diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 2a0ba29bfdd8..27c95c3396b9 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -3504,7 +3504,6 @@ public class com/facebook/react/uimanager/NativeViewHierarchyManager { public fun findTargetTagForTouch (IFF)I public fun getInstanceHandle (I)J public fun getRootViewNum ()I - public fun manageChildren (I[I[Lcom/facebook/react/uimanager/ViewAtIndex;[I)V public fun measure (I[I)V public fun measureInWindow (I[I)V public fun removeRootView (I)V @@ -3526,7 +3525,6 @@ public class com/facebook/react/uimanager/NativeViewHierarchyOptimizer { public static fun assertNodeSupportedWithoutOptimizer (Lcom/facebook/react/uimanager/ReactShadowNode;)V public fun handleCreateView (Lcom/facebook/react/uimanager/ReactShadowNode;Lcom/facebook/react/uimanager/ThemedReactContext;Lcom/facebook/react/uimanager/ReactStylesDiffMap;)V public fun handleForceViewToBeNonLayoutOnly (Lcom/facebook/react/uimanager/ReactShadowNode;)V - public fun handleManageChildren (Lcom/facebook/react/uimanager/ReactShadowNode;[I[I[Lcom/facebook/react/uimanager/ViewAtIndex;[I)V public static fun handleRemoveNode (Lcom/facebook/react/uimanager/ReactShadowNode;)V public fun handleSetChildren (Lcom/facebook/react/uimanager/ReactShadowNode;Lcom/facebook/react/bridge/ReadableArray;)V public fun handleUpdateLayout (Lcom/facebook/react/uimanager/ReactShadowNode;)V @@ -4272,7 +4270,6 @@ public class com/facebook/react/uimanager/UIImplementation { public fun getRootViewNum ()I protected fun handleCreateView (Lcom/facebook/react/uimanager/ReactShadowNode;ILcom/facebook/react/uimanager/ReactStylesDiffMap;)V protected fun handleUpdateView (Lcom/facebook/react/uimanager/ReactShadowNode;Ljava/lang/String;Lcom/facebook/react/uimanager/ReactStylesDiffMap;)V - public fun manageChildren (ILcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;)V public fun measure (ILcom/facebook/react/bridge/Callback;)V public fun measureInWindow (ILcom/facebook/react/bridge/Callback;)V public fun measureLayout (IILcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/Callback;)V @@ -4288,7 +4285,6 @@ public class com/facebook/react/uimanager/UIImplementation { public fun removeRootShadowNode (I)V public fun removeRootView (I)V protected final fun removeShadowNode (Lcom/facebook/react/uimanager/ReactShadowNode;)V - public fun replaceExistingNonRootView (II)V public fun resolveRootTagFromReactTag (I)I public final fun resolveShadowNode (I)Lcom/facebook/react/uimanager/ReactShadowNode; protected final fun resolveViewManager (Ljava/lang/String;)Lcom/facebook/react/uimanager/ViewManager; @@ -4358,7 +4354,6 @@ public class com/facebook/react/uimanager/UIManagerModule : com/facebook/react/b public fun initialize ()V public fun invalidate ()V public fun invalidateNodeLayout (I)V - public fun manageChildren (ILcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;)V public fun markActiveTouchForTag (II)V public fun measure (ILcom/facebook/react/bridge/Callback;)V public fun measureInWindow (ILcom/facebook/react/bridge/Callback;)V @@ -4407,7 +4402,6 @@ public class com/facebook/react/uimanager/UIViewOperationQueue { public fun enqueueDispatchCommand (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V public fun enqueueFindTargetForTouch (IFFLcom/facebook/react/bridge/Callback;)V public fun enqueueLayoutUpdateFinished (Lcom/facebook/react/uimanager/ReactShadowNode;Lcom/facebook/react/uimanager/UIImplementation$LayoutUpdateListener;)V - public fun enqueueManageChildren (I[I[Lcom/facebook/react/uimanager/ViewAtIndex;[I)V public fun enqueueMeasure (ILcom/facebook/react/bridge/Callback;)V public fun enqueueMeasureInWindow (ILcom/facebook/react/bridge/Callback;)V public fun enqueueRemoveRootView (I)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java index 1ace964c5fb7..2743719ed726 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java @@ -297,79 +297,6 @@ public synchronized void createView( } } - private static String constructManageChildrenErrorMessage( - ViewGroup viewToManage, - ViewGroupManager viewManager, - @Nullable int[] indicesToRemove, - @Nullable ViewAtIndex[] viewsToAdd, - @Nullable int[] tagsToDelete) { - StringBuilder stringBuilder = new StringBuilder(); - - if (null != viewToManage) { - stringBuilder.append( - "View tag:" - + viewToManage.getId() - + " View Type:" - + viewToManage.getClass().toString() - + "\n"); - stringBuilder.append(" children(" + viewManager.getChildCount(viewToManage) + "): [\n"); - for (int index = 0; viewManager.getChildAt(viewToManage, index) != null; index += 16) { - for (int innerOffset = 0; - viewManager.getChildAt(viewToManage, index + innerOffset) != null && innerOffset < 16; - innerOffset++) { - stringBuilder.append( - viewManager.getChildAt(viewToManage, index + innerOffset).getId() + ","); - } - stringBuilder.append("\n"); - } - stringBuilder.append(" ],\n"); - } - - if (indicesToRemove != null) { - stringBuilder.append(" indicesToRemove(" + indicesToRemove.length + "): [\n"); - for (int index = 0; index < indicesToRemove.length; index += 16) { - for (int innerOffset = 0; - ((index + innerOffset) < indicesToRemove.length) && innerOffset < 16; - innerOffset++) { - stringBuilder.append(indicesToRemove[index + innerOffset] + ","); - } - stringBuilder.append("\n"); - } - stringBuilder.append(" ],\n"); - } - if (viewsToAdd != null) { - stringBuilder.append(" viewsToAdd(" + viewsToAdd.length + "): [\n"); - for (int index = 0; index < viewsToAdd.length; index += 16) { - for (int innerOffset = 0; - ((index + innerOffset) < viewsToAdd.length) && innerOffset < 16; - innerOffset++) { - stringBuilder.append( - "[" - + viewsToAdd[index + innerOffset].mIndex - + "," - + viewsToAdd[index + innerOffset].mTag - + "],"); - } - stringBuilder.append("\n"); - } - stringBuilder.append(" ],\n"); - } - if (tagsToDelete != null) { - stringBuilder.append(" tagsToDelete(" + tagsToDelete.length + "): [\n"); - for (int index = 0; index < tagsToDelete.length; index += 16) { - for (int innerOffset = 0; - ((index + innerOffset) < tagsToDelete.length) && innerOffset < 16; - innerOffset++) { - stringBuilder.append(tagsToDelete[index + innerOffset] + ","); - } - stringBuilder.append("\n"); - } - stringBuilder.append(" ]\n"); - } - - return stringBuilder.toString(); - } - private Set getPendingDeletionsForTag(int tag) { if (mPendingDeletionsForTag == null) { mPendingDeletionsForTag = new HashMap<>(); @@ -382,147 +309,6 @@ private Set getPendingDeletionsForTag(int tag) { return mPendingDeletionsForTag.get(tag); } - /** - * @param tag react tag of the node we want to manage - * @param indicesToRemove ordered (asc) list of indices at which view should be removed - * @param viewsToAdd ordered (asc based on mIndex property) list of tag-index pairs that represent - * a view which should be added at the specified index - * @param tagsToDelete list of tags corresponding to views that should be removed - */ - public synchronized void manageChildren( - final int tag, - @Nullable int[] indicesToRemove, - @Nullable ViewAtIndex[] viewsToAdd, - @Nullable int[] tagsToDelete) { - if (DEBUG_MODE) { - FLog.d( - TAG, - "createView[%d]: %s %s %s", - tag, - (indicesToRemove != null ? indicesToRemove.toString() : ""), - (viewsToAdd != null ? viewsToAdd.toString() : ""), - (tagsToDelete != null ? tagsToDelete.toString() : "")); - } - UiThreadUtil.assertOnUiThread(); - - final Set pendingDeletionTags = getPendingDeletionsForTag(tag); - final ViewGroup viewToManage = (ViewGroup) mTagsToViews.get(tag); - final ViewGroupManager viewManager = (ViewGroupManager) resolveViewManager(tag); - if (viewToManage == null) { - throw new IllegalViewOperationException( - "Trying to manageChildren view with tag " - + tag - + " which doesn't exist\n detail: " - + constructManageChildrenErrorMessage( - viewToManage, viewManager, indicesToRemove, viewsToAdd, tagsToDelete)); - } - - int lastIndexToRemove = viewManager.getChildCount(viewToManage); - - if (indicesToRemove != null) { - for (int i = indicesToRemove.length - 1; i >= 0; i--) { - int indexToRemove = indicesToRemove[i]; - if (indexToRemove < 0) { - throw new IllegalViewOperationException( - "Trying to remove a negative view index:" - + indexToRemove - + " view tag: " - + tag - + "\n detail: " - + constructManageChildrenErrorMessage( - viewToManage, viewManager, indicesToRemove, viewsToAdd, tagsToDelete)); - } - if (viewManager.getChildAt(viewToManage, indexToRemove) == null) { - if (mRootTags.get(tag) && viewManager.getChildCount(viewToManage) == 0) { - // This root node has already been removed (likely due to a threading issue caused by - // async js execution). Ignore this root removal. - return; - } - throw new IllegalViewOperationException( - "Trying to remove a view index above child " - + "count " - + indexToRemove - + " view tag: " - + tag - + "\n detail: " - + constructManageChildrenErrorMessage( - viewToManage, viewManager, indicesToRemove, viewsToAdd, tagsToDelete)); - } - if (indexToRemove >= lastIndexToRemove) { - throw new IllegalViewOperationException( - "Trying to remove an out of order view index:" - + indexToRemove - + " view tag: " - + tag - + "\n detail: " - + constructManageChildrenErrorMessage( - viewToManage, viewManager, indicesToRemove, viewsToAdd, tagsToDelete)); - } - - if (!mLayoutAnimationEnabled) { - viewManager.removeViewAt(viewToManage, indexToRemove); - } - - lastIndexToRemove = indexToRemove; - } - } - - if (tagsToDelete != null) { - for (int i = 0; i < tagsToDelete.length; i++) { - int tagToDelete = tagsToDelete[i]; - final View viewToDestroy = mTagsToViews.get(tagToDelete); - if (viewToDestroy == null) { - throw new IllegalViewOperationException( - "Trying to destroy unknown view tag: " - + tagToDelete - + "\n detail: " - + constructManageChildrenErrorMessage( - viewToManage, viewManager, indicesToRemove, viewsToAdd, tagsToDelete)); - } - - if (!mLayoutAnimationEnabled) { - dropView(viewToDestroy); - } - } - } - - if (viewsToAdd != null) { - for (int i = 0; i < viewsToAdd.length; i++) { - ViewAtIndex viewAtIndex = viewsToAdd[i]; - View viewToAdd = mTagsToViews.get(viewAtIndex.mTag); - if (viewToAdd == null) { - throw new IllegalViewOperationException( - "Trying to add unknown view tag: " - + viewAtIndex.mTag - + "\n detail: " - + constructManageChildrenErrorMessage( - viewToManage, viewManager, indicesToRemove, viewsToAdd, tagsToDelete)); - } - - int normalizedIndex = viewAtIndex.mIndex; - if (!pendingDeletionTags.isEmpty()) { - normalizedIndex = 0; - int counter = 0; - while (normalizedIndex < viewToManage.getChildCount()) { - if (counter == viewAtIndex.mIndex) { - break; - } - View v = viewToManage.getChildAt(normalizedIndex); - if (!pendingDeletionTags.contains(v.getId())) { - counter++; - } - normalizedIndex++; - } - } - - viewManager.addView(viewToManage, viewToAdd, normalizedIndex); - } - } - if (pendingDeletionTags.isEmpty()) { - mPendingDeletionsForTag.remove(tag); - } - } - private boolean arrayContains(@Nullable int[] array, int ele) { if (array == null) { return false; @@ -535,19 +321,6 @@ private boolean arrayContains(@Nullable int[] array, int ele) { return false; } - /** - * Simplified version of constructManageChildrenErrorMessage that only deals with adding children - * views - */ - private static String constructSetChildrenErrorMessage( - ViewGroup viewToManage, ViewGroupManager viewManager, ReadableArray childrenTags) { - ViewAtIndex[] viewsToAdd = new ViewAtIndex[childrenTags.size()]; - for (int i = 0; i < childrenTags.size(); i++) { - viewsToAdd[i] = new ViewAtIndex(childrenTags.getInt(i), i); - } - return constructManageChildrenErrorMessage(viewToManage, viewManager, null, viewsToAdd, null); - } - /** Simplified version of manageChildren that only deals with adding children views */ public synchronized void setChildren(int tag, ReadableArray childrenTags) { if (DEBUG_MODE) { @@ -565,10 +338,7 @@ public synchronized void setChildren(int tag, ReadableArray childrenTags) { View viewToAdd = mTagsToViews.get(childrenTags.getInt(i)); if (viewToAdd == null) { throw new IllegalViewOperationException( - "Trying to add unknown view tag: " - + childrenTags.getInt(i) - + "\n detail: " - + constructSetChildrenErrorMessage(viewToManage, viewManager, childrenTags)); + "Trying to add unknown view tag: " + childrenTags.getInt(i)); } viewManager.addView(viewToManage, viewToAdd, i); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyOptimizer.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyOptimizer.java index 8bcbd2adc6da..54b2aaaf8b75 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyOptimizer.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyOptimizer.java @@ -132,52 +132,6 @@ public void handleUpdateView(ReactShadowNode node, String className, ReactStyles } } - /** - * Handles a manageChildren call. This may translate into multiple manageChildren calls for - * multiple other views. - * - *

NB: the assumption for calling this method is that all corresponding ReactShadowNodes have - * been updated **but tagsToDelete have NOT been deleted yet**. This is because we need to use the - * metadata from those nodes to figure out the correct commands to dispatch. This is unlike all - * other calls on this class where we assume all operations on the shadow hierarchy have already - * completed by the time a corresponding method here is called. - */ - public void handleManageChildren( - ReactShadowNode nodeToManage, - int[] indicesToRemove, - int[] tagsToRemove, - ViewAtIndex[] viewsToAdd, - int[] tagsToDelete) { - if (!ENABLED) { - assertNodeSupportedWithoutOptimizer(nodeToManage); - mUIViewOperationQueue.enqueueManageChildren( - nodeToManage.getReactTag(), indicesToRemove, viewsToAdd, tagsToDelete); - return; - } - - // We operate on tagsToRemove instead of indicesToRemove because by the time this method is - // called, these views have already been removed from the shadow hierarchy and the indices are - // no longer useful to operate on - for (int i = 0; i < tagsToRemove.length; i++) { - int tagToRemove = tagsToRemove[i]; - boolean delete = false; - for (int j = 0; j < tagsToDelete.length; j++) { - if (tagsToDelete[j] == tagToRemove) { - delete = true; - break; - } - } - ReactShadowNode nodeToRemove = mShadowNodeRegistry.getNode(tagToRemove); - removeNodeFromParent(nodeToRemove, delete); - } - - for (int i = 0; i < viewsToAdd.length; i++) { - ViewAtIndex toAdd = viewsToAdd[i]; - ReactShadowNode nodeToAdd = mShadowNodeRegistry.getNode(toAdd.mTag); - addNodeToNode(nodeToManage, nodeToAdd, toAdd.mIndex); - } - } - /** * Handles a setChildren call. This is a simplification of handleManagerChildren that only adds * children in index order of the childrenTags array @@ -241,43 +195,17 @@ private void addNodeToNode(ReactShadowNode parent, ReactShadowNode child, int in // Logic removed due to NativeKind removal } - /** - * For handling node removal from manageChildren. In the case of removing a node which isn't - * hosting its own children (e.g. layout-only or NativeKind.LEAF), we need to recursively remove - * all its children from their native parents. - */ - private void removeNodeFromParent(ReactShadowNode nodeToRemove, boolean shouldDelete) { - // Recursive removal logic removed due to NativeKind removal - - ReactShadowNode nativeNodeToRemoveFrom = nodeToRemove.getNativeParent(); - if (nativeNodeToRemoveFrom != null) { - int index = nativeNodeToRemoveFrom.indexOfNativeChild(nodeToRemove); - nativeNodeToRemoveFrom.removeNativeChildAt(index); - - mUIViewOperationQueue.enqueueManageChildren( - nativeNodeToRemoveFrom.getReactTag(), - new int[] {index}, - null, - shouldDelete ? new int[] {nodeToRemove.getReactTag()} : null); - } + private void addNativeChild(ReactShadowNode parent, ReactShadowNode child, int index) { + parent.addNativeChildAt(child, index); } + private void removeNodeFromParent(ReactShadowNode nodeToRemove, boolean shouldDelete) {} + private void addNonNativeChild( ReactShadowNode nativeParent, ReactShadowNode nonNativeChild, int index) { addGrandchildren(nativeParent, nonNativeChild, index); } - private void addNativeChild(ReactShadowNode parent, ReactShadowNode child, int index) { - parent.addNativeChildAt(child, index); - mUIViewOperationQueue.enqueueManageChildren( - parent.getReactTag(), - null, - new ViewAtIndex[] {new ViewAtIndex(child.getReactTag(), index)}, - null); - - // addGrandchildren call removed due to NativeKind removal - } - private void addGrandchildren(ReactShadowNode nativeParent, ReactShadowNode child, int index) { // Logic removed due to NativeKind removal } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java index 2e7bc238553a..45a11f908682 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java @@ -13,13 +13,11 @@ import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; -import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.UiThreadUtil; -import com.facebook.react.bridge.WritableArray; import com.facebook.react.common.ReactConstants; import com.facebook.react.common.annotations.internal.LegacyArchitecture; import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel; @@ -32,7 +30,6 @@ import com.facebook.yoga.YogaConstants; import com.facebook.yoga.YogaDirection; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -323,124 +320,6 @@ protected void handleUpdateView( } } - /** - * Invoked when there is a mutation in a node tree. - * - * @param tag react tag of the node we want to manage - * @param indicesToRemove ordered (asc) list of indices at which view should be removed - * @param viewsToAdd ordered (asc based on mIndex property) list of tag-index pairs that represent - * a view which should be added at the specified index - * @param tagsToDelete list of tags corresponding to views that should be removed - */ - public void manageChildren( - int viewTag, - @Nullable ReadableArray moveFrom, - @Nullable ReadableArray moveTo, - @Nullable ReadableArray addChildTags, - @Nullable ReadableArray addAtIndices, - @Nullable ReadableArray removeFrom) { - if (!mViewOperationsEnabled) { - return; - } - - synchronized (uiImplementationThreadLock) { - ReactShadowNode cssNodeToManage = mShadowNodeRegistry.getNode(viewTag); - - int numToMove = moveFrom == null ? 0 : moveFrom.size(); - int numToAdd = addChildTags == null ? 0 : addChildTags.size(); - int numToRemove = removeFrom == null ? 0 : removeFrom.size(); - - if (numToMove != 0 && (moveTo == null || numToMove != moveTo.size())) { - throw new IllegalViewOperationException("Size of moveFrom != size of moveTo!"); - } - - if (numToAdd != 0 && (addAtIndices == null || numToAdd != addAtIndices.size())) { - throw new IllegalViewOperationException("Size of addChildTags != size of addAtIndices!"); - } - - // We treat moves as an add and a delete - ViewAtIndex[] viewsToAdd = new ViewAtIndex[numToMove + numToAdd]; - int[] indicesToRemove = new int[numToMove + numToRemove]; - int[] tagsToRemove = new int[indicesToRemove.length]; - int[] tagsToDelete = new int[numToRemove]; - - if (numToMove > 0) { - Assertions.assertNotNull(moveFrom); - Assertions.assertNotNull(moveTo); - for (int i = 0; i < numToMove; i++) { - int moveFromIndex = moveFrom.getInt(i); - int tagToMove = cssNodeToManage.getChildAt(moveFromIndex).getReactTag(); - viewsToAdd[i] = new ViewAtIndex(tagToMove, moveTo.getInt(i)); - indicesToRemove[i] = moveFromIndex; - tagsToRemove[i] = tagToMove; - } - } - - if (numToAdd > 0) { - Assertions.assertNotNull(addChildTags); - Assertions.assertNotNull(addAtIndices); - for (int i = 0; i < numToAdd; i++) { - int viewTagToAdd = addChildTags.getInt(i); - int indexToAddAt = addAtIndices.getInt(i); - viewsToAdd[numToMove + i] = new ViewAtIndex(viewTagToAdd, indexToAddAt); - } - } - - if (numToRemove > 0) { - Assertions.assertNotNull(removeFrom); - for (int i = 0; i < numToRemove; i++) { - int indexToRemove = removeFrom.getInt(i); - int tagToRemove = cssNodeToManage.getChildAt(indexToRemove).getReactTag(); - indicesToRemove[numToMove + i] = indexToRemove; - tagsToRemove[numToMove + i] = tagToRemove; - tagsToDelete[i] = tagToRemove; - } - } - - // NB: moveFrom and removeFrom are both relative to the starting state of the View's children. - // moveTo and addAt are both relative to the final state of the View's children. - // - // 1) Sort the views to add and indices to remove by index - // 2) Iterate the indices being removed from high to low and remove them. Going high to low - // makes sure we remove the correct index when there are multiple to remove. - // 3) Iterate the views being added by index low to high and add them. Like the view removal, - // iteration direction is important to preserve the correct index. - - Arrays.sort(viewsToAdd, ViewAtIndex.COMPARATOR); - Arrays.sort(indicesToRemove); - - // Apply changes to CSSNodeDEPRECATED hierarchy - int lastIndexRemoved = -1; - for (int i = indicesToRemove.length - 1; i >= 0; i--) { - int indexToRemove = indicesToRemove[i]; - if (indexToRemove == lastIndexRemoved) { - throw new IllegalViewOperationException( - "Repeated indices in Removal list for view tag: " + viewTag); - } - cssNodeToManage.removeChildAt(indicesToRemove[i]); // Thread safety needed here - - lastIndexRemoved = indicesToRemove[i]; - } - - for (int i = 0; i < viewsToAdd.length; i++) { - ViewAtIndex viewAtIndex = viewsToAdd[i]; - ReactShadowNode cssNodeToAdd = mShadowNodeRegistry.getNode(viewAtIndex.mTag); - if (cssNodeToAdd == null) { - throw new IllegalViewOperationException( - "Trying to add unknown view tag: " + viewAtIndex.mTag); - } - cssNodeToManage.addChildAt(cssNodeToAdd, viewAtIndex.mIndex); - } - - mNativeViewHierarchyOptimizer.handleManageChildren( - cssNodeToManage, indicesToRemove, tagsToRemove, viewsToAdd, tagsToDelete); - - for (int i = 0; i < tagsToDelete.length; i++) { - removeShadowNode(mShadowNodeRegistry.getNode(tagsToDelete[i])); - } - } - } - /** * An optimized version of manageChildren that is used for initial setting of child views. The * children are assumed to be in index order @@ -469,41 +348,6 @@ public void setChildren(int viewTag, ReadableArray childrenTags) { } } - /** - * Replaces the View specified by oldTag with the View specified by newTag within oldTag's parent. - */ - public void replaceExistingNonRootView(int oldTag, int newTag) { - if (mShadowNodeRegistry.isRootNode(oldTag) || mShadowNodeRegistry.isRootNode(newTag)) { - throw new IllegalViewOperationException("Trying to add or replace a root tag!"); - } - - ReactShadowNode oldNode = mShadowNodeRegistry.getNode(oldTag); - if (oldNode == null) { - throw new IllegalViewOperationException("Trying to replace unknown view tag: " + oldTag); - } - - ReactShadowNode parent = oldNode.getParent(); - if (parent == null) { - throw new IllegalViewOperationException("Node is not attached to a parent: " + oldTag); - } - - int oldIndex = parent.indexOf(oldNode); - if (oldIndex < 0) { - throw new IllegalStateException("Didn't find child tag in parent"); - } - - WritableArray tagsToAdd = Arguments.createArray(); - tagsToAdd.pushInt(newTag); - - WritableArray addAtIndices = Arguments.createArray(); - addAtIndices.pushInt(oldIndex); - - WritableArray indicesToRemove = Arguments.createArray(); - indicesToRemove.pushInt(oldIndex); - - manageChildren(parent.getReactTag(), null, null, tagsToAdd, addAtIndices, indicesToRemove); - } - /** * Find the touch target child native view in the supplied root view hierarchy, given a react * target location. diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index f0ed262acc0a..d6e5a2c3996c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -462,46 +462,6 @@ public void updateView(final int tag, final String className, final ReadableMap mUIImplementation.updateView(tag, className, props); } - /** - * Interface for adding/removing/moving views within a parent view from JS. - * - * @param viewTag the view tag of the parent view - * @param moveFrom a list of indices in the parent view to move views from - * @param moveTo parallel to moveFrom, a list of indices in the parent view to move views to - * @param addChildTags a list of tags of views to add to the parent - * @param addAtIndices parallel to addChildTags, a list of indices to insert those children at - * @param removeFrom a list of indices of views to permanently remove. The memory for the - * corresponding views and data structures should be reclaimed. - */ - @ReactMethod - public void manageChildren( - int viewTag, - @Nullable ReadableArray moveFrom, - @Nullable ReadableArray moveTo, - @Nullable ReadableArray addChildTags, - @Nullable ReadableArray addAtIndices, - @Nullable ReadableArray removeFrom) { - if (DEBUG) { - String message = - "(UIManager.manageChildren) tag: " - + viewTag - + ", moveFrom: " - + moveFrom - + ", moveTo: " - + moveTo - + ", addTags: " - + addChildTags - + ", atIndices: " - + addAtIndices - + ", removeFrom: " - + removeFrom; - FLog.d(ReactConstants.TAG, message); - PrinterHolder.getPrinter().logMessage(ReactDebugOverlayTags.UI_MANAGER, message); - } - mUIImplementation.manageChildren( - viewTag, moveFrom, moveTo, addChildTags, addAtIndices, removeFrom); - } - /** * Interface for fast tracking the initial adding of views. Children view tags are assumed to be * in order diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java index 8d46ee3eb49e..f098572d15bd 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java @@ -181,30 +181,6 @@ public void execute() { } } - private final class ManageChildrenOperation extends ViewOperation { - - private final @Nullable int[] mIndicesToRemove; - private final @Nullable ViewAtIndex[] mViewsToAdd; - private final @Nullable int[] mTagsToDelete; - - public ManageChildrenOperation( - int tag, - @Nullable int[] indicesToRemove, - @Nullable ViewAtIndex[] viewsToAdd, - @Nullable int[] tagsToDelete) { - super(tag); - mIndicesToRemove = indicesToRemove; - mViewsToAdd = viewsToAdd; - mTagsToDelete = tagsToDelete; - } - - @Override - public void execute() { - mNativeViewHierarchyManager.manageChildren( - mTag, mIndicesToRemove, mViewsToAdd, mTagsToDelete); - } - } - private final class SetChildrenOperation extends ViewOperation { private final ReadableArray mChildrenTags; @@ -734,15 +710,6 @@ public void enqueueUpdateLayout( new UpdateLayoutOperation(parentTag, reactTag, x, y, width, height, layoutDirection)); } - public void enqueueManageChildren( - int reactTag, - @Nullable int[] indicesToRemove, - @Nullable ViewAtIndex[] viewsToAdd, - @Nullable int[] tagsToDelete) { - mOperations.add( - new ManageChildrenOperation(reactTag, indicesToRemove, viewsToAdd, tagsToDelete)); - } - public void enqueueSetChildren(int reactTag, ReadableArray childrenTags) { mOperations.add(new SetChildrenOperation(reactTag, childrenTags)); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewAtIndex.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewAtIndex.kt deleted file mode 100644 index 1677d5deac39..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewAtIndex.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -@file:Suppress("DEPRECATION") - -package com.facebook.react.uimanager - -import com.facebook.react.common.annotations.internal.LegacyArchitecture -import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel -import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger -import java.util.Objects - -/** - * Data structure that couples view tag to it's index in parent view. Used for managing children - * operation. - */ -@LegacyArchitecture(logLevel = LegacyArchitectureLogLevel.ERROR) -@Deprecated( - message = "This class is part of Legacy Architecture and will be removed in a future release", - level = DeprecationLevel.WARNING, -) -internal class ViewAtIndex( - @Suppress("NoHungarianNotation") @JvmField public val mTag: Int, - @Suppress("NoHungarianNotation") @JvmField public val mIndex: Int, -) { - - override fun equals(other: Any?): Boolean { - if (other == null || other.javaClass != javaClass) { - return false - } - val otherViewAtIndex = other as ViewAtIndex - return mIndex == otherViewAtIndex.mIndex && mTag == otherViewAtIndex.mTag - } - - override fun hashCode(): Int = Objects.hash(mTag, mIndex) - - override fun toString(): String = "[$mTag, $mIndex]" - - companion object { - @JvmField - var COMPARATOR: Comparator = Comparator { lhs, rhs -> lhs.mIndex - rhs.mIndex } - - init { - LegacyArchitectureLogger.assertLegacyArchitecture( - "ViewAtIndex", - LegacyArchitectureLogLevel.ERROR, - ) - } - } -}