Open behu-kea opened 9 months ago
Related: #305
- ```
What solution did you find?
You can wrap KonfettiView in a key to achieve this effect
key(content) {
if (content.konfettiState == KonfettiState.Started) {
KonfettiView(
modifier = Modifier.fillMaxSize(),
party = KonfettiUtil.getParty(colors = Color.KonfettiColors)
) {
onFinishConfettiAnimation.invoke()
}
}
}
key can be something like this
@Composable
fun RecreateComposableExample() {
var resetKey by remember { mutableStateOf(0) }
Column {
// The button will reset the composable below
Button(onClick = { resetKey++ }) {
Text("Recreate Composable")
}
// The composable to be recreated
key(resetKey) {
ComposableToRecreate()
}
}
}
@Composable
fun ComposableToRecreate() {
var counter by remember { mutableStateOf(0) }
Column {
Text(text = "Counter: $counter")
Button(onClick = { counter++ }) {
Text("Increment Counter")
}
}
}
I really love this confetti animation, but am struggling to create konfetti on button click. I have it working when the activity is loaded. I am using Kotlin and Compose without xml. I have tried things like:
I have also tried
Can someone please help?