Use native context menu functionality from React Native. On iOS 13+ this uses UIMenu
functionality, and on Android it uses a PopUpMenu
.
On iOS 12 and below, nothing happens. You may wish to do a Platform.OS === 'ios' && parseInt(Platform.Version, 10) <= 12
check, and add your own onLongPress
handler.
$ npm install react-native-context-menu-view --save
cd ios/
pod install
import ContextMenu from "react-native-context-menu-view";
const Example = () => {
return (
<ContextMenu
previewController={'yourRNViewClass'}
actions={[{ title: "Title 1" }, { title: "Title 2" }]}
onPress={(e) => {
console.warn(
`Pressed ${e.nativeEvent.name} at index ${e.nativeEvent.index}`
);
}}
>
<View style={styles.yourOwnStyles} />
</ContextMenu>
);
};
See example/
for basic usage.
Optional. The title above the popup menu.
Optional. The name of the React Native view you want to display as a custom preview
Array of { title: string, systemIcon?: string, destructive?: boolean, disabled?: boolean }
.
System icon refers to an icon name within SF Symbols.
Destructive items are rendered in red on iOS, and unchanged on Android.
Optional. When the popup is opened and the user picks an option. Called with { nativeEvent: { index, name } }
. Will return "preview" if the preview view was touched.
Optional. When the popop is opened and the user cancels.