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
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
1 year ago
Don't give the snackbar any power. Treat it like any other UI that needs displayed. Put showSnackbartrue (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.