Konfetti icon indicating copy to clipboard operation
Konfetti copied to clipboard

Konfetti on click problem

Open behu-kea opened this issue 1 year ago • 4 comments

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:

setContent {
    var position by remember {
        mutableStateOf(2f)
    }
    Button(onClick = {
        position = 5f;
    }) {
        Text(
            text = "Spray confetti" + position.toString())
    }

    KonfettiView(
        modifier = Modifier.fillMaxSize(),
        parties = listOf(Party(
            speed = 0f,
            maxSpeed = 30f,
            damping = 0.9f,
            spread = 360,
            colors = listOf(0xfce18a, 0xff726d, 0xf4306d, 0xb48def),
            emitter = Emitter(duration = 100, TimeUnit.MILLISECONDS).max(100),
            position = Position.Absolute(position, 1f)
        ))
    )
}

I have also tried

var party by remember { mutableStateOf<Party?>(null) }
            
Button(onClick = {
    party = Party (emitter = Emitter(duration = 5, TimeUnit.SECONDS).perSecond(30))
}) {
    Text(text = "Spray confetti!")
}

KonfettiView(
    modifier = Modifier.fillMaxSize(),
    parties = party?.let { listOf(it) } ?: emptyList()
)

Can someone please help?

behu-kea avatar Dec 14 '23 12:12 behu-kea

Related: #305

behu-kea avatar Dec 14 '23 12:12 behu-kea

- ```

jastigall392 avatar Jul 04 '24 14:07 jastigall392