show
Shows or queues a snack, will be shown at bottom of the SnackbarHost's window
Return
The result of the snack action, which will be: - SnackResult.Dismissed if snack dismissed by timeout or user cancel - SnackResult.ActionPerformed if user clicked the action button - SnackResult.Failure if called in a non-window container context or on other errors
Parameters
The message to be displayed in the snack.
The description to be displayed in the snack. Defaults to an empty string.
The leading icon to be displayed in the snack. Defaults to null.
The action to be performed when the snack is clicked. Defaults to an empty string.
The duration for which the snack should be displayed. Defaults to SnackbarDuration.Default.
Samples
com.pico.spatial.ui.design.samples.SnackSampleDisplays a snack with the provided message, description, leading icon, trailing actions, and duration.
Return
The result of the snack action, which will be: - SnackResult.Dismissed if snack dismissed by timeout or user cancel - SnackResult.ActionPerformed if user clicked the action button - SnackResult.Failure if called in a non-window container context or on other errors
Parameters
The composable function that provides the message content of the snack.
The composable function that provides the description content of the snack.
The composable function that provides the leading icon content of the snack.
The composable function that provides the trailing actions content of the snack.
The duration for which the snack should be displayed. Defaults to SnackbarDuration.Default.
Samples
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import com.pico.spatial.ui.design.Button
import com.pico.spatial.ui.design.Icon
import com.pico.spatial.ui.design.IconButton
import com.pico.spatial.ui.design.R
import com.pico.spatial.ui.design.Text
import com.pico.spatial.ui.design.windows.LocalSnackbarHostState
import com.pico.spatial.ui.design.windows.SnackbarHost
import com.pico.spatial.ui.design.windows.SnackbarResult
import kotlinx.coroutines.launch
fun main() {
//sampleStart
SnackbarHost {
val state = LocalSnackbarHostState.current
val coroutineScope = rememberCoroutineScope()
Button(
onClick = {
coroutineScope.launch {
state.show(
message = { Text("Hello") },
leadingIcon = {
Icon(
painter = painterResource(R.drawable.ic_sui_rating_star),
contentDescription = null,
)
},
trailingActions = {
Button(onClick = { this.performAction() }) { Text("OK") }
IconButton(onClick = { this.dismiss() }) {
Icon(
painter = painterResource(R.drawable.ic_sui_close),
contentDescription = null,
)
}
},
)
}
}
) {
Text("Show snack")
}
}
//sampleEnd
}