orangy
07/09/2022, 8:43 PMderivedStateOf
or maybe there is a bug. I have remembered derived state which basically gets parameter of a composable function (AnnotatedText) and produces a value from it, some other local mutable state (hover state) and some composition local (theme holding colors). The problem is that the derived state doesn’t produce change when composition local changes. If I remove remember
it obviously recomposes, new instance is created and it works fine. But that means that it will recompose and recalculate the value whenever anything changes, which is rather expensive in my case. Do I miss something?Tash
07/09/2022, 8:55 PMDominaezzz
07/09/2022, 9:32 PMderiveStateOf
won't work on arbitrary variables in a composition. It only works on mutableStateOf(...)
values. So if you read a State
in a deriveStateOf
, it'll subscribe to changes to it.rememberUpdatedStateOf
around the arbitrary variable, that might do what you want.orangy
07/09/2022, 9:47 PMZach Klippenstein (he/him) [MOD]
07/09/2022, 9:56 PM.current
, that call is tracked. But once you've read the local value, if you pass that somewhere else, it's just whatever value was in the local when it was read. If, for example, you capture the value in a memoized derivedStateOf
lambda, you just capture the value, not the underlying snapshot state.orangy
07/09/2022, 10:03 PMZach Klippenstein (he/him) [MOD]
07/09/2022, 10:04 PMorangy
07/09/2022, 10:07 PMZach Klippenstein (he/him) [MOD]
07/09/2022, 10:08 PMorangy
07/09/2022, 10:11 PM