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).
BottomSheet
与 @gorhom/bottom-sheet 兼容的底部弹出层。
A BottomSheet 组件,其 API 与 @gorhom/bottom-sheet 兼容。它封装了平台特定的 @expo/ui 原语:Android 上的 Jetpack Compose ModalBottomSheet,以及 iOS 上的 SwiftUI BottomSheet。在 web 上,它使用 HTML <dialog> 底部弹窗。
如果你需要对平台特定的样式、修饰器或布局行为进行更底层的控制,请直接使用原生原语。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
从 @gorhom/bottom-sheet 迁移
-
将以下导入更新为:
import BottomSheet, { BottomSheetView } from '@gorhom/bottom-sheet';改为使用
@expo/ui/community/bottom-sheet:import BottomSheet, { BottomSheetView } from '@expo/ui/community/bottom-sheet'; -
此实现不需要
react-native-gesture-handler中的GestureHandlerRootView。如果应用的其他部分需要它,你可以保留。 -
不支持诸如
BottomSheetBackdrop、BottomSheetHandle、BottomSheetFooter、BottomSheetDraggableView、BottomSheetVirtualizedList、BottomSheetFlashList、useBottomSheetModal、useBottomSheetSpringConfigs和useBottomSheetTimingConfigs之类的组件和 hook 导出。为保持 API 兼容性,导出了一些相关的属性类型。
基本用法
BottomSheetModal
从 @gorhom/bottom-sheet 的 modal API 迁移时,请使用 BottomSheetModal。它会以关闭状态开始,并通过 present() 打开。
动态尺寸
未提供 snapPoints 时,底部弹窗默认会自动调整大小以适配其内容。请使用 BottomSheetView 作为底部弹窗内容的包装器。
可滚动的 React Native 内容
底部弹窗支持将 React Native 的 FlatList 或 ScrollView(也支持像 FlashList 或 Legend List 这样的高性能列表)作为子组件来显示可滚动内容。启用 nestedScrollEnabled 后,列表会先滚动自身内容。到达顶部边缘后,剩余的拖动会移动弹窗。为了兼容 @gorhom/bottom-sheet,还导出了 BottomSheetFlatList 和 BottomSheetScrollView,但它们只是对 React Native 组件的简单重导出。
平台行为
@gorhom/bottom-sheet 会在其父视图底部以内联方式渲染。此组件在 Android 和 iOS 上使用原生模态呈现,在 web 上使用 HTML <dialog>。
这种差异是有意为之。@gorhom/bottom-sheet 通过 react-native-gesture-handler 和 react-native-reanimated 实现手势和动画层,而 @expo/ui/community/bottom-sheet 则将这些行为交由 Jetpack Compose、SwiftUI,以及 web 上的 HTML <dialog> 处理。因此,此组件最适用于模态底部弹窗流程,包括使用 BottomSheet API 而非 BottomSheetModal 的调用场景。
信息 在 iOS 上,如果要在另一个底部弹窗之上再显示一个底部弹窗,应将第二个
BottomSheet嵌套在第一个弹窗的内容中,而不是并列放置。这是底层 SwiftUIsheet修饰符的限制。有关更多信息,请参阅 如何呈现多个 sheet。
支持的导出
兼容性说明
- 支持
snapPoints、index、onChange、onClose、onDismiss、enablePanDownToClose和enableDynamicSizing。 handleComponent={null}会隐藏原生或 web 的拖拽指示器。自定义把手组件不会在原生平台上渲染。backgroundStyle在 web 上完全生效。在 Android 上,backgroundColor用于原生容器颜色。在 iOS 上,使用系统底部弹窗背景。- 动画、超额拖拽、内容拖动、把手拖动、键盘行为、自定义背景层、自定义背景、自定义页脚、动画值和分离式属性为兼容 API 而接受,但不会改变行为。
API
import BottomSheet from '@expo/ui/community/bottom-sheet';
Components
Type: React.Element<BottomSheetProps>
Bottom sheet component. Defaults to index={0} and opens at the first snap point on mount.
Props for the BottomSheet component. API-compatible with @gorhom/bottom-sheet where native platform behavior allows.
boolean • Default: trueWhether the sheet should automatically size to fit its content.
boolean • Default: falseWhether the sheet can be dismissed by panning down.
number • Default: 0Initial snap point index. Set to -1 to start closed.
(index: number) => voidCalled when the current snap point index changes.
() => voidAlias for onClose for BottomSheetModal compatibility.
Type: React.Element<BottomSheetProps>
Modal variant of BottomSheet. Starts closed and opens with present().
Type: React.Element<{
children: React.ReactNode
}>
Provider for BottomSheetModal. It renders children directly for API compatibility.
Type: React.Element<BottomSheetViewProps>
A wrapper for content inside a BottomSheet.
boolean • Default: trueWhether the sheet should automatically size to fit its content.
boolean • Default: falseWhether the sheet can be dismissed by panning down.
number • Default: 0Initial snap point index. Set to -1 to start closed.
(index: number) => voidCalled when the current snap point index changes.
() => voidAlias for onClose for BottomSheetModal compatibility.
Hooks
Returns the imperative methods for the nearest BottomSheet.
BottomSheetMethods