Vsevolod Kaganovych
04/04/2022, 11:20 AMAnimatedVisibility execution? Code in thread.Vsevolod Kaganovych
04/04/2022, 11:21 AMvar state by remember {
mutableStateOf(false)
}
LaunchedEffect(Unit) {
delay(500)
state = true
}
AnimatedVisibility(
visible = state,
enter = slideInHorizontally(
initialOffsetX = {
-it
}
)
)
this one does workVsevolod Kaganovych
04/04/2022, 11:21 AMAnimatedVisibility(
visible = true,
enter = slideInHorizontally(
initialOffsetX = {
-it
},
animationSpec = tween(durationMillis = 2000, delayMillis = 1000)
)
)
this one doesn'tCsaba Szugyiczki
04/04/2022, 11:24 AMCsaba Szugyiczki
04/04/2022, 11:28 AMVsevolod Kaganovych
04/04/2022, 11:30 AMDoris Liu
04/04/2022, 7:09 PMMutableTransitionState with AnimatedVisibility to create an animation that has a different target state than initial state:
AnimatedVisibility(
visibleState = remember { MutableTransitionState(false).apply { targetState = true } },
enter = slideInHorizontally(
initialOffsetX = {
-it
},
animationSpec = tween(durationMillis = 2000, delayMillis = 1000)
)
) { ... }Vsevolod Kaganovych
04/05/2022, 12:26 PMtargetState to another value, does it trigger the recomposition of animation? This is the same as mutableStateOf(), but for the animation particularly.
Just trying to understand how it works.Csaba Szugyiczki
04/05/2022, 2:14 PMDoris Liu
04/06/2022, 5:37 PMSo when we setYes.to another value, does it trigger the recomposition of animation?targetState
targetState in MutableTransitionState is backed by a mutable state: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]in/kotlin/androidx/compose/animation/core/Transition.kt;l=114
So when targetState changes, recomposition gets triggered and so do animations. MutableTransitionState allows you to define a different initial state than target state, which will run the animation immediately after the animation (e.g. Transition, AnimatedVisibility) that reads MutableTransitionState is composed for the first time.