Remove setViewZIndex and associated state from BaseViewManager (#56717)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56717

This is a follow-up to D91121582 which deprecated ReactZIndexedViewGroup and removed custom draw order logic from ReactViewGroup. That diff kept `setZIndex()` in BaseViewManager and BaseViewManagerDelegate for backward compatibility, to be removed in a follow-up.

This diff completes that cleanup by removing:
- The `setZIndex` method from `BaseViewManager` (which called `ViewGroupManager.setViewZIndex` and triggered `updateDrawingOrder()` on the parent)
- The `Z_INDEX` case from `BaseViewManagerDelegate`
- The `zIndexHash` WeakHashMap, `setViewZIndex`, and `getViewZIndex` static methods from `ViewGroupManager`'s companion object
- The `ViewGroupDrawingOrderHelper` class, which was dead code (marked `LegacyArchitecture`, no longer imported anywhere) and depended on the removed `getViewZIndex`

Z-index is now fully managed at the C++ Fabric layer, and these Android-side mechanisms are no longer needed.

Changelog: [Android][Removed] Removed `ViewGroupManager.setViewZIndex`/`getViewZIndex` and `ViewGroupDrawingOrderHelper` — z-index is now fully managed by the Fabric C++ layer

Reviewed By: sammy-SC

Differential Revision: D104101783

fbshipit-source-id: 7c69afc307cef9ebe3a939cf559050372f093c97
This commit is contained in:
Pieter De Baets authored and meta-codesync[bot] committed 2026-05-07 06:24:20 -07:00
1 parent 91702e50fe
commit c49aa90a86
6 files changed
+2 -206

No files matched your search

@@ -4090,11 +4090,6 @@ public final class com/facebook/react/uimanager/ReactStylesDiffMap {
public fun toString ()Ljava/lang/String;
}
public abstract interface class com/facebook/react/uimanager/ReactZIndexedViewGroup {
public abstract fun getZIndexMappedChildIndex (I)I
public abstract fun updateDrawingOrder ()V
}
public abstract interface class com/facebook/react/uimanager/RootView {
public abstract fun handleException (Ljava/lang/Throwable;)V
public abstract fun onChildEndedNativeGesture (Landroid/view/View;Landroid/view/MotionEvent;)V
@@ -4400,17 +4395,7 @@ public final class com/facebook/react/uimanager/ViewDefaults {
public static final field NUMBER_OF_LINES I
}
public final class com/facebook/react/uimanager/ViewGroupDrawingOrderHelper {
public fun <init> (Landroid/view/ViewGroup;)V
public final fun getChildDrawingOrder (II)I
public final fun handleAddView (Landroid/view/View;)V
public final fun handleRemoveView (Landroid/view/View;)V
public final fun shouldEnableCustomDrawingOrder ()Z
public final fun update ()V
}
public abstract class com/facebook/react/uimanager/ViewGroupManager : com/facebook/react/uimanager/BaseViewManager, com/facebook/react/uimanager/IViewGroupManager {
public static final field Companion Lcom/facebook/react/uimanager/ViewGroupManager$Companion;
public fun <init> ()V
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
public synthetic fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
@@ -4424,21 +4409,14 @@ public abstract class com/facebook/react/uimanager/ViewGroupManager : com/facebo
public synthetic fun getChildCount (Landroid/view/View;)I
public fun getChildCount (Landroid/view/ViewGroup;)I
public fun getShadowNodeClass ()Ljava/lang/Class;
public static final fun getViewZIndex (Landroid/view/View;)Ljava/lang/Integer;
public fun needsCustomLayoutForChildren ()Z
public fun removeView (Landroid/view/ViewGroup;Landroid/view/View;)V
public synthetic fun removeViewAt (Landroid/view/View;I)V
public fun removeViewAt (Landroid/view/ViewGroup;I)V
public static final fun setViewZIndex (Landroid/view/View;I)V
public synthetic fun updateExtraData (Landroid/view/View;Ljava/lang/Object;)V
public fun updateExtraData (Landroid/view/ViewGroup;Ljava/lang/Object;)V
}
public final class com/facebook/react/uimanager/ViewGroupManager$Companion {
public final fun getViewZIndex (Landroid/view/View;)Ljava/lang/Integer;
public final fun setViewZIndex (Landroid/view/View;I)V
}
public abstract class com/facebook/react/uimanager/ViewManager : com/facebook/react/bridge/BaseJavaModule {
public fun <init> ()V
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
@@ -6445,7 +6423,7 @@ public final class com/facebook/react/views/view/ReactDrawableHelper {
public static final fun createDrawableFromJSDescription (Landroid/content/Context;Lcom/facebook/react/bridge/ReadableMap;)Landroid/graphics/drawable/Drawable;
}
public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGroup, com/facebook/react/touch/ReactHitSlopView, com/facebook/react/touch/ReactInterceptingViewGroup, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/uimanager/ReactPointerEventsView, com/facebook/react/uimanager/ReactZIndexedViewGroup {
public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGroup, com/facebook/react/touch/ReactHitSlopView, com/facebook/react/touch/ReactInterceptingViewGroup, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/uimanager/ReactPointerEventsView {
public fun <init> (Landroid/content/Context;)V
public fun addChildrenForAccessibility (Ljava/util/ArrayList;)V
public final fun cleanUpAxOrderListener ()V
@@ -6465,7 +6443,6 @@ public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGro
public fun getOverflowInset ()Landroid/graphics/Rect;
public fun getPointerEvents ()Lcom/facebook/react/uimanager/PointerEvents;
public fun getRemoveClippedSubviews ()Z
public fun getZIndexMappedChildIndex (I)I
public fun hasOverlappingRendering ()Z
protected fun onAttachedToWindow ()V
public fun onHoverEvent (Landroid/view/MotionEvent;)Z
@@ -6498,7 +6475,6 @@ public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGro
public final fun setTranslucentBackgroundDrawable (Landroid/graphics/drawable/Drawable;)V
public fun updateClippingRect ()V
public fun updateClippingRect (Ljava/util/Set;)V
public fun updateDrawingOrder ()V
}
public class com/facebook/react/views/view/ReactViewManager : com/facebook/react/views/view/ReactClippingViewManager {
@@ -14,7 +14,6 @@ import android.text.TextUtils;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityEvent;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
@@ -285,12 +284,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
@ReactProp(name = ViewProps.Z_INDEX)
public void setZIndex(@NonNull T view, float zIndex) {
int integerZIndex = Math.round(zIndex);
ViewGroupManager.setViewZIndex(view, integerZIndex);
ViewParent parent = view.getParent();
if (parent instanceof ReactZIndexedViewGroup) {
((ReactZIndexedViewGroup) parent).updateDrawingOrder();
}
// No-op: Z-order is managed at the C++ layer in Fabric
}
@ReactProp(name = ViewProps.RENDER_TO_HARDWARE_TEXTURE)
@@ -1,35 +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.
*/
package com.facebook.react.uimanager
import com.facebook.react.common.annotations.internal.LegacyArchitecture
/**
* ViewGroup that supports z-index.
*
* This interface is part of the legacy architecture. CustomDrawOrder is no longer used when Fabric
* is enabled, which is now everywhere. Z-order is managed at the C++ layer, and no re-ordering is
* needed in the Android View layer. This interface is kept for backward compatibility but should
* not be used in new code.
*/
@LegacyArchitecture
public interface ReactZIndexedViewGroup {
/**
* Determine the index of a child view at [index] considering z-index.
*
* @param index The child view index
* @return The child view index considering z-index
*/
public fun getZIndexMappedChildIndex(index: Int): Int
/**
* Redraw the view based on updated child z-index. This should be called after updating one of its
* child z-index.
*/
public fun updateDrawingOrder()
}
@@ -1,113 +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.
*/
package com.facebook.react.uimanager
import android.view.View
import android.view.ViewGroup
import com.facebook.common.logging.FLog
import com.facebook.react.common.ReactConstants
import com.facebook.react.common.annotations.internal.LegacyArchitecture
/** Helper to handle implementing ViewGroups with custom drawing order based on z-index. */
@LegacyArchitecture
public class ViewGroupDrawingOrderHelper(private val viewGroup: ViewGroup) {
private var numberOfChildrenWithZIndex = 0
private var drawingOrderIndices: IntArray? = null
/**
* This should be called every time a view is added to the ViewGroup in [ViewGroup.addView].
*
* @param view The view that is being added
*/
public fun handleAddView(view: View) {
if (ViewGroupManager.getViewZIndex(view) != null) {
numberOfChildrenWithZIndex++
}
drawingOrderIndices = null
}
/**
* This should be called every time a view is removed from the ViewGroup in [ViewGroup.removeView]
* and [ViewGroup.removeViewAt].
*
* @param view The view that is being removed.
*/
public fun handleRemoveView(view: View?) {
if (ViewGroupManager.getViewZIndex(view) != null) {
numberOfChildrenWithZIndex--
}
drawingOrderIndices = null
}
/**
* If the ViewGroup should enable drawing order. ViewGroups should call
* [ViewGroup.setChildrenDrawingOrderEnabled] with the value returned from this method when a view
* is added or removed.
*/
public fun shouldEnableCustomDrawingOrder(): Boolean = numberOfChildrenWithZIndex > 0
/**
* The index of the child view that should be drawn. This should be used in
* [ViewGroup.getChildDrawingOrder].
*/
public fun getChildDrawingOrder(childCount: Int, index: Int): Int {
var currentDrawingOrderIndices = this.drawingOrderIndices
if (
currentDrawingOrderIndices != null &&
(index >= currentDrawingOrderIndices.size ||
currentDrawingOrderIndices[index] >= childCount)
) {
FLog.w(
ReactConstants.TAG,
"getChildDrawingOrder index out of bounds! Please check any custom view manipulations you" +
" may have done. childCount = %d, index = %d",
childCount,
index,
)
update()
}
if (currentDrawingOrderIndices == null) {
val viewsToSort = ArrayList<View>()
for (i in 0 until childCount) {
viewsToSort.add(viewGroup.getChildAt(i))
}
// Sort the views by zIndex
viewsToSort.sortWith { view1, view2 ->
val view1ZIndex = ViewGroupManager.getViewZIndex(view1) ?: 0
val view2ZIndex = ViewGroupManager.getViewZIndex(view2) ?: 0
view1ZIndex - view2ZIndex
}
currentDrawingOrderIndices = IntArray(childCount)
for (i in 0 until childCount) {
val child = viewsToSort[i]
currentDrawingOrderIndices[i] = viewGroup.indexOfChild(child)
}
this.drawingOrderIndices = currentDrawingOrderIndices
}
return currentDrawingOrderIndices[index]
}
/** Recheck all children for z-index changes. */
public fun update() {
numberOfChildrenWithZIndex = 0
for (i in 0 until viewGroup.childCount) {
val child = viewGroup.getChildAt(i)
if (ViewGroupManager.getViewZIndex(child) != null) {
numberOfChildrenWithZIndex++
}
}
drawingOrderIndices = null
}
}
@@ -11,7 +11,6 @@ import android.view.View
import android.view.ViewGroup
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.UiThreadUtil
import java.util.WeakHashMap
@Suppress("DEPRECATION")
public abstract class ViewGroupManager<T : ViewGroup>
@@ -76,13 +75,4 @@ constructor(reactContext: ReactApplicationContext? = null) :
* that case, onLayout for this View type must *not* call layout on its children.
*/
public override fun needsCustomLayoutForChildren(): Boolean = false
public companion object {
private val zIndexHash: WeakHashMap<View, Int> = WeakHashMap()
@JvmStatic
public fun setViewZIndex(view: View, zIndex: Int): Unit = zIndexHash.set(view, zIndex)
@JvmStatic public fun getViewZIndex(view: View?): Int? = zIndexHash[view]
}
}
@@ -58,7 +58,6 @@ import com.facebook.react.uimanager.ReactClippingViewGroup
import com.facebook.react.uimanager.ReactClippingViewGroupHelper.calculateClippingRect
import com.facebook.react.uimanager.ReactOverflowViewWithInset
import com.facebook.react.uimanager.ReactPointerEventsView
import com.facebook.react.uimanager.ReactZIndexedViewGroup
import com.facebook.react.uimanager.style.BorderRadiusProp
import com.facebook.react.uimanager.style.BorderStyle
import com.facebook.react.uimanager.style.LogicalEdge
@@ -81,7 +80,6 @@ public open class ReactViewGroup public constructor(context: Context?) :
ReactClippingViewGroup,
ReactPointerEventsView,
ReactHitSlopView,
ReactZIndexedViewGroup,
ReactOverflowViewWithInset {
public override val overflowInset: Rect = Rect()
@@ -622,20 +620,6 @@ public open class ReactViewGroup public constructor(context: Context?) :
}
}
/**
* No-op implementation for backward compatibility. Z-order is now managed at the C++ layer in
* Fabric.
*/
override fun getZIndexMappedChildIndex(index: Int): Int = index
/**
* No-op implementation for backward compatibility. Z-order is now managed at the C++ layer in
* Fabric.
*/
override fun updateDrawingOrder() {
// No-op: Z-order is managed at the C++ layer
}
override fun dispatchSetPressed(pressed: Boolean) {
// Prevents the ViewGroup from dispatching the pressed state
// to it's children.