Shakil Karim
12/27/2021, 10:47 AMChrimaeon
12/27/2021, 12:23 PMAlbert Chang
12/27/2021, 2:06 PMFlow
and collect the flow in a LaunchedEffect
.Chrimaeon
12/27/2021, 2:09 PMAlbert Chang
12/27/2021, 2:12 PMChrimaeon
12/27/2021, 2:14 PMAlbert Chang
12/27/2021, 2:18 PMColton Idle
12/27/2021, 3:05 PMisUserLoggedIn
state and navigates to the correct destination as needed:"
I'm still learning, so I'm probably wrong.
@Chrimaeon if you want, the docs were recently updated to have a case on snackbars.
https://developer.android.com/jetpack/guide/ui-layer/events#consuming-trigger-updatesChrimaeon
12/27/2021, 3:20 PMAlbert Chang
12/27/2021, 3:26 PMColton Idle
12/27/2021, 3:52 PMAdam Powell
12/27/2021, 4:25 PMshowSnackbar
method) and reduce those events to state (currentSnackbarData
). The methods on the SnackbarData
interface are also events: events published by the UI itself both when the user interacts with the snackbar and when the UI determines that it has shown a particular message for a timeout periodSnackbarHostData
has no UI dependencies, so it's safe to keep one in a ViewModel
or even a global singleton if you feel like it. Composables on any screen in your app can present this using a SnackbarHost
or your own implementation, since SnackbarHost
only uses the public API of SnackbarHostState
. You can test anything that your code does to a SnackbarHostState
without involving composition or UI at all.SnackbarHostState
instance without worrying about losing events or which UI consumed the event that a particular snackbar notification is talking aboutArjun Achatz
12/27/2021, 5:03 PM