I want to implement mechanism to force select app ...
# compose
i
I want to implement mechanism to force select app day-night theme. For example: if set returns it, else returns
isSystemInDarkTheme()
. For example this fun will be called
isAppInDarkTheme()
. I also want to recompose all dependent composables. Which parts and mechanism of compose is better to use to achieve behavior like it?
a
Just replace the
isSystemInDarkTheme()
in compose project template with your
isAppInDarkTheme()
and it’ll work.
i
I mean something different:
isAppInDarkTheme()
returns some nullable boolean (for example). Returns it when it is set or
isSystemInDarkTheme()
if doesn’t. This boolean - where must i store it? state, local provider, something different? When it changes how the composition three will know about it? I must notify something or whatever?
a
If a parameter of a composable function is observable and it changes, the function will automatically be recomposed. What you need is just a observable value (such as a
State
or a
StateFlow
) which stores the user preference. As for what you use as the store, it has nothing to do with Compose.