Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BottomSheetBehaviour setstate without animation

I have tried the new BottomSheetBehaviour with design library 23.0.2 but i think it too limited. When I change state with setState() method, the bottomsheet use ad animation to move to the new state.

How can I change state immediately, without animation? I don't see a public method to do that.

like image 590
Funny Devs Avatar asked Mar 23 '16 15:03

Funny Devs


2 Answers

Unfortunately it looks like you can't. Invocation of BottomSheetBehavior's setState ends with synchronous or asynchronous call of startSettlingAnimation(child, state). And there is no way to override these methods behavior cause setState is final and startSettlingAnimation has package visible modifier. Check the sources for more information.

I have problems with the same, but in a bit different way - my UI state changes setHideable to false before that settling animation invokes, so I'm getting IllegalStateException there. I will consider usage of BottomSheetCallback to manage this properly.

like image 88
Viacheslav Avatar answered Sep 22 '22 18:09

Viacheslav


If you want to remove the show/close animation you can use dialog.window?.setWindowAnimations(-1). For instance:

class MyDialog(): BottomSheetDialogFragment() {

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)

        dialog.window?.setDimAmount(0f) // for removing the dimm
        dialog.window?.setWindowAnimations(-1) // for removing the animation

        return dialog
    }
}
like image 26
Kuvonchbek Yakubov Avatar answered Sep 19 '22 18:09

Kuvonchbek Yakubov