🌐 Expo UI Menu matches the official SwiftUI Menu API and supports styling via the buttonStyle modifier. Menu opens on a single tap. For long-press interactions, use ContextMenu instead.
在使用 Mac 习惯用法(Xcode 的 为 Mac 优化界面)的 Mac Catalyst 构建中,SwiftUI 会将 Menu 渲染为 AppKit 下拉按钮:带边框的外观和一个下拉箭头取代了自定义的 label,而下拉自身的尺寸会使触发器变宽。结合 menuStyle('button')、buttonStyle('plain') 和 menuIndicator('hidden') 可以让标签成为整个触发器。
🌐 On a Mac Catalyst build that uses the Mac idiom (Xcode's Optimize Interface for Mac), SwiftUI renders Menu as an AppKit pull-down button: bordered chrome and a disclosure chevron replace a custom label, and the pull-down's own sizing widens the trigger. Combine menuStyle('button'), buttonStyle('plain') and menuIndicator('hidden') to keep the label as the entire trigger.
在菜单中使用ControlGroup来渲染一行水平的图标按钮,类似于 Apple Music 或 Safari 菜单中的快速操作行。
🌐 Use a ControlGroup inside a menu to render a horizontal row of icon buttons, similar to the quick actions row in Apple Music or Safari menus.
MenuWithControlGroupExample.tsx
import{Host,Menu,ControlGroup,Button,Section,Divider,}from'@expo/ui/swift-ui';exportdefaultfunctionMenuWithControlGroupExample(){return(<Hoststyle={{ flex:1}}><Menulabel="Song Options"systemImage="ellipsis.circle"><ControlGroup><ButtonsystemImage="plus"label="Add"onPress={()=>console.log('Add')}/><ButtonsystemImage="star"label="Favorite"onPress={()=>console.log('Favorite')}/><ButtonsystemImage="square.and.arrow.up"label="Share"onPress={()=>console.log('Share')}/></ControlGroup><Section><ButtonsystemImage="text.badge.plus"label="Add to a playlist"onPress={()=>console.log('Add to playlist')}/><ButtonsystemImage="antenna.radiowaves.left.and.right"label="Create station"onPress={()=>console.log('Create station')}/></Section><Divider/><ButtonsystemImage="hand.thumbsdown"label="Suggest less"onPress={()=>console.log('Suggest less')}/></Menu></Host>);}
🌐 Use the disabled(true) modifier on a menu Button to render it greyed-out and non-interactive. The button still appears in the menu but won't fire onPress.
DisabledMenuItemExample.tsx
import{Host,Menu,Button}from'@expo/ui/swift-ui';import{ disabled }from'@expo/ui/swift-ui/modifiers';exportdefaultfunctionDisabledMenuItemExample(){return(<Hoststyle={{ flex:1}}><Menulabel="Options"><Buttonlabel="Available"onPress={()=>console.log('Available')}/><Buttonlabel="Locked"systemImage="lock"modifiers={[disabled(true)]}onPress={()=>console.log('This never fires')}/></Menu></Host>);}
可选择的项目(勾选项)
🌐 Selectable items (checkmarks)
一个 SwiftUI Toggle 放在 Menu 里面时,会自动渲染成一行,并显示它的 SF 符号(当 systemImage 被设置时),而且当 isOn 是 true 时,该符号前会显示一个勾选标记。使用这个模式,而不是自己去发明一个自定义的勾选项。
🌐 A SwiftUI Toggle placed inside a Menu automatically renders as a row with its SF Symbol (when systemImage is set) and a checkmark before that symbol when isOn is true. Use this pattern instead of inventing a custom checkmark item.
🌐 Use the labelStyle('iconOnly') modifier to display only the icon without the label text. The label prop should still be provided for accessibility purposes.