Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Queue of snackbars jetpack Compose

When i call Snackbar multiple times, they create a queue and occure one by one. I want a new Snachbar to immediately close previous one. Here is my code:

Scaffold(
    snackbarHost = {
        SnackbarHost(it) { data ->
            Snackbar(
                actionColor = color5,
                snackbarData = data
            )
        }
    },...

That`s what documentation says:

SnackbarHostState guarantees to show at most one snackbar at a time. If this function is called while another snackbar is already visible, it will be suspended until this snack bar is shown and subsequently addressed. If the caller is cancelled, the snackbar will be removed from display and/or the queue to be displayed.

Any ideas how can i switch off this function of SnackbarHost?

like image 444
Максим Зозуляк Avatar asked Sep 20 '25 12:09

Максим Зозуляк


1 Answers

You could dismiss the previous snack bar before showing a new one. I don't know whether it is intended for this purpose, but SnackbarData interface in SnackbarHostStateclass has a dismiss() method:

snackbarHostState.currentSnackbarData?.dismiss()
like image 193
Jack Avatar answered Sep 23 '25 05:09

Jack