Jordi Saumell
01/29/2021, 6:36 PMZach Klippenstein (he/him) [MOD]
01/29/2021, 6:40 PMI haven’t found a way of observing the AmbientConfigurationWhat do you mean by this? If you’re reading the ambient, you’re observing it.
chao
01/29/2021, 6:41 PMJordi Saumell
01/29/2021, 6:42 PMAmbientConfiguration.current.locales
if I use this it does not trigger recomposition. Not sure of how this works… is it possible it is because it is mutating instead of assigning a new instance?Jordi Saumell
01/29/2021, 6:45 PMZach Klippenstein (he/him) [MOD]
01/29/2021, 6:51 PMProvideAndroidAmbients
):
var configuration by remember {
mutableStateOf(
context.resources.configuration,
@OptIn(ExperimentalComposeApi::class)
neverEqualPolicy()
)
}
owner.configurationChangeObserver = { configuration = it }
Might be a bug?Jordi Saumell
01/29/2021, 6:59 PM/**
* Used for updating the ConfigurationAmbient when configuration changes - consume the
* configuration ambient instead of changing this observer if you are writing a component
* that adapts to configuration changes.
*/
var configurationChangeObserver: (Configuration) -> Unit = {}
but I tried passing locales as parameter to a composable and it didn’t trigger recomposition.
Not sure if I’m missing something as I do not have a deep understanding of how recompositions workZach Klippenstein (he/him) [MOD]
01/29/2021, 7:10 PMJordi Saumell
01/29/2021, 7:20 PMval language: Int by appVm.currentLanguage.collectAsState()
AppLayout(language)
If I do this it does not work:
val locales = AmbientConfiguration.current.locales
AppLayout(locales)
Zach Klippenstein (he/him) [MOD]
01/29/2021, 7:23 PMLocaleList
is documented as an immutable list, and it isn’t annotated as Stable
, so i would think this should force recomposition on every change. Were you able to verify that AmbientConfiguration.current
is actually giving you a new Configuration
when it changes?Jordi Saumell
01/29/2021, 7:27 PMappVm.currentLanguage.collectAsState()
?Zach Klippenstein (he/him) [MOD]
01/29/2021, 7:28 PMprintln("configuration=${AmbientConfiguration.current}")
in your composable function, and see if it prints different values when you change the localeJordi Saumell
01/29/2021, 7:56 PMJordi Saumell
01/29/2021, 7:58 PMJordi Saumell
01/29/2021, 8:00 PMZach Klippenstein (he/him) [MOD]
01/29/2021, 10:06 PM