Can this <new API> support in AnimatedVisibility a...
# compose
k
Can this new API support in AnimatedVisibility also?. It can support suspend method in changing visibility. Check the issue ticket here
@Doris Liu @George Mount cc
g
I don't see why it wouldn't support
AnimatedVisibility
also. It should just work.
k
Thinking
currentState
as val referring
initialState
is wrong. Technically it is wrong, it is not currentState.
Unable to do like this
Copy code
val state = remember { SeekableTransitionState(false, true) }
    val transition = rememberTransition(state)
    val scope = rememberCoroutineScope()

    Column(
        Modifier.background(Color.White).fillMaxWidth(0.6f)
    ) {
        BasicText(transition.targetState.toString())
        BasicText(text = "Click", modifier = Modifier.clickable {
           scope.launch {
               if (state.currentState) state.animateToTargetState()
               else state.animateToCurrentState()
           }
        })
        Spacer(modifier = Modifier.padding(24.dp))
        transition.AnimatedVisibility(
            visible = { it }
        ) {
            BasicText("AnimatedVisibility")
        }
    }
This wont work
Copy code
scope.launch {
               if (state.currentState) state.animateToTargetState()
               else state.animateToCurrentState()
           }
Because state.currentState is immutable , not mutableState. And there is overload composable functions of
AnimatedVisibility
one supports
MutableTransitionState
and another
Transition.AnimatedVisiblity
. To hold the currentState i have to create one more state and using
LaunchedEffect
to change that
s
Looks exciting!