fix crash in RefreshControl (#45914)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45914

changelog: [internal]

Fix a crash when SwipeRefreshLayout uses a custom child.

According to the docs, [SwipeRefreshLayout must override canChildScrollUp](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#canChildScrollUp()) method if a custom view is used.

On Android, we do use a custom view: https://fburl.com/code/kfaj8q9z

Reviewed By: Abbondanzo

Differential Revision: D60829986

fbshipit-source-id: 09e6bc690bb66131d614b1eedfbede615f42d2e1
This commit is contained in:
Samuel Susla
2024-08-06 10:42:07 -07:00
committed by Facebook GitHub Bot
parent 9035008427
commit 8bf5a12ea2
2 changed files with 12 additions and 0 deletions
@@ -7334,6 +7334,7 @@ public final class com/facebook/react/views/scroll/ScrollEventType$Companion {
public class com/facebook/react/views/swiperefresh/ReactSwipeRefreshLayout : androidx/swiperefreshlayout/widget/SwipeRefreshLayout {
public fun <init> (Lcom/facebook/react/bridge/ReactContext;)V
public fun canChildScrollUp ()Z
public fun onInterceptTouchEvent (Landroid/view/MotionEvent;)Z
public fun onLayout (ZIIII)V
public fun onTouchEvent (Landroid/view/MotionEvent;)Z
@@ -8,6 +8,7 @@
package com.facebook.react.views.swiperefresh;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.facebook.infer.annotation.Nullsafe;
@@ -72,6 +73,16 @@ public class ReactSwipeRefreshLayout extends SwipeRefreshLayout {
}
}
@Override
public boolean canChildScrollUp() {
View firstChild = getChildAt(0);
if (firstChild != null) {
return firstChild.canScrollVertically(-1);
} else {
return super.canChildScrollUp();
}
}
/**
* {@link SwipeRefreshLayout} overrides {@link ViewGroup#requestDisallowInterceptTouchEvent} and
* swallows it. This means that any component underneath SwipeRefreshLayout will now interact