Skip to content

Commit 7f1edbd

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Migrate ReactClippingViewGroup to Kotlin (#49413)
Summary: Migrate com.facebook.react.uimanager.ReactClippingViewGroup to Kotlin ## Changelog: [INTERNAL] - Migrate com.facebook.react.uimanager.ReactClippingViewGroup to Kotlin Pull Request resolved: #49413 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: rshest Differential Revision: D69750532 Pulled By: cortinico fbshipit-source-id: 50ec87a71b3bd523e1a9518b8bd683a027a4b422
1 parent e4e03bd commit 7f1edbd

File tree

3 files changed

+61
-66
lines changed

3 files changed

+61
-66
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactClippingViewGroup.java

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.uimanager
9+
10+
import android.graphics.Rect
11+
import android.view.View
12+
13+
/**
14+
* Interface that should be implemented by [View] subclasses that support `removeClippedSubviews`
15+
* property. When this property is set for the [ViewGroup] subclass it's responsible for detaching
16+
* it's child views that are clipped by the view boundaries. Those view boundaries should be
17+
* determined based on it's parent clipping area and current view's offset in parent and doesn't
18+
* necessarily reflect the view visible area (in a sense of a value that [View.getGlobalVisibleRect]
19+
* may return). In order to determine the clipping rect for current view helper method
20+
* [ReactClippingViewGroupHelper.calculateClippingRect] can be used that takes into account parent
21+
* view settings.
22+
*/
23+
public interface ReactClippingViewGroup {
24+
/**
25+
* Notify view that clipping area may have changed and it should recalculate the list of children
26+
* that should be attached/detached. This method should be called only when property
27+
* `removeClippedSubviews` is set to `true` on a view.
28+
*
29+
* CAUTION: Views are responsible for calling [updateClippingRect] on it's children. This should
30+
* happen if child implement [ReactClippingViewGroup], return true from [getRemoveClippedSubviews]
31+
* and clipping rect change of the current view may affect clipping rect of this child.
32+
*/
33+
public fun updateClippingRect()
34+
35+
/**
36+
* Get rectangular bounds to which view is currently clipped to. Called only on views that has set
37+
* `removeCLippedSubviews` property value to `true`.
38+
*
39+
* @param outClippingRect output clipping rect should be written to this object.
40+
*/
41+
public fun getClippingRect(outClippingRect: Rect)
42+
43+
/**
44+
* Sets property `removeClippedSubviews` as a result of property update in JS. Should be called
45+
* only from [ViewManager.updateView] method.
46+
*
47+
* Helper method [ReactClippingViewGroupHelper.applyRemoveClippedSubviewsProperty] may be used by
48+
* [ViewManager] subclass to apply this property based on property update map
49+
* [ReactStylesDiffMap].
50+
*/
51+
public var removeClippedSubviews: Boolean
52+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollContainerLegacyView.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ internal class ReactHorizontalScrollContainerLegacyView(context: Context) :
1919
ReactViewGroup(context) {
2020
private val isRTL: Boolean = I18nUtil.instance.isRTL(context)
2121

22-
override fun setRemoveClippedSubviews(removeClippedSubviews: Boolean) {
23-
// removeClippedSubviews logic may read metrics before the offsetting we do in onLayout() and is
24-
// such unsafe
25-
if (isRTL) {
26-
super.setRemoveClippedSubviews(false)
27-
return
22+
override var removeClippedSubviews: Boolean = false
23+
set(value) {
24+
// removeClippedSubviews logic may read metrics before the offsetting we do in onLayout() and
25+
// is such unsafe
26+
if (isRTL) {
27+
field = false
28+
} else {
29+
field = value
30+
}
2831
}
2932

30-
super.setRemoveClippedSubviews(removeClippedSubviews)
31-
}
32-
3333
protected override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
3434
if (isRTL) {
3535
// When the layout direction is RTL, we expect Yoga to give us a layout

0 commit comments

Comments
 (0)