Propagate up/down swipe event from ViewPager2 to parent BottomSheet

I’m having a BottomSheetBehavior view which contains a ViewPager2. Both work well and do what they need except trying to swipe the BottomSheet up/down on the ViewPager2. Again, swipe up/down on BottomSheet works well if the finger is above or below the ViewPager2, except when the finger is ON the ViewPager2.

I need to find out how to propagate the up/down swipe events through the ViewPager2 down to the BottomSheet.

The code is very fragmented, so it’ll be complicated to show it here and wouldn’t really make sense. I just need the principle of how to propagate the events.

Answer

This is due to that the nested scrolling of the inner RecyclerView of the ViewPager2 is enabled by default. To disable it:

viewPager.children.find { it is RecyclerView }?.let {
        (it as RecyclerView).isNestedScrollingEnabled = false
}