Did you find a solution to your problem? I'm using CompositionLocal
(https://developer.android.com/develop/ui/compose/compositionlocal#creating)
Something like so:
data class Settings(val some: Int? = null)
internal val LocalSettings = compositionLocalOf { Settings() }
fun Fragment.composeView(content: @Composable () -> Unit): ComposeView {
val settingsViewModel = get<SettingsViewModel>() // here injected by koin
settingsViewModel.init() // <- launch and extract values from datastore/flow
return ComposeView(requireContext()).apply {
setContent {
val settings = remember(settingsViewModel.some) { Settings(settingsViewModel.some) }
CompositionLocalProvider(LocalSettings provides settings) {
MaterialTheme {
content()
}
}
}
}
}
Then value can be use in the hierarchy:
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = composeView {
val some = LocalSettings.current.some
Text(some)
}