From a886a2fa05ca2e0c8793c570d9f19caf4062b892 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 26 Sep 2024 15:50:26 -0700 Subject: [PATCH] Back out "ReactViewGroup post-conversion cleanup" Summary: Backing out the stack since a same crash that previously effected many apps appeared again, and there are changes soon landing that will add more conflicts. Reviewed By: Abbondanzo Differential Revision: D63493334 fbshipit-source-id: 175fc7b5b69aa2874c867e460ab102bb077a7cd8 --- .../ReactAndroid/api/ReactAndroid.api | 1 - .../react/uimanager/ReactOverflowView.java | 25 +++++++ .../react/uimanager/ReactOverflowView.kt | 23 ------ .../react/views/view/ReactViewGroup.kt | 70 +++++++++++-------- 4 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.java delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 5b503227f03..3e8222f3bd0 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -4742,7 +4742,6 @@ public final class com/facebook/react/uimanager/ReactInvalidPropertyException : public abstract interface class com/facebook/react/uimanager/ReactOverflowView { public abstract fun getOverflow ()Ljava/lang/String; - public abstract fun setOverflow (Ljava/lang/String;)V } public abstract interface class com/facebook/react/uimanager/ReactOverflowViewWithInset : com/facebook/react/uimanager/ReactOverflowView { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.java new file mode 100644 index 00000000000..6958e361ac2 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.java @@ -0,0 +1,25 @@ +/* + * 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 androidx.annotation.Nullable; + +/** + * Interface that should be implemented by {@link View} subclasses that support {@code overflow} + * style. This allows the overflow information to be used by {@link TouchTargetHelper} to determine + * if a View is touchable. + */ +public interface ReactOverflowView { + /** + * Gets the overflow state of a view. If set, this should be one of {@link ViewProps#HIDDEN}, + * {@link ViewProps#VISIBLE} or {@link ViewProps#SCROLL}. + */ + @Nullable + String getOverflow(); +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.kt deleted file mode 100644 index 415eeba7fd3..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.kt +++ /dev/null @@ -1,23 +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 - -/** - * Interface that should be implemented by [View] subclasses that support `overflow` style. This - * allows the overflow information to be used by [TouchTargetHelper] to determine if a View is - * touchable. - */ -public interface ReactOverflowView { - /** - * The overflow state of a view. If set, this should be one of: - * - [ViewProps.HIDDEN], - * - [ViewProps.VISIBLE] - * - [ViewProps.SCROLL]. - */ - public var overflow: String? -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt index 900473014d1..43e1e4f8ac8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt @@ -127,16 +127,9 @@ public open class ReactViewGroup(context: Context) : private var childrenLayoutChangeListener: ChildrenLayoutChangeListener? = null private var onInterceptTouchEventListener: OnInterceptTouchEventListener? = null private var needsOffscreenAlphaCompositing = false + private var _drawingOrderHelper: ViewGroupDrawingOrderHelper? = null private var backfaceOpacity = 1f private var backfaceVisibility: String? = "visible" - private var _drawingOrderHelper: ViewGroupDrawingOrderHelper? = null - private val drawingOrderHelper: ViewGroupDrawingOrderHelper - get() = - _drawingOrderHelper ?: ViewGroupDrawingOrderHelper(this).also { _drawingOrderHelper = it } - - init { - initView() - } /** * Set all default values here as opposed to in the constructor or field defaults. It is important @@ -165,7 +158,9 @@ public open class ReactViewGroup(context: Context) : val children = allChildren val listener = childrenLayoutChangeListener if (children != null && listener != null) { - children.forEach { child -> child?.removeOnLayoutChangeListener(listener) } + for (i in 0 until allChildrenCount) { + children[i]?.removeOnLayoutChangeListener(listener) + } } // Set default field values @@ -180,6 +175,16 @@ public open class ReactViewGroup(context: Context) : resetPointerEvents() } + private val drawingOrderHelper: ViewGroupDrawingOrderHelper + get() { + return _drawingOrderHelper + ?: ViewGroupDrawingOrderHelper(this).also { _drawingOrderHelper = it } + } + + init { + initView() + } + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { MeasureSpecAssertions.assertExplicitMeasureSpec(widthMeasureSpec, heightMeasureSpec) setMeasuredDimension( @@ -330,7 +335,9 @@ public open class ReactViewGroup(context: Context) : val clippingRect = checkNotNull(_clippingRect) val children = checkNotNull(allChildren) val listener = checkNotNull(childrenLayoutChangeListener) - children.forEach { child -> child?.removeOnLayoutChangeListener(listener) } + for (i in 0 until allChildrenCount) { + children[i]?.removeOnLayoutChangeListener(listener) + } getDrawingRect(clippingRect) updateClippingToRect(clippingRect) allChildren = null @@ -628,7 +635,9 @@ public open class ReactViewGroup(context: Context) : internal open fun removeAllViewsWithSubviewClippingEnabled(): Unit { Assertions.assertCondition(_removeClippedSubviews) val children = checkNotNull(allChildren) - children.forEach { child -> child?.removeOnLayoutChangeListener(childrenLayoutChangeListener) } + for (i in 0 until allChildrenCount) { + children[i]?.removeOnLayoutChangeListener(childrenLayoutChangeListener) + } removeAllViewsInLayout() allChildrenCount = 0 } @@ -705,22 +714,23 @@ public open class ReactViewGroup(context: Context) : protected open fun getBackgroundColor(): Int = BackgroundStyleApplicator.getBackgroundColor(this) ?: DEFAULT_BACKGROUND_COLOR - override var overflow: String? - get() = - when (_overflow) { - Overflow.HIDDEN -> "hidden" - Overflow.SCROLL -> "scroll" - Overflow.VISIBLE -> "visible" + // TODO: convert to val + public open fun setOverflow(overflow: String?): Unit { + _overflow = + if (overflow == null) { + Overflow.VISIBLE + } else { + Overflow.fromString(overflow) ?: Overflow.VISIBLE } - set(value) { - _overflow = - if (value == null) { - Overflow.VISIBLE - } else { - Overflow.fromString(value) ?: Overflow.VISIBLE - } - invalidate() - } + invalidate() + } + + override fun getOverflow(): String? = + when (_overflow) { + Overflow.HIDDEN -> "hidden" + Overflow.SCROLL -> "scroll" + Overflow.VISIBLE -> "visible" + } override fun setOverflowInset(left: Int, top: Int, right: Int, bottom: Int) { if (needsIsolatedLayer() && @@ -758,8 +768,8 @@ public open class ReactViewGroup(context: Context) : canvas.saveLayer( overflowInset.left.toFloat(), overflowInset.top.toFloat(), - (width - overflowInset.right).toFloat(), - (height - overflowInset.bottom).toFloat(), + (width + -overflowInset.right).toFloat(), + (height + -overflowInset.bottom).toFloat(), null) super.draw(canvas) canvas.restore() @@ -790,8 +800,8 @@ public open class ReactViewGroup(context: Context) : canvas.saveLayer( overflowInset.left.toFloat(), overflowInset.top.toFloat(), - (width - overflowInset.right).toFloat(), - (height - overflowInset.bottom).toFloat(), + (width + -overflowInset.right).toFloat(), + (height + -overflowInset.bottom).toFloat(), p) } }