Skip to content

Commit

Permalink
Better support for nested GestureFrameLayout scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvasilkov committed Aug 13, 2018
1 parent 552383e commit de0f9b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Expand Up @@ -601,7 +601,8 @@ protected boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2,

// First scroll event can stutter a bit, so we will ignore it for smoother scrolling
if (isScrollDetected) {
return true;
// By returning false here we give children views a chance to intercept this scroll
return false;
}
}

Expand Down Expand Up @@ -886,7 +887,6 @@ public interface OnGestureListener {

/**
* @param event Motion event
* @see GestureDetector.OnGestureListener#onDown(MotionEvent)
*/
void onUpOrCancel(@NonNull MotionEvent event);

Expand Down
Expand Up @@ -113,6 +113,20 @@ public ViewParent invalidateChildInParent(int[] location, @NonNull Rect dirty) {
return super.invalidateChildInParent(location, dirty);
}

@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
super.requestDisallowInterceptTouchEvent(disallowIntercept);

if (disallowIntercept) {
// We should pass "cancel" touch event to make sure controller does not expect
// any events anymore.
MotionEvent cancel = MotionEvent.obtain(currentMotionEvent);
cancel.setAction(MotionEvent.ACTION_CANCEL);
controller.onInterceptTouch(this, cancel);
cancel.recycle();
}
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Passing original event to controller
Expand Down
19 changes: 19 additions & 0 deletions sample/src/main/res/layout/layout_viewer_screen.xml
Expand Up @@ -51,6 +51,25 @@
android:layout_margin="16dp"
android:text="@string/random_button" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginBottom="16dp"
android:fadeScrollbars="false">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="16dp"
android:text="@string/random_text"
android:textColor="?android:textColorSecondary"
android:textSize="14sp" />

</ScrollView>

</LinearLayout>

</com.alexvasilkov.gestures.views.GestureFrameLayout>

0 comments on commit de0f9b0

Please sign in to comment.