This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 55).
DropdownMenu
一个用于显示下拉菜单的 Jetpack Compose DropdownMenu 组件。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Expo UI DropdownMenu 与官方 Jetpack Compose Menu API 保持一致,并在触发元素被按下时显示下拉菜单。
安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础下拉菜单
import { Host, DropdownMenu, Button, Text, Icon } from '@expo/ui/jetpack-compose'; import { useState } from 'react'; export default function BasicDropdownMenuExample() { const [isExpanded, setIsExpanded] = useState(false); return ( <Host matchContents> <DropdownMenu expanded={isExpanded} onDismissRequest={() => setIsExpanded(false)}> <DropdownMenu.Trigger> <Button variant="bordered" onClick={() => setIsExpanded(true)}> 显示菜单 </Button> </DropdownMenu.Trigger> <DropdownMenu.Items> <DropdownMenuItem onClick={() => { setIsExpanded(false); console.log('主页被按下'); }}> <DropdownMenuItem.Text> <Text>主页</Text> </DropdownMenuItem.Text> <DropdownMenuItem.LeadingIcon> <Icon source={homeIcon} size={24} /> </DropdownMenuItem.LeadingIcon> </DropdownMenuItem> </DropdownMenu.Items> </DropdownMenu> </Host> ); }
API
import { DropdownMenu } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<DropdownMenuProps>
Props of the DropdownMenu component.
ReactNodeThe contents of the submenu are used as an anchor for the dropdown menu. The children will be wrapped in a pressable element, which triggers opening of the dropdown menu.
() => voidCallback fired when the menu requests to be dismissed (e.g. tapping outside).
Must be provided when expanded is true to allow the menu to close.
Type: React.Element<DropdownMenuItemProps>
A dropdown menu item component that wraps Compose's DropdownMenuItem.
Should be used inside ContextMenu.Items.
Type: React.Element<{
children: ReactNode
}>
Container for items displayed in the dropdown menu.
Children should be DropdownMenuItem components or other native views.