Hi all, I am trying to understand the recompositi...
# compose
r
Hi all, I am trying to understand the recomposition of unstable lambda,
data class LambdaUnStableSample1ContextWrapper(val context: Context) //Unstable due to usage of context
@Composable
private fun LambdaUnStableSample1Outer(
onClick: () -> Unit
) {
println("RecompositionLambdaSampleList LambdaUnStableSample 3: Outer")
Column(
modifier = Modifier
.border(2.dp, getRandomColor())
.padding(10.dp)
) {
Button(onClick = onClick) {
Text(text = "Click")
}
}
}
@Composable
private fun LambdaUnStableSample1() {
var counter by remember {
mutableIntStateOf(0)
}
val contextWrapper = LambdaUnStableSample1ContextWrapper(LocalContext.current)
println("RecompositionLambdaSampleList LambdaUnStableSample 1: root")
Column {
println("RecompositionLambdaSampleList LambdaUnStableSample 2: Column")
LambdaUnStableSample1Outer {
println("RecompositionLambdaSampleList LambdaUnStableSample 4: Outer")
counter++
contextWrapper.context
}
}
}
the output is:
RecompositionLambdaSampleList LambdaUnStableSample 4: Outer
But the output should be  or i am expecting is as follows:
RecompositionLambdaSampleList LambdaUnStableSample 4: Outer
RecompositionLambdaSampleList LambdaUnStableSample 1: root
RecompositionLambdaSampleList LambdaUnStableSample 2: Column
RecompositionLambdaSampleList LambdaUnStableSample 3: Outer
As the lambda is unstable due to usage of contextWrapper.context in lambda body,
So can anyone help me to understand, why it is not printing the all, that i am expecting Or please provide me with a simple example were the composable recompose due to unstable lambda, without any viewmodel
🧵 3