This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
BottomSheet
一个 SwiftUI BottomSheet 组件,从屏幕底部展示内容。
信息 有关跨平台用法,请参见通用的
BottomSheet— 它会针对每个平台渲染相应的原生组件。
Expo UI BottomSheet 与官方 SwiftUI sheet API 保持一致,并从屏幕底部呈现内容。


安装
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 属性可自动调整弹窗大小以适配其内容。
自定义背景颜色
默认情况下,sheet 使用系统的半透明材质背景(iOS 26 上为 Liquid Glass)。可以在 Group 上使用 presentationBackground 修饰符,将 sheet 改为纯色背景,这样也会让 sheet 不再使用这种半透明材质。
优先使用
presentationBackground,而不是在 sheet 内容上使用background修饰符。background位于内容自身背景的 后面,因此会被Form或List覆盖,并且当 sheet 在不同 detent 之间移动时,颜色显示会不一致。presentationBackground作用于 sheet 表面本身,因此在每个 detent 下都能保持一致。当内容是Form或List时,还要添加scrollContentBackground('hidden'),这样 sheet 颜色才能透过分组背景显示出来。
带有 presentation detents 的底部弹窗
在 Group 上使用 presentationDetents 修饰器来控制可用高度。你可以使用:
'medium':系统中等高度(约半屏)'large':系统大高度(全屏){ fraction: number }:屏幕高度的比例(0-1){ height: number }:以点为单位的固定高度
跟踪 detent 选择的底部弹窗
将 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.