Lazard
11/28/2020, 4:36 PMval (counter, setCounter) = remember { mutableStateOf(0) }
If I want to create a incrementCounter()
function to prevent writing setCounter(counter + 1)
each time, inside my component I can write :
fun incrementCounter(value = 1) { setCounter(counter + value) }
But doing so, Jetpack Compose will behave weirdly and won't update the counter each time.
If I instead declare it like that :
val incrementCounter = fun(value: Int) { setCounter(counter + value) }
It work without any problem ! The only problem is that I cannot use default values with this syntax.
It reminds me of the arrow function in javascript and the reference of this
.
After a lot of trial and error, it seems the destructuration of the mutableState return is the culprit.
Does anybody have an idea ? Is it possible to write an internal function in a Jetpack Compose component while still using destructuration ?Timo Drick
11/28/2020, 6:46 PMvar counter by remember { mutableStateOf(0) }
Than you can use the variable counter like a normal variable.
E.g.: counter++ ; counter = 4; ...gildor
11/29/2020, 7:50 AMLazard
11/29/2020, 9:44 AMgildor
11/29/2020, 3:34 PMLazard
11/29/2020, 3:35 PMLazard
11/29/2020, 9:15 PMTimo Drick
11/29/2020, 11:22 PM