Button Press in jetpack compose showing multiple recomposition

917 Views Asked by At

enter image description hereHello the code is very simple on pressing a button i am changing the mutableState value.But i found the on button press recomposition is happening multiple time.

So is this some bug or for button the property is a bit different

1

There are 1 best solutions below

0
Motasem Jouda On

This is caused by the ripple effect that the button makes, you can do the following to stop this from happening:

class NoRippleInteractionSource() :  MutableInteractionSource {
override val interactions: Flow<Interaction> = emptyFlow()
override suspend fun emit(interaction: Interaction) {}
override fun tryEmit(interaction: Interaction) = true
}

And in your Button add this:

Button(
interactionSource = NoRippleInteractionSource(),
onClick = {  }) {
    Text("PressMe")
}