Colton Idle
11/29/2023, 1:17 AMAnimatedVisibility(visible = someState != null) {
MyUi(someState!!)
}
should compose/kotlin be able to figure out that I don't need !! or, am I setting up a potential footgun for myself here?Ian Lake
11/29/2023, 1:35 AMsomeState!!
would crash while the content is animating out (since setting visible
to false doesn't mean the content instantly vanishes) - that's why AnimatedContent
passes the lambda the targetState
- so you don't have to hold onto it separately)ephemient
11/29/2023, 1:52 AMZoltan Demant
11/29/2023, 5:45 AMIan Lake
11/29/2023, 5:47 AMcontentKey
on AnimatedContent
Zoltan Demant
11/29/2023, 6:01 AMIan Lake
11/29/2023, 6:33 AMColton Idle
11/29/2023, 8:14 AMAnimatedContent(targetState = someState) {
if (it != null) {
MyUi(it)
}
}
the animation seems right, even though the other thread linked Albert mentioned that we don't need the inner null check. But I can't get it to work without that inner null check
AnimatedContent(targetState = someState) {
MyUi(it!!)
}
crashesvide
11/29/2023, 8:22 AMAnimatedContent
would work in both directions. You can't skip the inner null check with AnimatedVisibility
Colton Idle
11/29/2023, 8:29 AMColton Idle
11/29/2023, 8:30 AMvide
11/29/2023, 8:38 AMvide
11/29/2023, 8:39 AMvide
11/29/2023, 8:39 AMColton Idle
11/29/2023, 8:41 AMAnimatedContent(targetState = someState) {
if (it != null) {
MyUi(it)
}
}
thanks!vide
11/29/2023, 8:47 AMStylianos Gakis
11/29/2023, 2:51 PMAh okay. so it does work when “entering”, but not during exit.Well yeah, if during exiting the state is set to null, and you render nothing, then there will be nothing to render 😄 In places like these I’ve just passed a nullable object into
MyUi
and then that component can handle the null cases too, which is basically from the first frame it starts animating out, until it’s actually out of composition. And that results in a nice animation out too.
It’s just a declarative UI thing, even as it’s animating out, you still need to tell it what it should look like.Zoltan Demant
11/29/2023, 3:17 PMIn places like these I’ve just passed a nullable object intoDo you mean doing something like remembering the value so that it still exists for the out animation? Just curious, thats effectively what Ive been doing, but always fun to explore new ways!and then that component can handle the null cases tooMyUi
Stylianos Gakis
11/29/2023, 3:23 PMZoltan Demant
11/29/2023, 3:24 PMColton Idle
11/29/2023, 5:13 PMStylianos Gakis
11/29/2023, 7:14 PMColton Idle
11/29/2023, 7:52 PMIan Lake
11/29/2023, 8:28 PMit
around all the way until it finishes animating out, even if nothing else outside of the AnimatedContent
is keeping that object aliveColton Idle
11/29/2023, 9:16 PM