Adjustable timing - Jetpack Compose
In Jetpack Compose, a Toast
is often used display temporary messages. The display duration might be too short for people to read or hear the message.
We recommend displaying messages by using an AlertDialog
or Snackbar
with the duration set to SnackbarDuration.Indefinite
. Don't forget to add a close button.
Also check whether Executors
, Handler
or Timer
are used somewhere. If there are any time limits, make sure they can be extended.
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
snackbarHost = { SnackbarHost(snackbarHostState) },
floatingActionButton = {
ExtendedFloatingActionButton(
onClick = {
// show snackbar as a suspend function
scope.launch {
snackbarHostState.showSnackbar(
message = "Snackbar title",
actionLabel = "Appt",
withDismissAction = true,
duration = SnackbarDuration.Indefinite
)
}
}
) {
// FAB content...
}
},
content = { innerPadding ->
// Scaffold content...
}
)