[BREAKGLASS] Use native context menus in React Native
Go to file
2023-11-24 11:35:12 -05:00
android feat(android): support disable menu 2023-11-08 05:37:40 -05:00
assets Add gif screenshot 2020-04-28 11:45:15 -04:00
example Update Example to work correctly 2023-11-24 11:35:12 -05:00
ios Added selected option to actions (#92) 2023-07-31 09:21:49 -04:00
.gitattributes Initial commit of new module 2020-04-27 11:39:10 -04:00
.gitignore Initial commit of new module 2020-04-27 11:39:10 -04:00
.npmignore Bump version, publish to npm 2020-04-27 15:13:15 -04:00
index.d.ts feat(android): support disable menu 2023-11-08 05:37:40 -05:00
index.js Fix issue where custom preview would occupy space on screen even though it was not rendered (#84) 2023-06-17 23:13:34 -04:00
LICENSE Add LICENSE 2022-03-17 13:33:53 -04:00
package.json Bump version 2023-07-31 09:22:37 -04:00
react-native-context-menu-view.podspec Rename projects!!! 2020-04-27 15:09:43 -04:00
README.md feat(android): support disable menu 2023-11-08 05:37:40 -05:00

react-native-context-menu-view

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.

Getting started

$ npm install react-native-context-menu-view --save

Mostly automatic installation

cd ios/
pod install

Usage

import ContextMenu from "react-native-context-menu-view";

const Example = () => {
  return (
    <ContextMenu
      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.

Props

title

Optional. The title above the popup menu.

actions

Array of { title: string, subtitle?: string, systemIcon?: string, destructive?: boolean, selected?: boolean, disabled?: boolean, disabled?: boolean, inlineChildren?: boolean, actions?: Array<ContextMenuAction> }.

Subtitle is only available on iOS 15+.

System icon refers to an icon name within SF Symbols on IOS and Drawable name on Android.

Destructive items are rendered in red.

Selected items have a checkmark next to them on iOS, and unchanged on Android.

Nested menus are supported on iOS only and result in nested UIMenu which can be optionally displayed inline.

onPress

Optional. When the popup is opened and the user picks an option. Called with { nativeEvent: { index, indexPath, name } }. When a nested action is selected the top level parent index is used for the callback.

iOS only: to get the full path to the item, indexPath is an array of indices to reach the item. For a top-levle item, it'll be an array with a single index. For an item one deep, it'll be an array with two indicies.

onCancel

Optional. When the popop is opened and the user cancels.

previewBackgroundColor

Optional. The background color of the preview. This is displayed underneath your view. Set this to transparent (or another color) if the default causes issues.

dropdownMenuMode

Optional. When set to true, the context menu is triggered with a single tap instead of a long press, and a preview is not show and no blur occurs. Uses the iOS 14 Menu API and a simple tap listener on android.

disabled

Optional. Disable menu interaction.