This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Snackbar
显示在屏幕底部的简短通知,用于提供反馈而不会打断用户
Expo UI 提供了两个组件,对应 Jetpack Compose 的 Snackbar API:
SnackbarHost包装了 Compose 的 SnackbarHost 和 SnackbarHostState。在布局中放置一次,然后调用ref上的showSnackbar。Snackbar 会根据duration自动关闭,也可以通过操作按钮或可选的关闭图标将其关闭。Snackbar是SnackbarHost的纯样式子组件。传入该组件可覆盖颜色,或将操作按钮放到新的一行。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
显示 snackbar
在布局中放置一次 SnackbarHost,并调用其 ref 上的 showSnackbar 来显示消息。Snackbar 消失后,返回的 promise 会解析为 'actionPerformed' 或 'dismissed'。
自定义样式
向 SnackbarHost 传入一个 Snackbar 子组件,即可覆盖颜色或将操作按钮放到新的一行。Snackbar 本身不接受内容,消息和操作按钮由每次 showSnackbar 调用提供。
API
import { Snackbar, SnackbarHost } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<SnackbarProps>
Styling configuration for the snackbar shown by SnackbarHost. Pass as a
child to override colors or place the action on a new line.
boolean • Default: falseWhether the action should be placed on a new line below the message. Useful for long action labels.
ColorValueThe preferred content color used for the message text.
ColorValueThe content color used for the dismiss-action icon button.
Type: React.Element<SnackbarHostProps>
A Material 3 SnackbarHost
that displays snackbars triggered via its ref's showSnackbar method.
ReactNodeOptional Snackbar child supplying styling for shown snackbars. Mirrors
Compose's SnackbarHost(hostState) { data -> Snackbar(data, ...) } lambda.
Types
Literal type: string
How long the snackbar is shown. Mirrors Compose's SnackbarDuration enum.
Acceptable values are: 'short' | 'long' | 'indefinite'
Literal type: string
Reason a snackbar invocation resolved. Mirrors Compose's SnackbarResult enum.
Acceptable values are: 'actionPerformed' | 'dismissed'