Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour #4

Open
Zanexess opened this issue Jan 12, 2017 · 12 comments
Open

Strange behaviour #4

Zanexess opened this issue Jan 12, 2017 · 12 comments

Comments

@Zanexess
Copy link

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
Copy link
Owner

laenger commented Jan 17, 2017

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
Copy link

+1

@frangilberte
Copy link

Any progress in this issue? Thanks in advance.

@Zanexess
Copy link
Author

Zanexess commented Mar 14, 2017

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
Copy link
Owner

laenger commented Mar 14, 2017

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

@Zanexess
Copy link
Author

Ok, I'll do it later )

@frangilberte
Copy link

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

@Zanexess
Copy link
Author

Zanexess commented Mar 15, 2017

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
Copy link

paprikanotfound commented Oct 21, 2017

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
Copy link

justasm commented Feb 23, 2018

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 @ trafi/anchor-bottom-sheet-behavior@0.9.1-alpha...0.10-alpha

kozmi55 added a commit to kozmi55/ViewPagerBottomSheet that referenced this issue Aug 7, 2018
Fixed closing/opening bottom sheet when ViewPager is scrolled.
@Huskyyy
Copy link

Huskyyy commented Jan 22, 2019

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 pushed a commit that referenced this issue Nov 5, 2019
Fixed closing/opening bottom sheet when ViewPager is scrolled.
@laenger
Copy link
Owner

laenger commented Nov 5, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants