ankur samarya
05/05/2025, 12:53 PMBar
is not recomposing with the new lambda instance?
In this example code, I am creating a new instance of onBarClick
every time the state changes.
Since it's a new instance, the Bar
should recompose as well — but it's not.
I've disabled strong skipping using enableStrongSkippingMode = false
.
@Composable
fun Foo() {
val state = remember {
mutableIntStateOf(1)
}
val onBarClick = {}
Log.d("logs", "Foo Recomposition ${onBarClick}" )
Column {
Text(text = "Value ${state.value}")
Bar(onBarClick = onBarClick)
Button(onClick = { state.value++ }) {
Text(text = "Increment")
}
}
}
@Composable
fun Bar(onBarClick: () -> Unit) {
Log.d("logs", "Bar Recomposition" )
Button(onClick = onBarClick) {
Text(text = "Dummy Button")
}
}
Thanksephemient
05/05/2025, 12:58 PMephemient
05/05/2025, 12:58 PMankur samarya
05/05/2025, 1:13 PMankur samarya
05/05/2025, 1:13 PMWinson Chiu
05/05/2025, 2:32 PMshikasd
05/05/2025, 2:47 PMankur samarya
05/05/2025, 4:46 PMWinson Chiu
05/05/2025, 4:49 PMWinson Chiu
05/05/2025, 4:49 PMWinson Chiu
05/05/2025, 4:52 PMWinson Chiu
05/05/2025, 4:53 PMankur samarya
05/05/2025, 5:09 PMval onBarClick = @DontMemoize {}
with this option I am getting same instance, which is probably because of kotlin compiler optimization - if the lambda doesn't capture anything, it can be made into a singletonWinson Chiu
05/05/2025, 5:16 PMankur samarya
05/05/2025, 5:24 PMrestartable skippable scheme("[androidx.compose.ui.UiComposable]") fun Foo()
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun Bar(
stable onBarClick: Function0<Unit>
)
efemoney
05/06/2025, 3:08 PM