What should I use to only observe state inside com...
# compose
t
What should I use to only observe state inside composable and trigger recomposition, but without caching the state so I can set the same value? 🧵
I have two composables, in the first one I have some buttons that should trigger different animations, which I am doing in the second composition. I want to be able to click on the same button and start the same animation. My current solution is to reset the animation state to default values when the animation is finished, but this causes unnecessary recomposition, is there a better way?
Copy code
@Composable
fun MainScreen() {
    var animation by remember { mutableStateOf(AnimationWrapper()) }

    Column {
        Card(animation = animation)

        Button(onClick = {
            animation = AnimationWrapper(400, 8)
        }) {
            Text(text = "Button")
        }
    }
}

@Composable
fun Card(animation: AnimationWrapper) {
    // make some animations based on animation wrapper
}

data class AnimationWrapper(val duration: Int = 0, val rotation: Int = 0)