Skip to content

Commit f1d7016

Browse files
Thomas Nardonefacebook-github-bot
authored andcommitted
ReactViewGroup cleanup (#47674)
Summary: Pull Request resolved: #47674 Small changes that can be done in Java and make a Kotlin conversion more seamless. Changelog: [Internal] Reviewed By: javache Differential Revision: D66033963 fbshipit-source-id: 666302f132b98019f1013a335a2c59c7a4f31836
1 parent 74995bc commit f1d7016

File tree

2 files changed

+27
-39
lines changed

2 files changed

+27
-39
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7832,7 +7832,6 @@ public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGro
78327832
public fun draw (Landroid/graphics/Canvas;)V
78337833
protected fun drawChild (Landroid/graphics/Canvas;Landroid/view/View;J)Z
78347834
protected fun getChildDrawingOrder (II)I
7835-
public fun getChildVisibleRect (Landroid/view/View;Landroid/graphics/Rect;Landroid/graphics/Point;)Z
78367835
public fun getClippingRect (Landroid/graphics/Rect;)V
78377836
public fun getHitSlopRect ()Landroid/graphics/Rect;
78387837
public fun getOverflow ()Ljava/lang/String;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import android.graphics.Canvas;
1818
import android.graphics.Color;
1919
import android.graphics.Paint;
20-
import android.graphics.Path;
2120
import android.graphics.Rect;
2221
import android.graphics.drawable.Drawable;
2322
import android.os.Build;
@@ -54,7 +53,6 @@
5453
import com.facebook.react.uimanager.ViewGroupDrawingOrderHelper;
5554
import com.facebook.react.uimanager.common.UIManagerType;
5655
import com.facebook.react.uimanager.common.ViewUtil;
57-
import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable;
5856
import com.facebook.react.uimanager.style.BorderRadiusProp;
5957
import com.facebook.react.uimanager.style.BorderStyle;
6058
import com.facebook.react.uimanager.style.LogicalEdge;
@@ -131,13 +129,11 @@ public void shutdown() {
131129
private @Nullable Rect mClippingRect;
132130
private @Nullable Rect mHitSlopRect;
133131
private Overflow mOverflow;
134-
private PointerEvents mPointerEvents;
132+
private PointerEvents mPointerEvents = PointerEvents.AUTO;
135133
private @Nullable ChildrenLayoutChangeListener mChildrenLayoutChangeListener;
136-
private @Nullable CSSBackgroundDrawable mCSSBackgroundDrawable;
137134
private @Nullable OnInterceptTouchEventListener mOnInterceptTouchEventListener;
138135
private boolean mNeedsOffscreenAlphaCompositing;
139136
private @Nullable ViewGroupDrawingOrderHelper mDrawingOrderHelper;
140-
private @Nullable Path mPath;
141137
private float mBackfaceOpacity;
142138
private String mBackfaceVisibility;
143139

@@ -168,11 +164,9 @@ private void initView() {
168164
mOverflow = Overflow.VISIBLE;
169165
mPointerEvents = PointerEvents.AUTO;
170166
mChildrenLayoutChangeListener = null;
171-
mCSSBackgroundDrawable = null;
172167
mOnInterceptTouchEventListener = null;
173168
mNeedsOffscreenAlphaCompositing = false;
174169
mDrawingOrderHelper = null;
175-
mPath = null;
176170
mBackfaceOpacity = 1.f;
177171
mBackfaceVisibility = "visible";
178172
}
@@ -266,7 +260,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
266260
}
267261

268262
@Override
269-
public boolean onTouchEvent(MotionEvent ev) {
263+
public boolean onTouchEvent(MotionEvent event) {
270264
// We do not accept the touch event if this view is not supposed to receive it.
271265
if (!PointerEvents.canBeTouchTarget(mPointerEvents)) {
272266
return false;
@@ -505,11 +499,6 @@ private void updateSubviewClipStatus(View subview) {
505499
}
506500
}
507501

508-
@Override
509-
public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset) {
510-
return super.getChildVisibleRect(child, r, offset);
511-
}
512-
513502
@Override
514503
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
515504
super.onSizeChanged(w, h, oldw, oldh);
@@ -685,18 +674,18 @@ View getChildAtWithSubviewClippingEnabled(int index) {
685674
/*package*/ void addViewWithSubviewClippingEnabled(
686675
final View child, int index, ViewGroup.LayoutParams params) {
687676
Assertions.assertCondition(mRemoveClippedSubviews);
688-
Assertions.assertNotNull(mClippingRect);
689-
Assertions.assertNotNull(mAllChildren);
677+
Rect clippingRect = Assertions.assertNotNull(mClippingRect);
678+
View[] childArray = Assertions.assertNotNull(mAllChildren);
690679
addInArray(child, index);
691680
// we add view as "clipped" and then run {@link #updateSubviewClipStatus} to conditionally
692681
// attach it
693682
int clippedSoFar = 0;
694683
for (int i = 0; i < index; i++) {
695-
if (mAllChildren[i].getParent() == null) {
684+
if (childArray[i].getParent() == null) {
696685
clippedSoFar++;
697686
}
698687
}
699-
updateSubviewClipStatus(mClippingRect, index, clippedSoFar);
688+
updateSubviewClipStatus(clippingRect, index, clippedSoFar);
700689
child.addOnLayoutChangeListener(mChildrenLayoutChangeListener);
701690

702691
if (child instanceof ReactClippingProhibitedView) {
@@ -728,13 +717,13 @@ public void run() {
728717

729718
Assertions.assertCondition(mRemoveClippedSubviews);
730719
Assertions.assertNotNull(mClippingRect);
731-
Assertions.assertNotNull(mAllChildren);
720+
View[] childArray = Assertions.assertNotNull(mAllChildren);
732721
view.removeOnLayoutChangeListener(mChildrenLayoutChangeListener);
733722
int index = indexOfChildInAllChildren(view);
734-
if (mAllChildren[index].getParent() != null) {
723+
if (childArray[index].getParent() != null) {
735724
int clippedSoFar = 0;
736725
for (int i = 0; i < index; i++) {
737-
if (mAllChildren[i].getParent() == null) {
726+
if (childArray[i].getParent() == null) {
738727
clippedSoFar++;
739728
}
740729
}
@@ -745,60 +734,60 @@ public void run() {
745734

746735
/*package*/ void removeAllViewsWithSubviewClippingEnabled() {
747736
Assertions.assertCondition(mRemoveClippedSubviews);
748-
Assertions.assertNotNull(mAllChildren);
737+
View[] childArray = Assertions.assertNotNull(mAllChildren);
749738
for (int i = 0; i < mAllChildrenCount; i++) {
750-
mAllChildren[i].removeOnLayoutChangeListener(mChildrenLayoutChangeListener);
739+
childArray[i].removeOnLayoutChangeListener(mChildrenLayoutChangeListener);
751740
}
752741
removeAllViewsInLayout();
753742
mAllChildrenCount = 0;
754743
}
755744

756745
private int indexOfChildInAllChildren(View child) {
757746
final int count = mAllChildrenCount;
758-
final View[] children = Assertions.assertNotNull(mAllChildren);
747+
final View[] childArray = Assertions.assertNotNull(mAllChildren);
759748
for (int i = 0; i < count; i++) {
760-
if (children[i] == child) {
749+
if (childArray[i] == child) {
761750
return i;
762751
}
763752
}
764753
return -1;
765754
}
766755

767756
private void addInArray(View child, int index) {
768-
View[] children = Assertions.assertNotNull(mAllChildren);
757+
View[] childArray = Assertions.assertNotNull(mAllChildren);
769758
final int count = mAllChildrenCount;
770-
final int size = children.length;
759+
final int size = childArray.length;
771760
if (index == count) {
772761
if (size == count) {
773762
mAllChildren = new View[size + ARRAY_CAPACITY_INCREMENT];
774-
System.arraycopy(children, 0, mAllChildren, 0, size);
775-
children = mAllChildren;
763+
System.arraycopy(childArray, 0, mAllChildren, 0, size);
764+
childArray = mAllChildren;
776765
}
777-
children[mAllChildrenCount++] = child;
766+
childArray[mAllChildrenCount++] = child;
778767
} else if (index < count) {
779768
if (size == count) {
780769
mAllChildren = new View[size + ARRAY_CAPACITY_INCREMENT];
781-
System.arraycopy(children, 0, mAllChildren, 0, index);
782-
System.arraycopy(children, index, mAllChildren, index + 1, count - index);
783-
children = mAllChildren;
770+
System.arraycopy(childArray, 0, mAllChildren, 0, index);
771+
System.arraycopy(childArray, index, mAllChildren, index + 1, count - index);
772+
childArray = mAllChildren;
784773
} else {
785-
System.arraycopy(children, index, children, index + 1, count - index);
774+
System.arraycopy(childArray, index, childArray, index + 1, count - index);
786775
}
787-
children[index] = child;
776+
childArray[index] = child;
788777
mAllChildrenCount++;
789778
} else {
790779
throw new IndexOutOfBoundsException("index=" + index + " count=" + count);
791780
}
792781
}
793782

794783
private void removeFromArray(int index) {
795-
final View[] children = Assertions.assertNotNull(mAllChildren);
784+
final View[] childArray = Assertions.assertNotNull(mAllChildren);
796785
final int count = mAllChildrenCount;
797786
if (index == count - 1) {
798-
children[--mAllChildrenCount] = null;
787+
childArray[--mAllChildrenCount] = null;
799788
} else if (index >= 0 && index < count) {
800-
System.arraycopy(children, index + 1, children, index, count - index - 1);
801-
children[--mAllChildrenCount] = null;
789+
System.arraycopy(childArray, index + 1, childArray, index, count - index - 1);
790+
childArray[--mAllChildrenCount] = null;
802791
} else {
803792
throw new IndexOutOfBoundsException();
804793
}

0 commit comments

Comments
 (0)