Skip to content

Commit

Permalink
Fix flat list scroll with refresh (#1742)
Browse files Browse the repository at this point in the history
## Description

Fixes: #1703

If FlatList contains `onRefresh` property then `ReactScrollView` is wrapped by `ReactSwipeRefreshLayout` who doesn't have `smoothScrollTo()` method.

ReactSwipeRefreshLayout support only vertical scroll - "[The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture.](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout)"
  • Loading branch information
piaskowyk authored Feb 24, 2021
1 parent 35218c0 commit d92b871
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import android.util.Log;
import android.view.View;
import android.view.ViewParent;
import android.view.animation.AnimationUtils;

import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.RootViewUtil;
import com.facebook.react.views.scroll.ReactHorizontalScrollView;
import com.facebook.react.views.scroll.ReactScrollView;
import com.facebook.react.views.swiperefresh.ReactSwipeRefreshLayout;

public class NativeMethodsHelper {

Expand Down Expand Up @@ -43,9 +45,15 @@ public static void scrollTo(View view, double argX, double argY, boolean animate

if (view instanceof ReactHorizontalScrollView) {
horizontal = true;
} else if (!(view instanceof ReactScrollView)) {
Log.w("REANIMATED", "NativeMethodsHelper: Unhandled scroll view type - allowed only {ReactScrollView, ReactHorizontalScrollView}");
return;
}
else {
if (view instanceof ReactSwipeRefreshLayout) {
view = findScrollView((ReactSwipeRefreshLayout)view);
}
if (!(view instanceof ReactScrollView)) {
Log.w("REANIMATED", "NativeMethodsHelper: Unhandled scroll view type - allowed only {ReactScrollView, ReactHorizontalScrollView}");
return;
}
}

if (animated) {
Expand All @@ -64,6 +72,15 @@ public static void scrollTo(View view, double argX, double argY, boolean animate

}

private static ReactScrollView findScrollView(ReactSwipeRefreshLayout view) {
for(int i = 0; i < view.getChildCount(); i++) {
if(view.getChildAt(i) instanceof ReactScrollView) {
return (ReactScrollView)view.getChildAt(i);
}
}
return null;
}

private static void computeBoundingBox(View view, int[] outputBuffer) {
RectF boundingBox = new RectF();
boundingBox.set(0, 0, view.getWidth(), view.getHeight());
Expand Down

0 comments on commit d92b871

Please sign in to comment.