Vahalaru
02/11/2022, 12:39 AMLaunchedEffect will cancel and re-launch if
// scaffoldState.snackbarHostState changes
LaunchedEffect(scaffoldState.snackbarHostState) {
// Show snackbar using a coroutine, when the coroutine is cancelled the
// snackbar will automatically dismiss. This coroutine will cancel whenever
// state.hasError is false, and only start when state.hasError is true
// (due to the above if-check), or if scaffoldState.snackbarHostState changes.
scaffoldState.snackbarHostState.showSnackbar(
message = "Error message",
actionLabel = "Retry message"
)
}
}
Scaffold(scaffoldState = scaffoldState) {
/* ... */
}
}Vahalaru
02/11/2022, 12:45 AMKirill Grouchnikov
02/11/2022, 12:50 AMMutableInteractionSource to a button lets you "inject" interactions to emulate programmatic changes to the pressed / hovered / focused / ... state.
Or to pass a ScrollState and then programmatically call animateScrollTo based on a certain condition - outside the specific inner logic of that scrollable component.Vahalaru
02/11/2022, 12:55 AMKirill Grouchnikov
02/11/2022, 12:57 AMKirill Grouchnikov
02/11/2022, 12:58 AMScaffoldState.snackbarHostState.showSnackbar for example, but I'm not sure how relevant that isKirill Grouchnikov
02/11/2022, 1:00 AMMyScreen shows the error snackbar based on a certain data state. But you could also do so in the caller of MyScreen if that caller passed its own ScaffoldState instance.Vahalaru
02/11/2022, 1:28 AMVahalaru
02/11/2022, 1:30 AMKirill Grouchnikov
02/11/2022, 1:31 AMsomeScreen and anotherScreen is that the first one requires you to pass a controller, and the second one provides a default one if you don't need that communication channel and are OK with that default.Vahalaru
02/11/2022, 3:00 AMVahalaru
02/11/2022, 3:00 AM