01/23/2021, 1:25 AM
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
, 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

Adam Powell

01/23/2021, 1:37 AM
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.
handles the state management and queuing behavior


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.
If you get recomposed in the middle you want the snackbar to still be displayed, just as you'd want the button.
👍 2

Adam Powell

01/23/2021, 3:12 AM
Yep. That's all
does, it just scopes that timeout and shows the current content from the state
👍 3