mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-22 21:25:46 +03:00
TabbedBottomSheetDialog: Fix scrollable pages (#5173)
This commit is contained in:
parent
0fb9ca3e8b
commit
69869115f6
2 changed files with 55 additions and 1 deletions
|
@ -0,0 +1,54 @@
|
|||
package eu.kanade.tachiyomi.widget.sheet
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import java.lang.reflect.Field
|
||||
|
||||
/**
|
||||
* From https://github.com/kafumi/android-bottomsheet-viewpager
|
||||
*/
|
||||
class BottomSheetViewPager @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null
|
||||
) : ViewPager(context, attrs) {
|
||||
|
||||
private val positionField: Field = LayoutParams::class.java.getDeclaredField("position").also {
|
||||
it.isAccessible = true
|
||||
}
|
||||
|
||||
override fun getChildAt(index: Int): View {
|
||||
val currentView = getCurrentView() ?: return super.getChildAt(index)
|
||||
return if (index == 0) {
|
||||
currentView
|
||||
} else {
|
||||
var view = super.getChildAt(index)
|
||||
if (view == currentView) {
|
||||
view = super.getChildAt(0)
|
||||
}
|
||||
return view
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentView(): View? {
|
||||
for (i in 0 until childCount) {
|
||||
val child = super.getChildAt(i)
|
||||
val lp = child.layoutParams as? LayoutParams
|
||||
if (lp != null) {
|
||||
val position = positionField.getInt(lp)
|
||||
if (!lp.isDecor && currentItem == position) {
|
||||
return child
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
init {
|
||||
addOnPageChangeListener(object : SimpleOnPageChangeListener() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
requestLayout()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<eu.kanade.tachiyomi.widget.sheet.BottomSheetViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
|
Loading…
Reference in a new issue