Let's assume we have an app that has some settings...
# compose-android
g
Let's assume we have an app that has some settings and one of the settings is a switch button which changes the color (or font size, whatever) of the
Text
. The setting is stored in
DataStore
. Only in certain screens and at specific places the
Text
must change based on the settings. So imagine we wrap this
Text
in a composable named
DynamicText
. The
DynamicText
can be found in ScreenA, ScreenB and ScreenD. One way I assume to achieve this is to observe the setting in the viewmodels of those screens and update
DynamicText
. However is there any other way to achieve this? I imagine something like a singleton class "Observer" that holds the value of the setting and we can somehow pass it to
DynamicText
, is that possible? Or any other way?
s
If you want this part of the screens to not come from the ViewModels you could take some inspiration from NiA for example where some part of the App state is just held in a normal state object, which is constructed in your main activity for example, and you can pass this down to any composable which is interested in this state. The source of truth can still be a DataStore or whatever you want it to be.
g
hmm that seems quite what I wanted. eyxaristw!
🌟 1
s
Glad to hear it! Parakalo 😊