How to disable BottomSheetDialogFragment
dragging by finger?
I saw similar questions, but they\'re all about BottomSheet
not BottomSheetD
Top rated answer contains boilerplate code such as Field and try-catches.
So here is a better version of it in Kotlin:
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
setOnShowListener(::onShow)
}
}
private fun onShow(dialogInterface: DialogInterface) {
val dialog = dialogInterface as BottomSheetDialog
val frameLayout =
dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet)
?: return
BottomSheetBehavior.from(frameLayout).apply {
addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
if (newState == BottomSheetBehavior.STATE_DRAGGING)
state = BottomSheetBehavior.STATE_EXPANDED
}
override fun onSlide(bottomSheet: View, slideOffset: Float) = Unit
})
}
}
Use it in BottomSheetDialogFragment