Skip to content

Commit

Permalink
Prevented coordinator intercepting sheet scrolls
Browse files Browse the repository at this point in the history
Couldn't scroll in a bottomsheet or sheet because the coordinator was intercepting it. This interception is a workaround for [a (react native or android?) bug](facebook/react-native#44099) where the nested scroll stops working of scroll content shorter than height.
Checked if the event target is a sheet and don't intercept in that case.
  • Loading branch information
grahammendick committed Jun 25, 2024
1 parent 8774eef commit 382f7cb
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ScrollView getScrollView() {
public boolean onInterceptTouchEvent(MotionEvent ev) {
ScrollView scrollView = getScrollView();
boolean cannotScroll = scrollView != null && scrollView.getScrollY() == 0 && !scrollView.canScrollVertically(1);
if (cannotScroll) {
if (cannotScroll && hitTest(scrollView, this, ev)) {
int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
Expand Down Expand Up @@ -147,6 +147,26 @@ public boolean onTouchEvent(MotionEvent ev) {
return super.onTouchEvent(ev) || dragging;
}

private boolean hitTest(ScrollView scrollView, ViewGroup parent, MotionEvent ev) {
for(int i = parent.getChildCount() - 1; i >= 0; i--) {
View view = parent.getChildAt(i);
int[] childLocation = new int[2];
view.getLocationOnScreen(childLocation);
float x = ev.getRawX();
float y = ev.getRawY();
int childLeft = childLocation[0];
int childTop = childLocation[1];
int childRight = childLeft + view.getWidth();
int childBottom = childTop + view.getHeight();
if (x >= childLeft && x < childRight && y >= childTop && y < childBottom) {
if (view instanceof BottomSheetView || view instanceof SheetView) return false;
if (view == scrollView) return true;
if (view instanceof ViewGroup viewGroup) return hitTest(scrollView, viewGroup, ev);
}
}
return false;
}

@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
drawingOrderHelper.handleAddView(child);
Expand Down

0 comments on commit 382f7cb

Please sign in to comment.