vide
06/24/2022, 11:13 AMval calculationResult by remember { derivedStateOf {
val primaryLocale = LocalConfiguration.current.locales.get(0) // error
// Some filtering, calculations, etc.
} }
Obviously this doesn't work, since CompositionLocal.current is @Composable and results in an error.
If I store the Configuration outside of the derivedStateOf block, it won't work either since it doesn't observe that State is being read and won't update.
val configuration = LocalConfiguration.current
val calculationResult by remember { derivedStateOf {
val primaryLocale = configuration.locales.get(0)
// Some filtering, calculations, etc.
} }
// Doesn't update
What would be an idiomatic/correct way to achieve what I'm trying to do here?Oleksandr Balan
06/24/2022, 11:44 AMremember
it without key, which means once calculated it will not change till Composable leaves the composition.
Either remove remember
, or add configuration
as a key
, so that the whole remember
content will be recalculated when configuration
changes:
val configuration = LocalConfiguration.current
val calculationResult by remember(configuration) { derivedStateOf {
val primaryLocale = configuration.locales.get(0)
// Some filtering, calculations, etc.
} }
Sean McQuillan [G]
06/24/2022, 4:58 PMvide
06/27/2022, 8:26 AMconfiguration
changes? (Opposed to recomposition only when the result of the calculation changes)Sean McQuillan [G]
06/27/2022, 8:10 PMextract class
and move it to Kotlin