Can someone explain to me how this works? First of...
# compose
e
Can someone explain to me how this works? First of all, everything works fine, just as I need, but I don't understand why. I have a
composable
function
Copy code
@Composable
fun modified(
object1: A,
object2: B) : Boolean {...}
Where
A
is a Data Class,
B
is a regular class with
MutableState
variables. I use this function to control the
Button
, so it's enabled only if there are any differences between the objects.
Copy code
Button(
...
enabled = modified(object1, object2)
...
)
How does it work? Any changes to
MutableState
variables of
object2
trigger the
modified
function?
z
Any changes to
MutableState
variables of
object2
trigger the
modified
function?
Yes. When you call
modified
from a composable, and it reads those state values, the composable tracks those reads and will trigger recomposition of the composable that the read happened in when they change.
👍 1
e
I thought the
modified
function will be called only with new
object1
or
object2
parameters, not by their properties
a
composable functions track any snapshot state read while the composable function was executing and will invalidate if a new snapshot is committed with changes to those objects
👍 1
and compose UI does the same for layout and drawing