Roberto Leinardi
11/09/2021, 8:14 PMScaffoldState
across the entire application (e.g. via singleton in Hilt)?
I have the feeling that would be really bad but I can't think of another way to solve this issue: https://stackoverflow.com/questions/69902988/how-to-show-snackbars-from-composables-or-viewmodels-on-a-multi-module-single-atad
11/09/2021, 8:39 PMSnackbarHostState
from your top-level Composable function would work. You can then use rememberScaffoldState(snackbarHostState=...)
where needed.tad
11/09/2021, 8:42 PMRoberto Leinardi
11/09/2021, 8:42 PMSnackbarHostState
since the Composable do not see each others. I'm not sure if you checked the SO link, but the architecture of the project is a little complex, mainly because of the multi module aspect.Roberto Leinardi
11/09/2021, 8:43 PMhttps://i.stack.imgur.com/60RWh.png▾
Roberto Leinardi
11/09/2021, 8:44 PMtad
11/09/2021, 8:44 PMSnackbarHostState
, and whatever calls those functions can supply one.tad
11/09/2021, 8:51 PMRoberto Leinardi
11/09/2021, 8:51 PMSnackbarHostState
via Hilt? This way I could just grab the instance in every ViewModel where is needed and just show a Snackbar from there.
I'm just curious to understand what issue it might cause: could it be some concurrency issues or some leaks?tad
11/09/2021, 8:54 PMtad
11/09/2021, 8:56 PMtad
11/09/2021, 8:58 PMRoberto Leinardi
11/09/2021, 9:01 PMRoberto Leinardi
11/09/2021, 9:02 PMCompositionLocalProvider
seems pretty interesting!Roberto Leinardi
11/09/2021, 9:03 PMRoberto Leinardi
11/09/2021, 9:27 PMval LocalSnackbarHostState = compositionLocalOf<SnackbarHostState> { error("No SnackbarHostState provided") }
CompositionLocalProvider(
LocalSnackbarHostState provides scaffoldState.snackbarHostState
) {
[...]
}
val snackbarHostState = LocalSnackbarHostState.current