I am trying to make the floating action button move up to make room for the Snackbar to appear, which is the normal behavior when using android xml UI files.
It looks like its not implemented in Scafford.
Please find below my code so far on Compose for desktop (But it should be similar on Android) :
fun main() = Window(
title = "Box Demo",
size = IntSize(600, 500)
) {
MaterialTheme {
val snackbarHostState = remember { SnackbarHostState() }
val scaffoldState = rememberScaffoldState()
Scaffold(
scaffoldState = scaffoldState,
snackbarHost = {scaffoldState.snackbarHostState },
floatingActionButtonPosition = FabPosition.End,
floatingActionButton = { FloatingActionButton(onClick = {}) { Text("+") } },
topBar = { TopAppBar(title = { Text("TopAppBar") }) },
bottomBar = { BottomAppBar() { Text("BottomAppBar") } }
) {
Column(
modifier = Modifier.fillMaxSize()
) {
Button(
modifier = Modifier.padding(top = 20.dp, start = 20.dp),
onClick = {
GlobalScope.launch {
snackbarHostState.showSnackbar(
message = "Hey I am a snackbar",
actionLabel = "Hide",
duration = SnackbarDuration.Short
)
}
}
) {
Text("Show snackbar")
}
SnackbarHost(
modifier = Modifier.padding(top = 180.dp),
hostState = snackbarHostState,
snackbar = {
Snackbar(
action = {
TextButton(
onClick = {
snackbarHostState.currentSnackbarData?.dismiss()
}
) {
Text(
text = snackbarHostState.currentSnackbarData?.actionLabel ?: "",
style = TextStyle(color = Color.White)
)
}
}
) {
Text(snackbarHostState.currentSnackbarData?.message ?: "")
}
}
)
}
}
}
}
my config:
plugins {
kotlin("jvm") version "1.4.21"
id("org.jetbrains.compose") version "0.2.0-build132"
}