Does anyone have any recommendations around presenting a Snackbar once? Driving the UI from state i...
c
Does anyone have any recommendations around presenting a Snackbar once? Driving the UI from state is easy except when I want to present something at a particular point in time, and only once. I could create state that contains something like
showSnackbar
, but if my UI gets recomposed because of a configuration change the Snackbar will show again. Is the recommended approach to handle the timing in whatever produces state, and after a period of time output state with
showSnackbar = false
?
a
you can present a snack using a suspend call on the state object, and it will return the user's action once they acknowledge it or it is dismissed.
SnackbarHostState
handles the state management and queuing behavior
j
Don't give the snackbar any power. Treat it like any other UI that needs displayed. Put `showSnackbar`true (sorry FUCK slack) in your UI state, start a delayed coroutine, and then flip it to false. The same way you would show a button for 1s. Never let a UI component control it's own dismissal.
6
If you get recomposed in the middle you want the snackbar to still be displayed, just as you'd want the button.
👍 2
a
Yep. That's all
SnackbarHost
does, it just scopes that timeout and shows the current content from the state
👍 3