46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import type { MenuComponentProps } from "@expo/ui/community/menu"
|
|
import { Button, Host, Menu, RNHostView } from "@expo/ui/swift-ui"
|
|
import { disabled, menuOrder } from "@expo/ui/swift-ui/modifiers"
|
|
|
|
// SwiftUI's automatic order reverses menus that open upward in the player.
|
|
// Keep the same top-to-bottom order as the UIKit long-press menus.
|
|
export function MenuView({
|
|
actions,
|
|
children,
|
|
style,
|
|
testID,
|
|
onPressAction,
|
|
}: MenuComponentProps) {
|
|
return (
|
|
<Host matchContents style={style} testID={testID} ignoreSafeArea="all">
|
|
<Menu
|
|
modifiers={[menuOrder("fixed")]}
|
|
label={
|
|
<RNHostView matchContents>
|
|
<>{children}</>
|
|
</RNHostView>
|
|
}
|
|
>
|
|
{actions
|
|
.filter((action) => !action.attributes?.hidden)
|
|
.map((action) => (
|
|
<Button
|
|
key={action.id ?? action.title}
|
|
label={action.title}
|
|
systemImage={
|
|
typeof action.image === "string" ? action.image : undefined
|
|
}
|
|
role={action.attributes?.destructive ? "destructive" : undefined}
|
|
modifiers={[disabled(action.attributes?.disabled ?? false)]}
|
|
onPress={() =>
|
|
onPressAction?.({
|
|
nativeEvent: { event: action.id ?? action.title },
|
|
})
|
|
}
|
|
/>
|
|
))}
|
|
</Menu>
|
|
</Host>
|
|
)
|
|
}
|