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
一个 SwiftUI 底部弹窗组件,从屏幕底部呈现内容。
有关跨平台用法,请参见通用的
BottomSheet—— 它会针对每个平台渲染相应的原生组件。
Expo UI BottomSheet 与官方 SwiftUI sheet API 保持一致,并从屏幕底部展示内容。


在 iOS 上,如果要在另一个底部弹窗之上再显示一个底部弹窗,应将第二个
BottomSheet嵌套在第一个弹窗的内容中,而不是与其并列。这是底层 SwiftUIsheet修饰符的限制。有关更多信息,请参见如何展示多个 sheet。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
使用
基本底部弹窗
将打开弹窗的控件作为 anchor 属性传入。子元素是弹窗的内容。
将 React Native 视图用作锚点
锚点可以是 React Native 视图。将其包裹在 RNHostView 中。
适配内容的底部弹窗
使用 fitToContents 属性可让弹窗自动调整大小以适配其内容。
自定义背景
默认情况下,弹窗使用系统的半透明材质背景(iOS 26 上为 Liquid Glass)。使用 Group 上的 presentationBackground 修饰符自行绘制弹窗背景,这也会使弹窗不再使用该半透明材质。它接受任何 ShapeStyle:纯色、材质或渐变。
在 iOS 26 上,材质(例如
{ type: 'material', material: 'ultraThin' })会渲染为纯色,而不是半透明模糊效果。请选择一种在不透明状态下也清晰易辨的背景。
优先使用
presentationBackground,而不是在 sheet 内容上使用background修饰符。background位于内容自身背景的 后面,因此Form或List会将其遮住,并且当 sheet 在不同 detent 之间移动时,颜色显示会不一致。presentationBackground会给 sheet 表面本身着色,因此在每个 detent 下都保持一致。当内容是Form或List时,也请添加scrollContentBackground('hidden'),这样 sheet 颜色就能透过分组背景显示出来。
带有停靠位置的底部弹窗
在 Group 上使用 presentationDetents 修饰器来控制可用高度。你可以使用:
'medium':系统中等高度(大约半屏)'large':系统大高度(全屏){ fraction: number }:屏幕高度的比例(0-1){ height: number }:以点为单位的固定高度
跟踪停靠位置选择的底部弹窗
将 selection 和 onSelectionChange 选项传递给 presentationDetents,即可通过编程方式控制弹窗停靠到哪个停靠位置。
带背景交互的底部弹窗
使用 presentationBackgroundInteraction 修饰器,允许与弹窗后面的内容进行交互。
不可交互关闭的底部弹窗
使用 interactiveDismissDisabled 修饰器可防止用户通过滑动关闭弹窗。
带有 React Native 内容的底部弹窗
使用 RNHostView 将 React Native 组件嵌入到底部弹窗中。设置 matchContents 可让宿主视图自动调整大小以适配其内容。
带有灵活 React Native 内容的底部弹窗
当使用带有 flex: 1 的 React Native 内容时,请省略 RNHostView 上的 matchContents 属性,并使用 presentationDetents 来控制弹窗高度。
可滚动的 React Native 内容
将可滚动的 React Native 列表,例如 FlatList、ScrollView,或高性能列表(如 FlashList 或 Legend List)嵌套在带有 RNHostView 的弹窗中。使用 presentationDetents 设置弹窗尺寸,列表会在该高度内滚动。
API
import { BottomSheet } from '@expo/ui/swift-ui';
Component
Type: React.Element<BottomSheetProps>
BottomSheet presents content from the bottom of the screen.
ReactNodeA view the sheet is anchored to, for example the Button that opens it. Rendered in place and
kept mounted, so presenting the sheet doesn't shift surrounding layout. Optional.
ReactNodeThe sheet's content, mounted while presented and unmounted after dismiss. Wrap it in Group
to apply presentation modifiers.
boolean • Default: falseWhen true, the sheet will automatically size itself to fit its content.
This sets the presentation detent to match the height of the children.
() => voidCallback function that is called after the BottomSheet has been fully dismissed.
(isPresented: boolean) => voidCallback function that is called when the BottomSheet presented state changes.