From cc569d83427958c42bfd372c00479b5284755ee0 Mon Sep 17 00:00:00 2001 From: "priyanka.raghuvanshi" Date: Sun, 13 Apr 2025 00:48:01 +0530 Subject: [PATCH 1/3] Migrate ReactClippingViewGroupHelper.java to Kotlin --- .../ReactClippingViewGroupHelper.java | 65 ----------------- .../uimanager/ReactClippingViewGroupHelper.kt | 71 +++++++++++++++++++ 2 files changed, 71 insertions(+), 65 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.java deleted file mode 100644 index ff88e2471da764..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.java +++ /dev/null @@ -1,65 +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.graphics.Rect; -import android.view.View; -import android.view.ViewParent; -import com.facebook.infer.annotation.Nullsafe; -import javax.annotation.concurrent.NotThreadSafe; - -/** - * Provides implementation of common tasks for view and it's view manager supporting property {@code - * removeClippedSubviews}. - */ -@Nullsafe(Nullsafe.Mode.LOCAL) -@NotThreadSafe -public class ReactClippingViewGroupHelper { - - public static final String PROP_REMOVE_CLIPPED_SUBVIEWS = "removeClippedSubviews"; - - private static final Rect sHelperRect = new Rect(); - - /** - * Can be used by view that support {@code removeClippedSubviews} property to calculate area that - * given {@param view} should be clipped to based on the clipping rectangle of it's parent in case - * when parent is also set to clip it's children. - * - * @param view view that we want to calculate clipping rect for - * @param outputRect where the calculated rectangle will be written - */ - public static void calculateClippingRect(View view, Rect outputRect) { - ViewParent parent = view.getParent(); - if (parent == null) { - outputRect.setEmpty(); - return; - } else if (parent instanceof ReactClippingViewGroup) { - ReactClippingViewGroup clippingViewGroup = (ReactClippingViewGroup) parent; - if (clippingViewGroup.getRemoveClippedSubviews()) { - clippingViewGroup.getClippingRect(sHelperRect); - // Intersect the view with the parent's rectangle - // This will result in the overlap with coordinates in the parent space - if (!sHelperRect.intersect( - view.getLeft(), - view.getTop() + (int) view.getTranslationY(), - view.getRight(), - view.getBottom() + (int) view.getTranslationY())) { - outputRect.setEmpty(); - return; - } - // Now we move the coordinates to the View's coordinate space - sHelperRect.offset(-view.getLeft(), -view.getTop()); - sHelperRect.offset(-(int) view.getTranslationX(), -(int) view.getTranslationY()); - sHelperRect.offset(view.getScrollX(), view.getScrollY()); - outputRect.set(sHelperRect); - return; - } - } - view.getDrawingRect(outputRect); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt new file mode 100644 index 00000000000000..5cef1651d4b901 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt @@ -0,0 +1,71 @@ +/* + * 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.graphics.Rect + import android.view.View + import com.facebook.infer.annotation.Nullsafe + import javax.annotation.concurrent.NotThreadSafe + + /** + * Provides implementation of common tasks for view and it's view manager supporting property + * [removeClippedSubviews]. + */ + @Nullsafe(Nullsafe.Mode.LOCAL) + @NotThreadSafe + public object ReactClippingViewGroupHelper { + + public const val PROP_REMOVE_CLIPPED_SUBVIEWS: String = "removeClippedSubviews" + + private val sHelperRect: Rect = Rect() + + /** + * Can be used by view that support [removeClippedSubviews] property to calculate area that + * given [view] should be clipped to based on the clipping rectangle of it's parent in case when + * parent is also set to clip it's children. + * + * @param view view that we want to calculate clipping rect for + * @param outputRect where the calculated rectangle will be written + */ + @JvmStatic + public fun calculateClippingRect(view: View, outputRect: Rect): Unit { + val parent = view.parent + when { + parent == null -> { + outputRect.setEmpty() + return + } + parent is ReactClippingViewGroup -> { + if (parent.removeClippedSubviews) { + parent.getClippingRect(sHelperRect) + // Intersect the view with the parent's rectangle + // This will result in the overlap with coordinates in the parent space + if ( + !sHelperRect.intersect( + view.left, + view.top + view.translationY.toInt(), + view.right, + view.bottom + view.translationY.toInt() + ) + ) { + outputRect.setEmpty() + return + } + // Now we move the coordinates to the View's coordinate space + sHelperRect.offset(-view.left, -view.top) + sHelperRect.offset(-view.translationX.toInt(), -view.translationY.toInt()) + sHelperRect.offset(view.scrollX, view.scrollY) + outputRect.set(sHelperRect) + return + } + } + } + view.getDrawingRect(outputRect) + } + } + \ No newline at end of file From 38b2a0157ae283f5eb9e785eb897e0ea216f448e Mon Sep 17 00:00:00 2001 From: "priyanka.raghuvanshi" Date: Mon, 14 Apr 2025 18:55:34 +0530 Subject: [PATCH 2/3] Resolving Comments --- .../uimanager/ReactClippingViewGroupHelper.kt | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt index 5cef1651d4b901..0d65ff51790ac9 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt @@ -9,20 +9,18 @@ import android.graphics.Rect import android.view.View - import com.facebook.infer.annotation.Nullsafe import javax.annotation.concurrent.NotThreadSafe /** * Provides implementation of common tasks for view and it's view manager supporting property * [removeClippedSubviews]. */ - @Nullsafe(Nullsafe.Mode.LOCAL) @NotThreadSafe public object ReactClippingViewGroupHelper { public const val PROP_REMOVE_CLIPPED_SUBVIEWS: String = "removeClippedSubviews" - private val sHelperRect: Rect = Rect() + private val helperRect: Rect = Rect() /** * Can be used by view that support [removeClippedSubviews] property to calculate area that @@ -34,19 +32,18 @@ */ @JvmStatic public fun calculateClippingRect(view: View, outputRect: Rect): Unit { - val parent = view.parent - when { - parent == null -> { + when (val parent = view.parent) { + null -> { outputRect.setEmpty() return } - parent is ReactClippingViewGroup -> { + is ReactClippingViewGroup -> { if (parent.removeClippedSubviews) { - parent.getClippingRect(sHelperRect) + parent.getClippingRect(helperRect) // Intersect the view with the parent's rectangle // This will result in the overlap with coordinates in the parent space if ( - !sHelperRect.intersect( + !helperRect.intersect( view.left, view.top + view.translationY.toInt(), view.right, @@ -57,10 +54,10 @@ return } // Now we move the coordinates to the View's coordinate space - sHelperRect.offset(-view.left, -view.top) - sHelperRect.offset(-view.translationX.toInt(), -view.translationY.toInt()) - sHelperRect.offset(view.scrollX, view.scrollY) - outputRect.set(sHelperRect) + helperRect.offset(-view.left, -view.top) + helperRect.offset(-view.translationX.toInt(), -view.translationY.toInt()) + helperRect.offset(view.scrollX, view.scrollY) + outputRect.set(helperRect) return } } From 8e0539fac344684469434af751f7d4d205552b3e Mon Sep 17 00:00:00 2001 From: "priyanka.raghuvanshi" Date: Mon, 14 Apr 2025 19:00:07 +0530 Subject: [PATCH 3/3] Resolving Comments --- .../facebook/react/uimanager/ReactClippingViewGroupHelper.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt index 0d65ff51790ac9..b0ea87837bd7fd 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroupHelper.kt @@ -41,7 +41,6 @@ if (parent.removeClippedSubviews) { parent.getClippingRect(helperRect) // Intersect the view with the parent's rectangle - // This will result in the overlap with coordinates in the parent space if ( !helperRect.intersect( view.left, @@ -53,7 +52,7 @@ outputRect.setEmpty() return } - // Now we move the coordinates to the View's coordinate space + // Move coordinates to View's coordinate space helperRect.offset(-view.left, -view.top) helperRect.offset(-view.translationX.toInt(), -view.translationY.toInt()) helperRect.offset(view.scrollX, view.scrollY)