question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to make ViewPager be more aggressive in responding to horizontal gesture when nested inside a vertical ScrollView?

See original GitHub issue

Hi everyone,

Users are reporting that it is difficult to use the ViewPager to successfully scroll left and right between images, since the ScrollView that the ViewPager is nested in seems to grab the event more than it should.

Example

Indeed, I compared my app to Google Maps which has a very similar UI: A horizontally scrollable set of images inside a vertically scrolling parent view. In Google Maps, I can move my finger at 45 degrees to either side, and the horizontal images view takes the event. In my app, moving my finger 45 degrees is picked up by the ScrollView and the entire page begins scrolling up and down.

Here, the purple arrows are what is handled by both apps successfully. The blue arrows are what is handled successfully by Google Maps but not by ScrollView/ViewPager. In Google Maps, the result is a horizontal scroll, in my app the result is a vertical scroll - and angry users.

I have looked into the props and found: ViewPager.onStartShouldSetResponder and ViewPager.onMoveShouldSetResponderCapture. I tried providing a function that always returns true for both, but got no effect in my app. I also tried the same props but returning false for the ScrollView. Still nothing. I also tried ScrollView.disableScrollViewPanResponder, although I’m not really sure what this does.

Somewhat at a loss here, can anyone help?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
zholmes1commented, Oct 8, 2021

@dcoulter45 I stopped using ViewPager and replaced it with FlatList with pagingEnabled. Works really well honestly and doesn’t require an extra native library. And it definitely responds more naturally to gestures when inside a ScrollView

1reaction
tothvoj-glcommented, Feb 21, 2022

We are facing the same issue. Here is a nice article explaining the source of the issue: https://bladecoder.medium.com/fixing-recyclerview-nested-scrolling-in-opposite-direction-f587be5c1a04

There is a workaround which we are using, but it has some drawbacks. We are decreasing the pager swipe sensitivity, however you need to find the sweet spot between fixing this issues and making the swiping too hard.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ViewPager inside ScrollView - vertical scroll doesn't work
My solution was to only trigger that method after the user started scrolling horizontally for a specified distance (the 'margin' variable).
Read more >
ViewPager with FragmentPagerAdapter - CodePath Cliffnotes
A ViewPager is a layout which can be added to any layout XML file inside a root ... you need to include a...
Read more >
Support nested scrolling elements with the same scroll direction.
1+). One possible option for VerticalViewPager with nested scrolling in the same scroll direction is using a RecyclerView implementing NestedScrollingParent + ...
Read more >
Create swipe views with tabs using ViewPager
This navigation pattern is also referred to as horizontal paging. This topic teaches you how to create a tab layout with swipe views...
Read more >
Support nested scrollable elements inside ViewPager2
Actually you should wrap your nested scroll view(here viewPager), inside your NestedScrollableHost custom view.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found