views-widgets-samples icon indicating copy to clipboard operation
views-widgets-samples copied to clipboard

Used OnTouchListener for nested scrolling in ViewPager2

Open tunjid opened this issue 4 years ago • 0 comments

👋 👋 👋

This PR modifies the NestedScrollableHost to be a View.OnTouchListener rather than a ViewGroup that houses the nested scrolling child.

I don't think this is a better implementation per se, just more of a different one. I'm mostly curious about the design decisions that led to opting for nesting the scrollable child rather than using the View.OnTouchListener.

Off the top of my head, I can see the View.onTouchListener is a bit intrusive and limits custom touch interception on the nested scrollable View, however this is mitigated if this View were a RecyclerView as it could use the RecyclerView.OnItemTouchListener instead, which would be perfect for this example.

FWIW, this solution worked with nested ViewPagers, i.e I had ViewPager2 -> ViewPager2 -> HorizontalScrollView where the middle ViewPager2 had isUserInputEnabled = false and it worked a charm.

tunjid avatar Feb 16 '20 23:02 tunjid