Matti MK
12/27/2021, 9:51 AMonAppear
modifier, however, looks like there isn’t a similar option with Compose. I looked over the Animation
docs, but can’t seem to find a non-state based animation, which leads me to believe I need to have state that changes when the screen becomes visible?Rafs
12/27/2021, 9:59 AMAnimatable
API.Matti MK
12/27/2021, 10:02 AMAlbert Chang
12/27/2021, 10:03 AMAnimatedVisibility
.Matti MK
12/27/2021, 10:14 AMonAppear
, but it looks like something like this does not exist and thus it’s necessary to have a state that gets updated when the view becomes visible. The only thing I could think of for this is mutating the state value in LaunchedEffect
.
So, could the answer be to do this:
var visibleStateForAnimation by remember { mutableStateOf(false) }
LaunchedEffect(null) {
visibleStateForAnimation = true
}
I’m not too familiar with LaunchedEffect
so not quite sure about passing null
as the key 🤔Matti MK
12/27/2021, 10:15 AMMatti MK
12/27/2021, 10:25 AMDoris Liu
01/04/2022, 6:57 PMAnimatedVisibility
combined with MutableTransitionState
would allow you to start an animation going from not visible to visible:
AnimatedVisibility(
visibleState = remember {
// This sets up the initial state of the AnimatedVisibility to false to
// guarantee an initial enter transition. In contrast, initializing this as
// `MutableTransitionState(visible)` would result in no initial enter
// transition.
MutableTransitionState(initialState = false)
}.apply {
// This changes the target state of the visible state. If it's different than
// the initial state, an enter/exit transition will be triggered.
targetState = true
},
) { // Content that needs to appear/disappear goes here:
...
}