The `SnackbarDuration.Indefinite` javadoc says "_S...
# compose
c
The
SnackbarDuration.Indefinite
javadoc says "_Show the Snackbar indefinitely until explicitly dismissed or action is clicked_", however so far I haven't figured out any way for the user to manually dismiss a snackbar other than clicking the action. How can this be done?
2
a
I think it means “dismissed programmatically”.
1
c
Tragic, I'd love to provide a way for the user to dismiss it manually but I am using the action button for something else already and the Snackbar API seems pretty closed for extension when using it withing a scaffold / snackbarhost
a
Actually it’s quite easy to extend. You can use your own Snackbar implementation or apply any modifiers to the official implementation. We implemented swipe-to-dismiss for snackbars like this:
Copy code
Scaffold(
    snackbarHost = { state ->
        SnackbarHost(hostState = state) { data ->
            SwipeDismissSnackbar(snackbarData = data)
        }
    }
)
c
Thanks, I'll try this, maybe I was thinking about it the wrong way
I guess I was trying to conditionally change the Snackbar implementation, e.g. I wouldn't always want the user to be able to manually dismiss it. (Was thinking of optionally giving the entire Snackbar a click handler). But then I would need to somehow pass that click handler (and whether the Snackbar should be clickable) through SnackbarData which I couldn't think of a clean way to do. But just making all Snackbars swipe-to-dismiss seems reasonable.
Would be nice if we could extend SnackbarData to add some of our own data that our implementation might need