laenger / ViewPagerBottomSheet

Use ViewPagers in Bottom Sheets!
Apache License 2.0
465 stars 86 forks source link

can not use vpbs in project with androidx #35

Open moradi-morteza opened 4 years ago

moradi-morteza commented 4 years ago

hello i have a project with androidx and i add vpbs module in my project but in class ViewPagerUtils layoutParams.position (position is private in viewpager in androidx) so i have an error and can not use vbps now how i should do? thanks

BackPackerDz commented 4 years ago

Hi, did you find a solution?

svrlopatrik commented 4 years ago

Check forked repo https://github.com/svrlopatrik/ViewPagerBottomSheet

nolanamy commented 4 years ago

Try this:

// ViewPagerBottomSheetBehavior.kt

// must be in the same package as BottomSheetBehavior
package com.google.android.material.bottomsheet

import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import java.lang.ref.WeakReference

class ViewPagerBottomSheetBehavior<V : View>(context: Context, attrs: AttributeSet?) : BottomSheetBehavior<V>(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)
    }
}

https://gist.github.com/nolanamy/9fc31c3056e561fa22d6e3ef71630870