Stylianos Gakis
08/25/2023, 8:00 AMAnimatedContent(uiState) { uiState ->
when(uiState) {
us Error -> { ErrorComposable() }
is Loading -> { Spinner() }
is Content -> { ScreenContent(uiState) }
}
}
Now thing is, when my uiState goes from being Content with some parameters, to still being content, but with some changed state, (like from Content(someState = true)
to Content(someState = false)
) my AnimatedContent animation still plays, which is of course not what I am looking for here.
Is there some approach I am missing here as to how to not make AnimatedContent consider these two Content cases things that it needs to animate between?key
for the content by itself, but just 1 layer deeper, when using updateTransition
, the transition.AnimatedContent
function does seem to take a contentKey: (targetState: S) -> Any? = { it },
parameter, which should allow me to pass the same key for the cases that the AnimatedContent should consider as the same stateFilip Wiesner
08/25/2023, 8:03 AMcontentKey
is definetly what you are looking for 👍 I had the same problem recentlyStylianos Gakis
08/25/2023, 8:04 AMFilip Wiesner
08/25/2023, 8:04 AMcontentKey
in regular animated content somewhere 🤔 Maybe some beta version of ComposeStylianos Gakis
08/25/2023, 8:05 AMcontentKey = { uiState ->
when (uiState) {
is HomeUiState.Error -> "Error"
HomeUiState.Loading -> "Loading"
is HomeUiState.Success -> "Success"
}
},
And it works exactly as I wanted it to, super nice!
Maybe I could make this a bit simpler, like uiState::class in the lambda, but idk if I wanna rely on something like that after r8 runs etc.
What did you do when you had to use it?Filip Wiesner
08/25/2023, 8:06 AMStylianos Gakis
08/25/2023, 8:38 AMFilip Wiesner
08/25/2023, 9:04 AMAlex Vanyo
08/25/2023, 5:42 PM1.5.0-alpha04
is the version that introduced the contentKey
argument on the main AnimatedContent
call (without having to go a level deeper to transition.AnimatedContent
) https://developer.android.com/jetpack/androidx/releases/compose-animation#1.5.0-alpha04Stylianos Gakis
08/25/2023, 6:01 PM