This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
BottomSheet
一个从屏幕底部滑出的模态面板。
一个从屏幕底部滑出的模态面板。面板的可见性是可控的——通过 React 状态切换 isPresented,并可以从 onDismiss 关闭(当用户向下滑动或点击遮罩时调用)。
🌐 A modal sheet that slides up from the bottom of the screen. The sheet's visibility is controlled — toggle isPresented from React state and dismiss it from onDismiss (called when the user swipes down or taps the overlay).
安装
🌐 Installation
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
🌐 Usage
基本底部面板
🌐 Basic bottom sheet
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="Open sheet" onPress={() => setIsPresented(true)} /> <BottomSheet isPresented={isPresented} onDismiss={() => setIsPresented(false)}> <Column spacing={12}> <Text textStyle={{ fontSize: 18, fontWeight: '700' }}>Sheet contents</Text> <Text>Drag down or tap the overlay to dismiss.</Text> <Button label="Close" onPress={() => setIsPresented(false)} /> </Column> </BottomSheet> </Host> ); }
隐藏拖动指示器
🌐 Hiding the drag indicator
对于没有把手的板材,请传入 showDragIndicator={false}。
🌐 Pass showDragIndicator={false} for sheets without a handle.
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="Open" onPress={() => setIsPresented(true)} /> <BottomSheet isPresented={isPresented} onDismiss={() => setIsPresented(false)} showDragIndicator={false}> <Text>No drag handle.</Text> </BottomSheet> </Host> ); }
吸附点
🌐 Snap points
传入 snapPoints 以让用户在多个停靠高度之间拖动底部弹出层。你可以使用语义值 'half' 和 'full' 来实现跨平台一致性。{ fraction } 和 { height } 形式在 iOS 和网页上都能准确支持。
🌐 Pass snapPoints to let the user drag the sheet between multiple resting heights. You can use the semantic values 'half' and 'full' for cross-platform parity. The { fraction } and { height } forms are honored precisely on iOS and web.
当表格内容可能比最小吸附点更高时,将其封装在 ScrollView 中,以便溢出内容能够正确滚动。
🌐 When sheet content can be taller than the smallest snap point, wrap it in a ScrollView so the overflow scrolls correctly.
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="Open" onPress={() => setIsPresented(true)} /> <BottomSheet isPresented={isPresented} onDismiss={() => setIsPresented(false)} snapPoints={['half', 'full']}> <ScrollView> <Column spacing={12}> <Text textStyle={{ fontSize: 20, fontWeight: '700' }}>Half / full sheet</Text> <Text>Drag the sheet between half and full screen height.</Text> </Column> </ScrollView> </BottomSheet> </Host> ); }
在 Android 上,
{ fraction }和{ height }会吸附到最近的'half'/'full'—— 底层的ModalBottomSheet仅支持两个静止状态。部分状态只有在内容足够高以超过 Material 的部分阈值时才可见;如果你需要在短内容上显示半状态,请为内容指定明确的高度或填充可用空间。
应用接口
🌐 API
import { BottomSheet } from '@expo/ui';
Component
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.
ModifierConfig[]Platform-specific modifier escape hatch. Pass an array of modifier configs
from @expo/ui/swift-ui/modifiers or @expo/ui/jetpack-compose/modifiers.
() => voidCalled when the bottom sheet is dismissed by the user (e.g. swiping down or tapping the overlay).
boolean • Default: trueWhether to show a drag indicator at the top of the sheet.
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
Types
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:
| Property | Type | Description |
|---|---|---|
| fraction | number | - |
Or object shaped as below:
| Property | Type | Description |
|---|---|---|
| height | number | - |