https://kotlinlang.org logo
#compose
Title
# compose
a

Archie

02/23/2021, 1:00 PM
Hi, is there a way to add listener to
Transition
? I'd like to do an action after the new state have been reached something like:
Copy code
val transitionState = remember {
    MutableTransitionState(false)
}

val transition = updateTransition(transitionState)
val scale by transition.animateFloat(
    transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy) }
) {
    when (it) {
        true -> 1f
        false -> 0f
    }
}

LaunchedEffect(viewModel, navController) {
   delay(1000)
   transitionState.targetState = true
   // Then I want to do an action after the animation finished
   // but I can't find a way to attached a listener to Transition.
}
j

jim

02/23/2021, 1:57 PM
cc @Doris Liu
As a side note, I'm not sure how I feel about a transition being the thing that triggers a followup action. Your data flow feels a bit inverted to me - your app state should be driving the transition, not your transition logic driving your app state. Compose is all about one-way flow of information.
a

Archie

02/23/2021, 2:02 PM
Hi @jim, Thank you very much for the feedback. I actually wanted to do an "Exit" animation before navigating to the next screen in this scenario. I am thinking doing it this way as a workaround but I would I imagine when navigation transition would be available I wont have to do this.
b

bruno.aybar

02/23/2021, 3:23 PM
a

Archie

02/24/2021, 3:56 AM
Hi @bruno.aybar, Thanks! I guess that would work.
👍 1
8 Views