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 属性自动调整工作表大小,使其适应内容
自定义背景
默认情况下,工作表使用系统的半透明材质背景(iOS 26 上为 Liquid Glass)。在 Group 上使用 presentationBackground 修饰符来自定义工作表背景,同时工作表也不会再使用该半透明材质。它接受任何 ShapeStyle:纯色、材质或渐变
iOS 26 会将材质(例如
{ type: 'material', material: 'ultraThin' })渲染为纯色,而不是半透明模糊效果。请选择在不透明状态下也清晰易读的背景
建议优先使用
presentationBackground,而不是在工作表内容上使用background修饰符。background位于内容自身背景的后面,因此Form或List会覆盖它,并且当工作表在不同 detent 之间移动时,颜色显示也不一致。presentationBackground会直接设置工作表表面的颜色,因此在每个 detent 下都能保持一致。当内容为Form或List时,还应添加scrollContentBackground('hidden'),以便工作表颜色透过分组背景显示
带有 presentation detent 的底部工作表
在 Group 上使用 presentationDetents 修饰符来控制可用高度。你可以使用:
'medium':系统中等高度(约为屏幕的一半)'large':系统大高度(全屏){ fraction: number }:屏幕高度的比例(0-1){ height: number }:以点为单位的固定高度
跟踪底部工作表的 detent 选择
将 selection 和 onSelectionChange 选项传递给 presentationDetents,以便以编程方式控制工作表吸附到哪个 detent
带有背景交互的底部工作表
使用 presentationBackgroundInteraction 修饰符,允许与工作表后面的内容进行交互
不可关闭的底部工作表
使用 interactiveDismissDisabled 修饰符,防止用户通过滑动关闭工作表
带有 React Native 内容的底部工作表
使用 RNHostView 将 React Native 组件嵌入底部工作表。设置 matchContents,使宿主视图自动调整大小以适应其内容
带有可伸缩 React Native 内容的底部工作表
使用 flex: 1 的 React Native 内容时,请省略 RNHostView 上的 matchContents 属性,并使用 presentationDetents 控制工作表高度
可滚动的 React Native 内容
使用 RNHostView 将可滚动的 React Native 列表(例如 FlatList、ScrollView,或 FlashList、Legend List 等高性能列表)嵌套在工作表中。使用 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.