diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 3e8222f3bd0..5b503227f03 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -4742,6 +4742,7 @@ 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 deleted file mode 100644 index 6958e361ac2..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.java +++ /dev/null @@ -1,25 +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 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 new file mode 100644 index 00000000000..415eeba7fd3 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactOverflowView.kt @@ -0,0 +1,23 @@ +/* + * 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 43e1e4f8ac8..900473014d1 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,9 +127,16 @@ 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 @@ -158,9 +165,7 @@ public open class ReactViewGroup(context: Context) : val children = allChildren val listener = childrenLayoutChangeListener if (children != null && listener != null) { - for (i in 0 until allChildrenCount) { - children[i]?.removeOnLayoutChangeListener(listener) - } + children.forEach { child -> child?.removeOnLayoutChangeListener(listener) } } // Set default field values @@ -175,16 +180,6 @@ 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( @@ -335,9 +330,7 @@ public open class ReactViewGroup(context: Context) : val clippingRect = checkNotNull(_clippingRect) val children = checkNotNull(allChildren) val listener = checkNotNull(childrenLayoutChangeListener) - for (i in 0 until allChildrenCount) { - children[i]?.removeOnLayoutChangeListener(listener) - } + children.forEach { child -> child?.removeOnLayoutChangeListener(listener) } getDrawingRect(clippingRect) updateClippingToRect(clippingRect) allChildren = null @@ -635,9 +628,7 @@ public open class ReactViewGroup(context: Context) : internal open fun removeAllViewsWithSubviewClippingEnabled(): Unit { Assertions.assertCondition(_removeClippedSubviews) val children = checkNotNull(allChildren) - for (i in 0 until allChildrenCount) { - children[i]?.removeOnLayoutChangeListener(childrenLayoutChangeListener) - } + children.forEach { child -> child?.removeOnLayoutChangeListener(childrenLayoutChangeListener) } removeAllViewsInLayout() allChildrenCount = 0 } @@ -714,23 +705,22 @@ public open class ReactViewGroup(context: Context) : protected open fun getBackgroundColor(): Int = BackgroundStyleApplicator.getBackgroundColor(this) ?: DEFAULT_BACKGROUND_COLOR - // TODO: convert to val - public open fun setOverflow(overflow: String?): Unit { - _overflow = - if (overflow == null) { - Overflow.VISIBLE - } else { - Overflow.fromString(overflow) ?: Overflow.VISIBLE + override var overflow: String? + get() = + when (_overflow) { + Overflow.HIDDEN -> "hidden" + Overflow.SCROLL -> "scroll" + Overflow.VISIBLE -> "visible" } - invalidate() - } - - override fun getOverflow(): String? = - when (_overflow) { - Overflow.HIDDEN -> "hidden" - Overflow.SCROLL -> "scroll" - Overflow.VISIBLE -> "visible" - } + set(value) { + _overflow = + if (value == null) { + Overflow.VISIBLE + } else { + Overflow.fromString(value) ?: Overflow.VISIBLE + } + invalidate() + } override fun setOverflowInset(left: Int, top: Int, right: Int, bottom: Int) { if (needsIsolatedLayer() && @@ -768,8 +758,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() @@ -800,8 +790,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) } }