Hello, i'm trying to only change a variable only w...
# compose
f
Hello, i'm trying to only change a variable only when this column is focused, but it keeps getting the inicial last_location value when it is not focused. PS: location is a state variable
s
create a state for
last_location1
and change it in the
onFocusChanged
callback
f
Oh, thank you!. Could you explain to me why this works?
s
Updating a state triggers re-composition. Changing a normal variable can't trigger re-composition. Therefore your Column composable is not getting re-composed. PS. This is a good example of side-effects that you should avoid 🙂 https://developer.android.com/jetpack/compose/mental-model - this a very good article that explain how it works 🙂
😃 1