mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 21:01:50 +01:00
TabbedBottomSheetDialog: Fix scrollable pages (#5173)
This commit is contained in:
parent
0fb9ca3e8b
commit
69869115f6
@ -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.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<androidx.viewpager.widget.ViewPager
|
<eu.kanade.tachiyomi.widget.sheet.BottomSheetViewPager
|
||||||
android:id="@+id/pager"
|
android:id="@+id/pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
Loading…
Reference in New Issue
Block a user