Reference version

This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

底部弹出面板

一种从屏幕底部滑出的模态弹出面板。

Android
iOS
Web
Included in Expo Go
Recommended version:
~57.0.0

一个从屏幕底部滑出的模态面板。该面板的可见性是受控的——从 React 状态切换 isPresented,并通过 onDismiss 将其关闭(当用户向下滑动或点击遮罩层时会调用)。

安装

Terminal
npx expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

基础底部弹窗

BottomSheetExample.tsx
import { useState } from 'react'; import { Host, Column, Button, BottomSheet, Text } from '@expo/ui'; export default function BottomSheetExample() { const [isPresented, setIsPresented] = useState(false); return ( <Host style={{ flex: 1 }}> <Button label="打开弹窗" onPress={() => setIsPresented(true)} /> <BottomSheet isPresented={isPresented} onDismiss={() => setIsPresented(false)}> <Column spacing={12}> <Text textStyle={{ fontSize: 18, fontWeight: '700' }}>弹窗内容</Text> <Text>向下拖动或点击遮罩层即可关闭。</Text> <Button label="关闭" onPress={() => setIsPresented(false)} /> </Column> </BottomSheet> </Host> ); }

隐藏拖拽指示器

对于没有把手的弹窗,传入 showDragIndicator={false}

BottomSheetNoIndicatorExample.tsx
import { useState } from 'react'; import { Host, Button, BottomSheet, Text } from '@expo/ui'; export default function BottomSheetNoIndicatorExample() { const [isPresented, setIsPresented] = useState(false); return ( <Host style={{ flex: 1 }}> <Button label="打开" onPress={() => setIsPresented(true)} /> <BottomSheet isPresented={isPresented} onDismiss={() => setIsPresented(false)} showDragIndicator={false}> <Text>没有拖拽把手。</Text> </BottomSheet> </Host> ); }

吸附点

传入 snapPoints 让用户可以在多个静止高度之间拖动弹窗。你可以使用语义值 'half''full' 以获得跨平台一致性。{ fraction }{ height } 形式会在 iOS 和 web 上被精确应用。

当弹窗内容可能比最小吸附点更高时,请将其包裹在 ScrollView 中,以便溢出内容能够正确滚动。

BottomSheetSnapPointsExample.tsx
import { useState } from 'react'; import { Host, BottomSheet, Button, Column, ScrollView, Text } from '@expo/ui'; export default function BottomSheetSnapPointsExample() { const [isPresented, setIsPresented] = useState(false); return ( <Host style={{ flex: 1 }}> <Button label="打开" onPress={() => setIsPresented(true)} /> <BottomSheet isPresented={isPresented} onDismiss={() => setIsPresented(false)} snapPoints={['half', 'full']}> <ScrollView> <Column spacing={12}> <Text textStyle={{ fontSize: 20, fontWeight: '700' }}>半屏 / 全屏弹窗</Text> <Text>在半屏和全屏高度之间拖动弹窗。</Text> </Column> </ScrollView> </BottomSheet> </Host> ); }

API

import { BottomSheet } from '@expo/ui';

Component

BottomSheet

Type: React.Element<BottomSheetProps>

A modal sheet that slides up from the bottom of the screen.

Props for the BottomSheet component, a modal sheet that slides up from the bottom of the screen.

BottomSheetProps

children

Optional • Type: ReactNode

Content to render inside the bottom sheet.

isPresented

Type: boolean

Whether the bottom sheet is currently visible.

modifiers

Optional • Type: ModifierConfig[]

Platform-specific modifier escape hatch. Pass an array of modifier configs from @expo/ui/swift-ui/modifiers or @expo/ui/jetpack-compose/modifiers.

onDismiss

Type: () => void

Called when the bottom sheet is dismissed by the user (e.g. swiping down or tapping the overlay).

showDragIndicator

Optional • Type: boolean • Default: true

Whether to show a drag indicator at the top of the sheet.

snapPoints

Optional • Type: SnapPoint[]

Heights the sheet can rest at. When omitted, the sheet auto-sizes to its content. See SnapPoint for the supported values.

Example

``['half', 'full'] — draggable between half and full

Example

``['full'] — always full height

testID

Optional • Type: string

Identifier used to locate the component in end-to-end tests.

Types

SnapPoint

A snap point describing one of the heights a BottomSheet can rest at.

  • 'half' — Approximately half-screen.
  • 'full' — Fully expanded.
  • { fraction } — A fraction of the screen height (0–1). iOS / web only.
  • { height } — A fixed pixel height. iOS / web only.

On Android, { fraction } and { height } snap to the nearest of 'half' / 'full'. See the component docs for platform behavior notes.

Type: 'half' or 'full' or object shaped as below:

PropertyTypeDescription
fractionnumber
-

Or object shaped as below:

PropertyTypeDescription
heightnumber
-