laenger / ViewPagerBottomSheet

Use ViewPagers in Bottom Sheets!
Apache License 2.0
465 stars 86 forks source link

Strange behaviour #4

Open Zanexess opened 7 years ago

Zanexess commented 7 years ago

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?

laenger commented 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.

victordigio commented 7 years ago

+1

frangilberte commented 7 years ago

Any progress in this issue? Thanks in advance.

Zanexess commented 7 years ago

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.

laenger commented 7 years ago

A pull request with the necessary changes would be much appreciated.

Zanexess commented 7 years ago

Ok, I'll do it later )

frangilberte commented 7 years ago

Thanks @Zanexess, yes, that pull request would be great

Zanexess commented 7 years ago

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.

paprikanotfound commented 6 years ago

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);

justasm commented 6 years ago

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

  1. greater than a minimum fling velocity
  2. greater than the horizontal velocity

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

Huskyyy commented 5 years ago

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.

laenger commented 4 years ago

New version 0.0.6 seems to resolve this. Thank you @kozmi55