This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
ModalBottomSheet
一个从屏幕底部呈现内容的 Jetpack Compose ModalBottomSheet 组件
如需跨平台使用,请参阅通用的
BottomSheet— 它会根据平台渲染相应的原生组件。
Expo UI ModalBottomSheet 匹配官方 Jetpack Compose Bottom Sheet 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 在 Compose 底部表单中嵌入交互式 React Native 视图。这样可以将 Compose 布局与 Pressable 和 Text 等 RN 组件混合使用。
带 flex 的 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.