This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
模态底部表单
一个 Jetpack Compose ModalBottomSheet 组件,用于从屏幕底部展示内容。
有关跨平台用法,请参阅通用的
BottomSheet— 它会为每个平台渲染合适的原生组件。
Expo UI ModalBottomSheet 与官方 Jetpack Compose 底部抽屉 API 保持一致,并以从底部滑入的模态底部抽屉形式显示内容。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础底部抽屉
在卸载组件之前,使用 ref.hide() 通过动画以编程方式关闭底部抽屉。
跳过部分展开状态
设置 skipPartiallyExpanded 时,底部抽屉会直接以完全展开状态打开,而不会先停在半高位置。
初始完全展开状态
当 initialFullyExpanded 为 true 时,底部抽屉会在首次组合时直接以完全展开状态打开,同时仍保留可到达的部分展开状态。与 skipPartiallyExpanded 不同,用户仍然可以向下拖拽到部分展开状态。partialExpand() 方法也仍然可用。
自定义颜色
使用 containerColor、contentColor 和 scrimColor 自定义底部抽屉的外观。
自定义拖拽把手
使用 ModalBottomSheet.DragHandle 插槽提供自定义拖拽把手,或者设置 showDragHandle={false} 将其完全隐藏。
底部抽屉中的 React Native 内容
使用 RNHostView 将可交互的 React Native 视图嵌入 Compose 底部抽屉中。这样你就可以混合使用 Compose 布局与 Pressable 和 Text 等 RN 组件。
带弹性布局的 React Native 内容
不使用 matchContents 的 RNHostView 可以让 RN 视图填充底部抽屉中剩余的空间。将其与父级 Column 上固定的 height 修饰符结合使用,以控制底部抽屉尺寸。
可滚动的 React Native 内容
使用 RNHostView 将可滚动的 React Native 列表(例如 FlatList、ScrollView,或高性能列表如 FlashList 或 Legend List)嵌套到抽屉中。为可滚动组件设置 nestedScrollEnabled,使其优先滚动自身内容。滚动到顶部边缘后,剩余的拖拽操作会移动抽屉。如果未设置 nestedScrollEnabled,列表会消耗手势,抽屉则保持不动。
不可关闭的底部抽屉
结合 properties、sheetGesturesEnabled 创建一个只能通过编程方式关闭的底部抽屉。
API
import { ModalBottomSheet } from '@expo/ui/jetpack-compose';
Constants
Props
ReactNodeThe children of the ModalBottomSheet component.
Can include a ModalBottomSheet.DragHandle slot for a custom drag handle.
ColorValueThe preferred color of the content inside the bottom sheet.
boolean • Default: falseOpens the sheet fully expanded on first composition. Ignored when skipPartiallyExpanded is true.
() => voidCallback function that is called when the user dismisses the bottom sheet (via swipe, back press, or tapping outside the scrim).
ModalBottomSheetPropertiesProperties for the modal window behavior.
Ref<ModalBottomSheetRef>Can be used to imperatively hide the bottom sheet with an animation.
boolean • Default: trueWhether gestures (swipe to dismiss) are enabled on the bottom sheet.
boolean • Default: trueWhether to show the default drag handle at the top of the bottom sheet.
Ignored if a custom ModalBottomSheet.DragHandle slot is provided.