https://kotlinlang.org logo
Title
e

elye

02/08/2022, 11:54 AM
Hi @Doris Liu, an animation related inquiry. I can’t seems to find any additional benefit of
MutableStateTransition
compare to normal
mutableStateOf
has to offer. It’s long to describe here, so I have put the inquiry on StackOverflow https://stackoverflow.com/questions/71033419/whats-the-use-of-mutablestatetransition-looks-like-mutablestateof-does-all-i. Hopes to get some insight from you. Thanks 🙏
Thanks @Doris Liu for the answer. Excellent example indeed.
val currentState = remember {
        MutableTransitionState(BoxState.Collapsed).apply {
            targetState = BoxState.Expanded
        }
    }
makes full sense. I think the example code in https://developer.android.com/jetpack/compose/animation#updateTransition should use the above instead of
// Start in collapsed state and immediately animate to expanded
var currentState = remember { MutableTransitionState(BoxState.Collapsed) }
currentState.targetState = BoxState.Expanded
val transition = updateTransition(currentState)
// ...