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
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.
Adam Powell
01/23/2021, 1:39 AM
SnackbarHostState
handles the state management and queuing behavior
j
jw
01/23/2021, 1:50 AM
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
jw
01/23/2021, 1:51 AM
If you get recomposed in the middle you want the snackbar to still be displayed, just as you'd want the button.
👍 2
a
Adam Powell
01/23/2021, 3:12 AM
Yep. That's all
SnackbarHost
does, it just scopes that timeout and shows the current content from the state