🌐 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).
import{ useState }from'react';import{ useColorScheme }from'react-native';import{Host,Column,Button,BottomSheet,Text}from'@expo/ui';exportdefaultfunctionBottomSheetExample(){const[isPresented, setIsPresented]=useState(false);const colorScheme =useColorScheme();const ink ={ color: colorScheme ==='dark'?'#FFFFFF':'#000000'};return(<><HostmatchContents><Buttonlabel="Open sheet"onPress={()=>setIsPresented(true)}/></Host><BottomSheetisPresented={isPresented}onDismiss={()=>setIsPresented(false)}><Columnspacing={12}><TexttextStyle={{...ink, fontSize:18, fontWeight:'700'}}>Sheet contents</Text><TexttextStyle={ink}>Drag down or tap the overlay to dismiss.</Text><Buttonlabel="Close"onPress={()=>setIsPresented(false)}/></Column></BottomSheet></>);}
🌐 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.
BottomSheetSnapPointsExample.tsx
import{ useState }from'react';import{ useColorScheme }from'react-native';import{Host,BottomSheet,Button,Column,ScrollView,Text}from'@expo/ui';exportdefaultfunctionBottomSheetSnapPointsExample(){const[isPresented, setIsPresented]=useState(false);const colorScheme =useColorScheme();const ink ={ color: colorScheme ==='dark'?'#FFFFFF':'#000000'};return(<><HostmatchContents><Buttonlabel="Open"onPress={()=>setIsPresented(true)}/></Host><BottomSheetisPresented={isPresented}onDismiss={()=>setIsPresented(false)}snapPoints={['half','full']}><ScrollView><Columnspacing={12}><TexttextStyle={{...ink, fontSize:20, fontWeight:'700'}}>Half / full sheet</Text><TexttextStyle={ink}>Drag the sheet between half and full screen height.</Text></Column></ScrollView></BottomSheet></>);}
🌐 The bottom sheet supports a React Native list such as FlatList (or a high-performance list like FlashList or Legend List) as a child when wrapped in RNHostView. snapPoints sizes the sheet, and the list scrolls within that height. With nestedScrollEnabled, the list scrolls its own content first; once it reaches the top edge, the remaining drag moves the sheet.