Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button Press in jetpack compose showing multiple recomposition

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

like image 401
rohan ghosh Avatar asked Oct 17 '25 15:10

rohan ghosh


1 Answers

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")
}
like image 179
Motasem Jouda Avatar answered Oct 20 '25 05:10

Motasem Jouda