Android ViewPager with RecyclerView works incorrectly inside BottomSheet

后端 未结 7 1037
故里飘歌
故里飘歌 2020-12-13 02:51

When I try to scroll list, sometimes this works incorrect - BottomSheet intercepts the scroll event and hides.

How to reproduce this:

  1. Open Bottom Sheet
7条回答
  •  暖寄归人
    2020-12-13 03:10

    Looks like all that's required is updating nestedScrollingChildRef appropriately.

    Simply setting it to the target parameter in onStartNestedScroll is working for me:

    package com.google.android.material.bottomsheet
    
    class ViewPagerBottomSheetBehavior(context: Context, attrs: AttributeSet?) : BottomSheetBehavior(context, attrs) {
    
        override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: V, directTargetChild: View, target: View, axes: Int, type: Int): Boolean {
            nestedScrollingChildRef = WeakReference(target)
            return super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type)
        }
    }
    

提交回复
热议问题