chris-horner

    chris-horner

    1 year ago
    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
    ?
    Adam Powell

    Adam Powell

    1 year ago
    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

    jw

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

    Adam Powell

    1 year ago
    Yep. That's all
    SnackbarHost
    does, it just scopes that timeout and shows the current content from the state