This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
小吃吧
出现在屏幕底部的简短通知,用于在不打断用户的情况下提供反馈。
Expo UI 提供了两个组件,它们与 Jetpack Compose 的 Snackbar API 相对应:
🌐 Expo UI exposes two components that mirror Jetpack Compose's Snackbar APIs:
SnackbarHost封装了 Compose 的 SnackbarHost 和 SnackbarHostState。在布局中放置一次,然后在ref上调用showSnackbar。Snackbar 会根据duration自动消失,也可以通过操作按钮或可选的关闭图标手动关闭。Snackbar是SnackbarHost的仅样式子元素。传入一个以覆盖颜色或将操作放在新行上。


安装
🌐 Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
🌐 Usage
显示一个 snackbar
🌐 Showing a snackbar
在你的布局中放置一个 SnackbarHost,然后在它的引用上调用 showSnackbar 来显示一条消息。返回的 Promise 会在 snackbar 消失后以 'actionPerformed' 或 'dismissed' 作为结果解决。
🌐 Place a SnackbarHost once in your layout and call showSnackbar on its ref to display a message. The returned promise resolves with 'actionPerformed' or 'dismissed' once the snackbar goes away.
自定义样式
🌐 Custom styling
将Snackbar子项传递给SnackbarHost以覆盖颜色或将操作放在新行。Snackbar本身不包含内容,消息和操作来自每个showSnackbar调用。
🌐 Pass a Snackbar child to SnackbarHost to override colors or place the action on a new line. The Snackbar itself takes no content, the message and action come from each showSnackbar call.
应用接口
🌐 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'