Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for effects bottomsheet flickering to the expanded state while being dragged #575

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ open class BaseDialogFragment : BottomSheetDialogFragment(), CoroutineScope {

open val statusBarColor: StatusBarColor? = StatusBarColor.Light

private var isBeingDragged = false
private val dismissCallback = object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {}

override fun onSlide(bottomSheet: View, slideOffset: Float) {
isBeingDragged = true
}
}

@Inject lateinit var theme: Theme

override val coroutineContext: CoroutineContext
Expand All @@ -47,14 +56,38 @@ open class BaseDialogFragment : BottomSheetDialogFragment(), CoroutineScope {
view.doOnLayout {
ensureExpanded()
}

isBeingDragged = false
addDismissCallback()
}

private fun addDismissCallback() {
val dialog = dialog as BottomSheetDialog
(dialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout?)?.let { bottomSheet ->
val behavior = BottomSheetBehavior.from(bottomSheet)
behavior.addBottomSheetCallback(dismissCallback)
}
}

private fun removeDismissCallback() {
val dialog = dialog as BottomSheetDialog
(dialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout?)?.let { bottomSheet ->
val behavior = BottomSheetBehavior.from(bottomSheet)
behavior.removeBottomSheetCallback(dismissCallback)
}
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
removeDismissCallback()
(activity as? FragmentHostListener)?.updateStatusBar()
}

fun ensureExpanded() {
// skip this when the user is dragging the bottomsheet
// as it causes the bottomsheet flicker to the expanded state
if (isBeingDragged) return

val dialog = dialog as BottomSheetDialog
(dialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout?)?.let { bottomSheet ->
val behavior = BottomSheetBehavior.from(bottomSheet)
Expand Down