Skip to content

Commit

Permalink
ReactViewGroup - utilize onViewAdded/Removed (facebook#47890)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#47890

The fix in [facebook#40859](facebook#40859) overrode every possible add or remove to ensure completeness, but all paths should also call onViewAdded/onViewRemoved via:
- `addView`/`addViewInLayout` -> [addViewInner](https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-15.0.0_r5/core/java/android/view/ViewGroup.java#5310)
- `removeView`/`removeViewInLayout` -> [removeViewInternal](https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-15.0.0_r5/core/java/android/view/ViewGroup.java#5606)
- `removeViews`/`removeViewsInLayout` -> [removeViewsInternal](https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-15.0.0_r5/core/java/android/view/ViewGroup.java#5714)

Changelog: [Android][Changed] Consolidated ReactViewGroup add/remove overrides

Reviewed By: javache

Differential Revision: D66320586

fbshipit-source-id: aaf16af5ad87789f575fcb79dcf31f5686002b2d
  • Loading branch information
Thomas Nardone authored and facebook-github-bot committed Nov 22, 2024
1 parent 3d1a505 commit 0b22b95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 66 deletions.
9 changes: 2 additions & 7 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -7823,8 +7823,6 @@ public class com/facebook/react/views/view/ReactDrawableHelper {

public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGroup, com/facebook/react/touch/ReactHitSlopView, com/facebook/react/touch/ReactInterceptingViewGroup, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/uimanager/ReactPointerEventsView, com/facebook/react/uimanager/ReactZIndexedViewGroup {
public fun <init> (Landroid/content/Context;)V
public fun addView (Landroid/view/View;ILandroid/view/ViewGroup$LayoutParams;)V
protected fun addViewInLayout (Landroid/view/View;ILandroid/view/ViewGroup$LayoutParams;Z)Z
protected fun dispatchDraw (Landroid/graphics/Canvas;)V
public fun dispatchGenericMotionEvent (Landroid/view/MotionEvent;)Z
public fun dispatchProvideStructure (Landroid/view/ViewStructure;)V
Expand All @@ -7847,11 +7845,8 @@ public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGro
protected fun onMeasure (II)V
protected fun onSizeChanged (IIII)V
public fun onTouchEvent (Landroid/view/MotionEvent;)Z
public fun removeView (Landroid/view/View;)V
public fun removeViewAt (I)V
public fun removeViewInLayout (Landroid/view/View;)V
public fun removeViews (II)V
public fun removeViewsInLayout (II)V
public fun onViewAdded (Landroid/view/View;)V
public fun onViewRemoved (Landroid/view/View;)V
public fun requestLayout ()V
public fun setBackfaceVisibility (Ljava/lang/String;)V
public fun setBackfaceVisibilityDependantOpacity ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,83 +524,33 @@ private boolean customDrawOrderDisabled() {
return ViewUtil.getUIManagerType(getId()) == UIManagerType.FABRIC;
}

private void handleAddView(View view) {
@Override
public void onViewAdded(View child) {
UiThreadUtil.assertOnUiThread();

if (!customDrawOrderDisabled()) {
getDrawingOrderHelper().handleAddView(view);
getDrawingOrderHelper().handleAddView(child);
setChildrenDrawingOrderEnabled(getDrawingOrderHelper().shouldEnableCustomDrawingOrder());
} else {
setChildrenDrawingOrderEnabled(false);
}
super.onViewAdded(child);
}

private void handleRemoveView(@Nullable View view) {
@Override
public void onViewRemoved(View child) {
UiThreadUtil.assertOnUiThread();

if (!customDrawOrderDisabled()) {
if (indexOfChild(view) == -1) {
if (indexOfChild(child) == -1) {
return;
}
getDrawingOrderHelper().handleRemoveView(view);
getDrawingOrderHelper().handleRemoveView(child);
setChildrenDrawingOrderEnabled(getDrawingOrderHelper().shouldEnableCustomDrawingOrder());
} else {
setChildrenDrawingOrderEnabled(false);
}
}

private void handleRemoveViews(int start, int count) {
int endIndex = start + count;
for (int index = start; index < endIndex; index++) {
if (index < getChildCount()) {
handleRemoveView(getChildAt(index));
}
}
}

@Override
public void addView(View child, int index, @Nullable ViewGroup.LayoutParams params) {
// This will get called for every overload of addView so there is not need to override every
// method.
handleAddView(child);
super.addView(child, index, params);
}

@Override
protected boolean addViewInLayout(
View child, int index, LayoutParams params, boolean preventRequestLayout) {
handleAddView(child);
return super.addViewInLayout(child, index, params, preventRequestLayout);
}

@Override
public void removeView(@Nullable View view) {
handleRemoveView(view);
super.removeView(view);
}

@Override
public void removeViewAt(int index) {
handleRemoveView(getChildAt(index));
super.removeViewAt(index);
}

@Override
public void removeViewInLayout(View view) {
handleRemoveView(view);
super.removeViewInLayout(view);
}

@Override
public void removeViewsInLayout(int start, int count) {
handleRemoveViews(start, count);
super.removeViewsInLayout(start, count);
}

@Override
public void removeViews(int start, int count) {
handleRemoveViews(start, count);
super.removeViews(start, count);
super.onViewRemoved(child);
}

@Override
Expand Down

0 comments on commit 0b22b95

Please sign in to comment.