ViewPagerBottomSheet icon indicating copy to clipboard operation
ViewPagerBottomSheet copied to clipboard

Strange behaviour

Open Zanexess opened this issue 8 years ago • 12 comments
trafficstars

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?

Zanexess avatar Jan 12 '17 17:01 Zanexess

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.

laenger avatar Jan 17 '17 09:01 laenger

+1

victordigio avatar Mar 14 '17 08:03 victordigio

Any progress in this issue? Thanks in advance.

frangilberte avatar Mar 14 '17 08:03 frangilberte

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.

Zanexess avatar Mar 14 '17 09:03 Zanexess

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

laenger avatar Mar 14 '17 13:03 laenger

Ok, I'll do it later )

Zanexess avatar Mar 14 '17 13:03 Zanexess

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

frangilberte avatar Mar 15 '17 08:03 frangilberte

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.

Zanexess avatar Mar 15 '17 10:03 Zanexess

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

paprikanotfound avatar Oct 21 '17 20:10 paprikanotfound

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

justasm avatar Feb 23 '18 14:02 justasm

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.

Huskyyy avatar Jan 22 '19 10:01 Huskyyy

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

laenger avatar Nov 05 '19 17:11 laenger