changing dragging behavior of bottom sheets to be like iOS

ie: if at the top of the scrollview it can be dragged down, even if you scroll a bit down then up without letting go
This commit is contained in:
Jays2Kings 2021-04-29 00:22:49 -04:00
parent b0948cf0a7
commit eb88d4e94f
2 changed files with 6 additions and 26 deletions

View File

@ -7,7 +7,6 @@ import androidx.recyclerview.widget.RecyclerView
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.databinding.RecyclerWithScrollerBinding
import eu.kanade.tachiyomi.util.view.isExpanded
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
class RecyclerWithScrollerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
@ -22,24 +21,12 @@ class RecyclerWithScrollerView @JvmOverloads constructor(context: Context, attrs
binding.recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (sheet.isOnView(this@RecyclerWithScrollerView) &&
(
newState == RecyclerView.SCROLL_STATE_IDLE ||
newState == RecyclerView.SCROLL_STATE_SETTLING
)
if (newState == RecyclerView.SCROLL_STATE_IDLE ||
newState == RecyclerView.SCROLL_STATE_SETTLING
) {
sheet.sheetBehavior?.isDraggable = true
}
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (sheet.isOnView(this@RecyclerWithScrollerView) &&
sheet.sheetBehavior.isExpanded() &&
recyclerView.canScrollVertically(-1) &&
recyclerView.scrollState != RecyclerView.SCROLL_STATE_SETTLING
) {
sheet.sheetBehavior?.isDraggable = false
} else {
sheet.sheetBehavior?.isDraggable = !recyclerView.canScrollVertically(-1)
}
}
})

View File

@ -67,15 +67,8 @@ abstract class E2EBottomSheetDialog<VB : ViewBinding>(activity: Activity) :
newState == RecyclerView.SCROLL_STATE_SETTLING
) {
sheetBehavior.isDraggable = true
}
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (recyclerView.canScrollVertically(-1) &&
recyclerView.scrollState != RecyclerView.SCROLL_STATE_SETTLING
) {
sheetBehavior.isDraggable = false
} else {
sheetBehavior.isDraggable = !recyclerView.canScrollVertically(-1)
}
}
})