ContextMenuWithPreviewExample.tsx import { View , Text as RNText } from 'react-native' ;
import { Host , ContextMenu , Button , Text } from '@expo/ui/swift-ui' ;
export default function ContextMenuWithPreviewExample ( ) {
return (
< Host matchContents >
< ContextMenu >
< ContextMenu.Items >
< Button label = " 编辑" onPress = { ( ) => console . log ( 'Edit' ) } />
< Button label = " 删除" role = " destructive" onPress = { ( ) => console . log ( 'Delete' ) } />
</ ContextMenu.Items >
< ContextMenu.Trigger >
< Text > 长按我 </ Text >
</ ContextMenu.Trigger >
< ContextMenu.Preview >
< View style = { { width: 200 , height: 100 , backgroundColor: '#f0f0f0' , padding: 16 } } >
< RNText > 预览内容 </ RNText >
</ View >
</ ContextMenu.Preview >
</ ContextMenu >
</ Host >
) ;
}
ContextMenuWithPickerExample.tsx import { useState } from 'react' ;
import { Host , ContextMenu , Button , Text , Picker } from '@expo/ui/swift-ui' ;
import { pickerStyle, tag } from '@expo/ui/swift-ui/modifiers' ;
export default function ContextMenuWithPickerExample ( ) {
const [ selectedIndex, setSelectedIndex] = useState < number | undefined > ( 0 ) ;
return (
< Host matchContents >
< ContextMenu >
< ContextMenu.Items >
< Button label = " 操作" onPress = { ( ) => console . log ( 'Action' ) } />
< Picker
label = " 大小"
modifiers = { [ pickerStyle ( 'menu' ) ] }
selection = { selectedIndex}
onSelectionChange = { setSelectedIndex} >
{ [ 'Small' , 'Medium' , 'Large' ] . map ( ( option, index) => (
< Text key = { index} modifiers = { [ tag ( index) ] } >
{ option}
</ Text >
) ) }
</ Picker >
</ ContextMenu.Items >
< ContextMenu.Trigger >
< Text > 长按我 </ Text >
</ ContextMenu.Trigger >
</ ContextMenu >
</ Host >
) ;
}
ContextMenuWithSectionsExample.tsx import { Host , ContextMenu , Button , Text , Section , Divider } from '@expo/ui/swift-ui' ;
export default function ContextMenuWithSectionsExample ( ) {
return (
< Host matchContents >
< ContextMenu >
< ContextMenu.Items >
< Section title = " 操作" >
< Button label = " 编辑" onPress = { ( ) => console . log ( 'Edit' ) } />
< Button label = " 复制" onPress = { ( ) => console . log ( 'Duplicate' ) } />
</ Section >
< Divider />
< Button label = " 删除" role = " destructive" onPress = { ( ) => console . log ( 'Delete' ) } />
</ ContextMenu.Items >
< ContextMenu.Trigger >
< Text > 长按我 </ Text >
</ ContextMenu.Trigger >
</ ContextMenu >
</ Host >
) ;
}
Type: React.Element < ContextMenuProps >
ContextMenu allows you to create a context menu, which can be used to provide additional options to the user.
Props of the ContextMenu component.
The contents of the context menu.
Should include ContextMenu.Trigger, ContextMenu.Items, and optionally ContextMenu.Preview.
Type: React.Element < {
children: ReactNode
} >
Items visible inside the context menu. It could be Section, Divider, Button, Toggle, Picker or even ContextMenu itself for nested menus. Remember to use components from the @expo/ui/swift-ui library.
Type: React.Element < {
children: ReactNode
} >
The component visible above the menu when it is opened.
Type: React.Element < {
children: ReactNode
} >
The component visible all the time that triggers the context menu when long-pressed.