Open Zanexess opened 7 years ago
I also found the gesture detection to be quite sensitive to vertical swipes compared to horizontal. I didn't have a look into how to tweak this. Can you find out how other nested scrolling children implement the increased threshold for vertical scrolling when in a view pager? We might be able to learn from existing code.
+1
Any progress in this issue? Thanks in advance.
Yeah, it's easy to fix it. I just add some additional conditions in onInterceptTouchEvent. Before
if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) {
return true;
}
After
if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event) && Math.abs(event.getY() - mInitialY) > Math.abs(event.getX() - mInitialX)
&& Math.abs(event.getY() - mInitialY) > 100) {
return true;
}
mInitialY and initialX should be global variable. Maybe I changed something else, but I don't remember, sorry :) Try it, hope it helps.
A pull request with the necessary changes would be much appreciated.
Ok, I'll do it later )
Thanks @Zanexess, yes, that pull request would be great
Okay it's sad, but I find out that my solution works only in my specific case. Meanwhile you can use something like I did in pull request to make it work for you.
It seems to me that when the viewpager sends a cancel event when it starts scrolling between pages, which triggers the dialog to expand/close.
My quick work around for this issue was this to override the onPageScrollStateChanged method of the viewpager listener and add this line:
bottomSheetDialog.setCancelable(ViewPager.SCROLL_STATE_DRAGGING != state);
I was just tackling this issue in our fork (which supports an intermediate anchor state). It required tweaking the code that calculates the top
and targetState
variables, and only initiating state changes if the vertical velocity was
This results in relatively pleasing behaviour. You can find the diff @ https://github.com/trafi/anchor-bottom-sheet-behavior/compare/0.9.1-alpha...0.10-alpha
Maybe the sensitivity of ViewPagerBottomSheet not only depends on the dis of Y, but also depends on the velocity of Y. So the appropriate way to intercept the touch event would be something like this:
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
......
return action == MotionEvent.ACTION_MOVE
&& scroll != null
&& !mIgnoreEvents
&& mState != STATE_DRAGGING
&& !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY())
&& Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()
&& Math.abs(getYVelocity()) > Math.abs(getXVelocity())
&& Math.abs(mInitialX - event.getX()) < Math.abs(mInitialY - event.getY());
}
Just compare the distance and the velocity between X and Y, it seems to work for me.
New version 0.0.6 seems to resolve this. Thank you @kozmi55
Thanks a lot for this library! But there is a little problem. When i try to swipe ViewPager's fragment, it often close bottom sheet; To change fragment of viewpager i should move finger right on x axis without any y movements. Is there any workaround to intercept this action to fix this strange behavior?