2.5.1 β€’ Published 2 months ago

react-native-ios-context-menu v2.5.1

Weekly downloads
73
License
MIT
Repository
github
Last release
2 months ago

react-native-ios-context-menu

🚧⚠️ Documentation WIP ⚠️🚧

πŸ“ Note: See TODO.md for progress.

  • The documentation is incomplete (some parts/sections are marked as TBA i.e. "to be added").
  • Some of the links in the documentation are broken (i.e. the URL points to PLACE_HOLDER_LINK).
  • Some of the gifs/images are old, or broken.
  • For now, please see the Usage And Examples section, and Showcase, Tests and Demos section for information on how to use this library.

Notice
πŸ“ Note #1: Staring on version 2.x, this library now uses expo-modules, and contains a peer dependency to react-native-ios-utilites.
πŸ“ Note #2: The documentation + examples are currently being rewritten.πŸ’… README-old.md β€” The old version of the documentation (archived).πŸ’– example/src/examples β€” The typescript rewrite of the examples (WIP).

Versions

Library VersionCompatibility
2.1+Uses Expo-ModulesDepends on react-native-ios-utilities@4.xDepends on ContextMenuAuxiliaryPreviewiOS 13+Xcode 15+
2.0.xUses Expo-ModulesDepends on react-native-ios-utilities@4.xiOS 13+Xcode 15+
1.6.2iOS 10 to iOS 15Xcode 12+
1.4iOS 10 to iOS 15Xcode 13+
1.3 and BelowiOS 10 to 14Xcode 12+

πŸ“ Note: Supports projects targeting iOS 10 but will use the action sheet fallback when running on iOS 12 and older.

Table of Contents

Sections and Links
A. Introductionβ€’ Gifs and Demosβ€’ Features
B. Installationβ€’ Expoβ€’ Troubleshooting--β€’ Xcode Build Error (Swift)--β€’ Xcode Build Error (Undefined symbol)
C. Basic Usage
D. Documentationβ€’ D.1. Components--β€’ ContextMenuView Component----β€’ Props----β€’ Event Props----β€’ Properties/Methods----β€’ Experimental - Aux. Preview--β€’ ContextMenuButton Component----β€’ Props----β€’ Event Props----β€’ Properties/Methodsβ€’ D.2. Context--β€’ ContextMenuButtonContext--β€’ ContextMenuButtonContextβ€’ D.3. Hooks--β€’ useMenuContext--β€’ useMenuButtonContextβ€’ D.4. Objects and Types--β€’ MenuConfig.ts----β€’ Object Type: MenuConfig----β€’ Object Type: MenuActionConfig----β€’ Object Type: DeferredMenuElementConfig----β€’ String Union: MenuAttributes----β€’ String Union: MenuState----β€’ String Union: UIMenuOptions--β€’ MenuPreviewConfig.ts----β€’ Object Type: MenuPreviewConfig----β€’ String Union: ContextMenuInteractionCommitStyle----β€’ String Union: MenuPreviewSize----β€’ String Union: MenuPreviewType--β€’ MenuAuxiliaryPreviewConfig.ts----β€’ Object Type: MenuAuxiliaryPreviewConfig----β€’ String Union Type: MenuAuxiliaryPreviewAnchorPosition----β€’ String Union Type: MenuAuxiliaryPreviewHorizontalAlignment----β€’ String Union Type: UIViewAnimateOptions----β€’ Object Type: UIViewAnimateConfig----β€’ Object Type: MenuAuxiliaryPreviewBaseTransitionConfig----β€’ Object Union Type: MenuAuxiliaryPreviewTransitionConfig----β€’ Mixed Union Type: MenuAuxiliaryPreviewTransitionEntranceDelay--β€’ MenuIconConfig.ts--β€’ ImageItemConfig.ts----β€’ Object Type: ImageItemConfig----β€’ Object Type: ImageResolvedAssetSource----β€’ Object Type: ImageRectConfig----β€’ Object Type: ImageGradientConfig----β€’ Object Type: ImageSystemConfig--β€’ Undocumented Typesβ€’ D.5. Constants
E. Usage And ExamplesπŸ“ Note: See Example Index section for a complete list of examples + their descriptions.
F. Showcase, Tests and Demos
G. Meta
H. Licence

TOC: Examples Index

Examples
πŸ“Œ ContextMenuView Example 01πŸ’­ Summary: A basic context menu that has 3 menu action items.
πŸ“Œ ContextMenuView Example 02πŸ’­ Summary: Icon Example β€” A basic context menu that has 3 menu action items, each with a different "SF Symbols" icon. This examples shows how to add a system icon in the context menu action.
πŸ“Œ ContextMenuView Example 03πŸ’­ Summary: Nested Menu β€” This example shows a context menu that has a submenu item inside its list of menu actions.
πŸ“Œ ContextMenuView Example 04πŸ’­ Summary: Menu Attributes β€” This example context menu showcases the MenuActionConfig.menuAttributes property.
πŸ“Œ ContextMenuView Example 05πŸ’­ Summary: Nested Menu + Menu Attributes β€” A context menu that has a in-line submenu.
πŸ“Œ ContextMenuView Example 06πŸ’­ Summary: Menu Options β€” A context menu that has a destructive submenu.
πŸ“Œ ContextMenuView Example 07πŸ’­ Summary: Menu Options β€” A context menu that set to be both "destructive" and "display in-line".
πŸ“Œ ContextMenuView Example 08πŸ’­ Summary: Menu State β€” A context menu with 3 actions that has 'on', 'off', and 'mixed' menuState.
πŸ“Œ ContextMenuView Example 09πŸ’­ Summary: Events β€” An example for the onPressMenuItem event prop.
πŸ“Œ ContextMenuView Example 10πŸ’­ Summary: Dynamic Menu β€” An example showing how to dynamically update the context menu while it's visible. In this example, the menu action changes every time the counter increments every second.
πŸ“Œ ContextMenuView Example 11πŸ’­ Summary: Context Menu Previews β€” An example showing how to use a custom preview for the context menu.
πŸ“Œ ContextMenuView Example 12πŸ’­ Summary: Context Menu Previews β€” An example showing a custom context menu preview that dynamically changes its size due to its contents updating every second.
πŸ“Œ ContextMenuView Example 13πŸ’­ Summary: Menu Action β€” An example showing how to add a subtitle to menu action.
πŸ“Œ ContextMenuView Example 14πŸ’­ Summary: Context Menu Previews β€” An example that changes the exit transition of the context menu preview when its tapped using the preferredCommitStyle config.
πŸ“Œ ContextMenuView Example 15πŸ’­ Summary: Context Menu Previews β€” An example showing how to configure a context menu that uses targeted previews.
πŸ“Œ ContextMenuView Example 15-02πŸ’­ Summary: Context Menu Previews (Cont). β€” An example showing how to configure a context menu that uses targeted previews + WrapperView.
πŸ“Œ ContextMenuView Example 16πŸ’­ Summary: Icon Example β€” An example showing a context menu with an action that uses a 'IMAGE_ASSET' image for its icon.
πŸ“Œ ContextMenuView Example 17πŸ’­ Summary: Icon Example β€” An example showing a context menu with action items that have different colored icons.
πŸ“Œ ContextMenuView Example 18πŸ’­ Summary: Icon Example β€” An example showing a context menu with action items that has icons that uses local image assets imported via require(...).
πŸ“Œ ContextMenuView Example 19πŸ’­ Summary: Dynamic Menu β€” An example showing a context menu that has a loading indicator using deferred menu elements.
πŸ“Œ ContextMenuView Example 20πŸ’­ Summary: Dynamic Menu β€” An example showing a state-controlled context menu that shows a loading indicator using deferred menu elements.
πŸ“Œ ContextMenuView Example 21πŸ’­ Summary: Menu Element Size β€” TBA
πŸ“Œ ContextMenuView Example 22πŸ’­ Summary: Menu Element Size β€” TBA
πŸ“Œ ContextMenuView Example 23πŸ’­ Summary: Menu Element Size β€” TBA
πŸ“Œ ContextMenuView Example 24πŸ’­ Summary: Menu Attributes β€” keepsMenuPresented
πŸ“Œ ContextMenuView Example 25πŸ’­ Summary: Icon Example β€” Advanced customization (E.g. scale, weight, paletteColors, hierarchicalColor).
πŸ“Œ ContextMenuView Example 26πŸ’­ Summary: Icon Example β€” Network/Remote images as icons.
πŸ“Œ ContextMenuView Example 27πŸ’­ Summary: Icon Example β€” Network/Remote images as icons + fallback image.
πŸ“Œ ContextMenuView Example 28πŸ’­ Summary: Programmatically shows the context menu.
πŸ“Œ ContextMenuView Auxiliary Preview - Example 01πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 02πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 03πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 04πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 05πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 06πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 07πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 08πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 09πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 10πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 11πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 12πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 13πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 14πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 15πŸ’­ Summary: TBA
πŸ“Œ ContextMenuView Auxiliary Preview - Example 16πŸ’­ Summary: Programmatically shows the auxiliary preview as a popover (w/o showing the context menu).
πŸ“Œ ContextMenuButton Example 01πŸ’­ Summary: TBA
πŸ“Œ ContextMenuButton Example 02πŸ’­ Summary: TBA

A. Introduction

A react native component to use UIMenu on iOS 13 and later.

Gifs and Demos

πŸ“ Note: These gifs are from an older version of the library running on iOS 13 (see Usage And Examples section for updated example gifs).

ContextMenuView Examples, Left: Example 1, Example 2, and Right: Example 3, Example 4 Simple Example 1 to 4 Gifs

ContextMenuView examples, Left: Example 5, Example 6, and Right: Example 7, Example 8 Simple Example 5 to 8 Gifs

ContextMenuView example, Left: Example 9, and Right: Example 10 Simple Example 9 and 8 Gifs

ContextMenuView examples, Left: Example 11, Example 12, and Right: Example 13, Example 14 Simple Example 11 to 14 Gifs

ContextMenuView examples, Left: Example 15, Example 16, and Right: Example 17, Example 18 Simple Example 11 to 14 Gifs

ContextMenuView tests, Left: Test 1, and Right: Test 2 Context Menu View Test 1 and 2 Gifs

ContextMenuView tests, Left: Test 3, and Right: Test 4 Context Menu View Test 3 and 4 Gifs

ContextMenuView tests, Left: Test 5, and Right: Test 6 Context Menu View Test 5 and 6 Gifs

ContextMenuView tests, Left/Right: Test 7 Context Menu View 7 Gifs

ContextMenuView ActionSheetIOS fallback for simple example 1 to 9 Action Sheet Fallback for Simple Example 1 to 9 Gifs

ContextMenuView ActionSheetIOS fallback for context menu view test 1 to 6 Action Sheet Fallback for Context Menu View Test 1 to 6 Gifs

ContextMenuButton examples, Left: Example 1, and Right: Example 2 Simple Example 1 and 2 Gifs

Features

  • Support for creating menu actions and submenus (i.e. nested and in-line menus).
  • Support for customizing the menu icons (i.e. support for SF Symbols, require(image), and xcasset icons, icon tint, etc).
  • Extensive support for SF Symbols configuration (e.g. pointSize, weight, scale, hierarchicalColor, paletteColors).
  • Support for iOS 14 functionality (like the UIButton context menu, dynamically updating the menu while it's visible, etc).
  • Support for setting (almost) all of the native UIMenu and οΏΌUIAction properties (e.g. UIMenuElementState, MenuElementAtrributes, discoverabilityTitle, etc.)
  • Basic ActionSheetIOS menu fallback for iOS 12 and below.
  • Support for creating custom context menu previews (with support for dynamic or fixed preview sizes, setting the UIPreviewParameters, specifying a UITargetedPreview, etc).
  • Support for custom auxiliary previews (experimental).
  • Support for deferred context menu items.

B. Installation

# 1. install library + dependencies
npm install react-native-ios-utilities
npm install react-native-ios-context-menu

# 2. then run pod install (uses auto-linking)
cd ios && pod install

πŸ“ Note A: You might encounter some build errors since this library is written in swift, so there's some extra step involved to use this library (see table below for reference).

πŸ“ Note B: If you want to use an older or different version of this library, please refer to versions section's compatibility table.

Additional Steps
1️⃣ Add an empty swift file to your project
2️⃣ Update the project's "Library Search Paths" build settings

Installation (Experimental Version)

# 1. install library + dependencies
npm install react-native-ios-utilities@next
npm install react-native-ios-context-menu@next


# 2. then run pod install (uses auto-linking)
cd ios && pod install

Updating

This library has cocoapods dependency to ContextMenuAuxiliaryPreview, so you need to update it separately.

# A. Either update this specific pod...
pod update ContextMenuAuxiliaryPreview

# B. Or update all the pods
pod update

Expo

Versions and Dependencies

Library VersionDependencies + Versions
2.0.xreact-native-ios-utilities - 4.x
2.1.xreact-native-ios-utilities - 4.xContextMenuAuxiliaryPreview - 0.1.x
2.2.xreact-native-ios-utilities - 4.xContextMenuAuxiliaryPreview - 0.2.x

Troubleshooting

If you encounter any errors/bugs while using this library, or want a particular feature implemented, please create an issue! (my inbox is a mess, please feel free to tag me). ✨

Troubleshooting: Xcode Build Error (Swift)

πŸ“ Note: This library is written in swift. If you are having trouble building your app after installing this library, try adding an empty swift file to your project:

  1. Open up your ios/project.xcworkspace project
  2. On the project navigator panel (located on the right side of Xcode), right click on your project group (or another folder/group i.e the blue or yellow icons) and select the "New File..." option
  3. In the popup sheet, select "Swift" as the template and then click the "Next" button
  4. A "Save As" popup sheet should appear and then click "Create" (you can rename the file first if you want to)
  5. If Xcode asks you to create a "Objective-C Bridging Header" choose "Create Objective-C Bridging Header"

Troubleshooting: Xcode Build Error (Undefined symbol)

When installing this library on Xcode 12+, you'll get the following error in Xcode:

Xcode linking build error

Undefined symbol: (extension in UIKit):
__C.UIMenu.init(title: Swift.String, image: __C.UIImage?, identifier: __C.UIMenuIdentifier?, options: __C.UIMenuOptions, children: [__C.UIMenuElement]) -> __C.UIMenu

Undefined symbol: (extension in UIKit):
__C.UIAction.init(title: Swift.String, image: __C.UIImage?, identifier: __C.UIActionIdentifier?, discoverabilityTitle: Swift.String?, attributes: __C.UIMenuElementAttributes, state: __C.UIMenuElementState, handler: (__C.UIAction) -> ()) -> __C.UIAction

To fix this, see screenshot + follow the steps below:

Xcode - Remove library search paths

  1. Open your ios/project.xcworkspace project.
  2. In the project navigator panel (located on the right side of Xcode), select your project group (i.e. the item with the blueprint icon).
  3. The Xcode project editor should appear. In the left panel, under the "Project" section, select your project (if it isn't already selected).
  4. In the project section's top tab bar, select the "Build Settings" tab (also make sure the "All" and "Combined" tabs are selected).
  5. In the project navigator list, under the "Search Path" section, there should be a "Library Search Paths" setting (alternatively, you can search for "Library Search Paths" in the search bar).
  6. According to this issue comment, you can clear all the items listed in the "Library Search Paths" setting by selecting the items in the list, and pressing the "-" button in the popover.
    • TLDR: Xcode automatically manages this setting, and the RN template hardcodes it to use Swift 5.0.
    • Alternatively, you can change the entry "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" to "$(TOOLCHAIN_DIR)/usr/lib/swift-5.3/$(PLATFORM_NAME)" i.e. change swift-5.0 to swift-5.3, or whatever the newest version of swift that comes with your Xcode installation (to show the popup dialog, double click the value/item).
  7. If you haven't already, make sure to create an empty swift file. Then clean the build folder (the option is in the menu bar under: "Product" -> "Clean Build Folder") and try building your project again.
  8. If you are still having problems building the app, try the following and build your project again:
  • Try clearing out Xcode's derivedData directory: rm -rf ~/Library/Developer/Xcode/DerivedData/* (check out this gist for instructions on how to clean up Xcode)
  • Try clearing out the Cocoapods cache: rm -rf "${HOME}/Library/Caches/CocoaPods" (and then try running pod install again).

Xcode - Remove library search paths

Explanation: Some versions of the react-native template hard codes the swift library search paths to use swift 5.0 (which causes the linker to mismatch the swift system libraries bundled with your Xcode + iOS/Simulator installation).

Here are some related issues in the RN repo: Issue 30202 and Issue 29178.

C. Basic Usage

For more examples, check out the Usage And Examples section.

πŸ”— Full Example

import * as React from 'react';
import { StyleSheet, Text } from 'react-native';

import { ContextMenuView } from 'react-native-ios-context-menu';

export function BasicUsageExample01() {
  return (
    <ContextMenuView
      style={styles.container}
      menuConfig={{
        menuTitle: 'BasicUsageExample01',
        menuItems: [{
          actionKey  : 'key-01',
          actionTitle: 'Action #1',
        }, {
          actionKey  : 'key-02'   ,
          actionTitle: 'Action #2',
        }, {
          actionKey  : 'key-03'   ,
          actionTitle: 'Action #3',
        }],
      }}
    >
      <Text style={styles.text}>
        Press And Hold To Show Context Menu
      </Text>
    </ContextMenuView>
  );
};

const styles = StyleSheet.create({
  container: {
    margin: 10,
    padding: 10,
  },
  text: {
    fontSize: 16,
  },
});

D. Documentation

πŸ’‘ Tip: Most of the time, when a type or component is mentioned, you can click it to jump to that item in the README (or its declaration in the source code).

D.1. Components

ContextMenuView Component

ContextMenuView Component: Props
Prop Name and TypeDescription
βš›οΈ ViewPropsThis component supports all the standard props from a <View/> component.
πŸ”€ menuConfigβš›οΈ MenuConfigThis prop configures the context menu, along with what menu actions to show.This prop accepts a MenuConfig object. This object is used to configure various aspects of the context menu. Here are some relevant properties:1️⃣ MenuConfig.menuTitle: the context menu title (required) β€” if you don't want to show the menu title, pass in an empty string.2️⃣ MenuConfig.menuItems: the actions to show (e.g. the title, icons, subtitle, etc) β€” accepts either an array of MenuActionConfig or MenuConfig objects.3️⃣ MenuConfig.menuOptions: the attributes of the context menu (e.g. destructive) β€” accepts an array of UIMenuOptions string items, and any nested menus or submenus to show (see "Note A"). πŸ“ Note A: Passing a MenuConfig object inside of the MenuConfig.menuItems property will result in a nested context menu (i.e. a submenu).In this scenario, the MenuConfig.menuOptions and MenuConfig.icon can be used to configure the appearance of the submenu.For usage examples regarding nested menus, see Example 06.πŸ“ Note B: Passing a value of null (or undefined) to this prop will not disable the context menu. Instead, please use the isContextMenuEnabled prop to disable the context menu. πŸ“ Note C: You can put MenuConfig in state if you want to dynamically change the menu configuration (this will allow you to add/remove submenu items, or update the current menu options).If the context menu is currently visible, changing/updating the MenuConfig value passed to this prop will cause the context menu to change in real-time. This behavior is only supported on iOS 14+.πŸ“Œ Some example links to get you started:β€’ For basic usage examples regarding MenuConfig, see: Example 1,β€’ For examples on creating + configuring the menu action items (i.e MenuActionConfig), see: Example 2,β€’ For menu action attributes + menu state, and action subtitles, see: Example 4, Example 8, and Example 13,β€’ For examples regarding the usage of icons (i.e ImageItemConfig), see: Example 16, Example 17, and Example 18.
πŸ”€ previewConfigβš›οΈ MenuPreviewConfigConfigures the context menu's preview.If no configuration is provided then it will default to using the context menu component itself as the preview.πŸ“ Note: If you do not want to show a preview (i.e. only show the context menu itself), consider using a ContextMenuButton component instead.πŸ“Œ Some example links to get you started:β€’ For examples regarding the configuration of the context menu preview (e.g. custom previews), see: Example 11, Example 12, Example 14, and Example 15.
πŸ”€ shouldUseDiscoverabilityTitleAsFallbackValueForSubtitleβš›οΈ boolean✳️ Default: trueOn iOS 15+, the value passed to the MenuActionConfig.discoverabilityTitle property is no longer displayed as a subtitle under the menu action.Instead you need to set a different property called MenuActionConfig.subtitle.The discoverabilityTitle property is now used for the "discoverability heads-up display" (e.g when an app supports keyboard shortcuts, holding down the command key presents a list of shortcuts; the discoverabilityTitle is then used as the title for the shortcut).If this prop is set to true, it will then use the value passed on to the discoverabilityTitle value as the subtitle for the menu action, preserving the old behavior. In other words, this prop exists for backwards-compatibility reasons.πŸ“ Note: This prop is set to true by default; set this to false if you don't want this automatic behaviour to happen.
πŸ”€ shouldWaitForMenuToHideBeforeFiringOnPressMenuItemβš›οΈ boolean✳️ Default: trueIf set to true (which it is by default), the onPressMenuItem event will be triggered after the context menu has been hidden (i.e. after onMenuDidHide event is triggered).Set this to false if you want onPressMenuItem to trigger as soon as an item has been pressed in the context menu.πŸ“ Note: Layout updates while the context menu is transitioning from it's open to hidden state might cause layout flickering (e.g. Issue #43).
πŸ”€ isContextMenuEnabledβš›οΈ boolean✳️ Default: trueEnables or disables the context menu. Useful if you want to temporarily disable the context menu.
πŸ”€ lazyPreviewβš›οΈ boolean✳️ Default: trueIf set to true (which it is by default), the custom context menu preview (i.e. the component returned from the ContextMenuView.renderPreview prop) and the auxiliary preview (i.e. the component returned from the ContextMenuView.renderAuxillaryPreview prop) are only mounted/rendered when the context menu is visible.Set this to false if you want the preview content to be always mounted.
πŸ”€ shouldEnableAggressiveCleanupβš›οΈ boolean✳️ Default: trueDeprecated. This prop no longer does anything (see shouldCleanupOnComponentWillUnmountForMenuPreview, and shouldCleanupOnComponentWillUnmountForAuxPreview).
πŸ”€ useActionSheetFallbackβš›οΈ boolean✳️ Default: trueContext menus are only supported on iOS 13+ (i.e context menus are not supported on iOS 12, and below).On iOS 12 and below, a long press on a ContextMenuView will show a ActionSheetIOS menu based on the current menuConfig prop. If you want to disable this behavior, set this prop to false.πŸ“ Note: Default value is false on iOS 13+, and true on iOS 12 and below.
πŸ”€ renderPreviewβš›οΈ () => React.ReactElementThis prop is a "render" prop, i.e it accepts a function that returns a react component.The returned component will displayed in the context menu preview.
πŸ”€ isAuxiliaryPreviewEnabledβš›οΈ boolean✳️ Default: false⚠️ Experimental: Please see Auxiliary Preview section.TBA
πŸ”€ auxiliaryPreviewConfigβš›οΈ MenuAuxiliaryPreviewConfig⚠️ Experimental: Please see Auxiliary Preview section.TBA
πŸ”€ renderAuxillaryPreviewβš›οΈ () => React.ReactElement⚠️ Experimental: Please see Auxiliary Preview section.TBA
πŸ”€ internalCleanupModeβš›οΈ RNICleanupMode✳️ Default: automaticInternally, a clean up routine is triggered whenever a component is unmounted.However, if the clean up routine is triggered too early, this will lead to the context menu component disappearing (E.g. issue #34).If you are experiencing this issue, you can disable the clean up routine from triggering altogether by setting this prop to disabled.Additionally, you can also try setting this prop to either to viewController, didMoveToWindowNil, or reactComponentWillUnmount.viewController mode will trigger the clean up routine via the UIViewController.viewWillDisappear lifecycle method, and didMoveToWindowNil will trigger the cleanup routine during the UIView.didMoveToWindow lifecycle method, while the reactComponentWillUnmount mode on the other hand, will trigger the clean up routine via the componentWillUnmount react lifecycle event.
πŸ”€ shouldCleanupOnComponentWillUnmountForMenuPreviewβš›οΈ boolean✳️ Default: falseIf set to true, the custom preview is immediately freed from memory once the context menu is closed.πŸ“ Note: For the immediately cleanup to take effect, the lazyPreview prop also needs to be enabled.
πŸ”€ shouldCleanupOnComponentWillUnmountForAuxPreviewβš›οΈ boolean✳️ Default: falseIf set to true, the aux. preview is immediately freed from memory once the context menu is closed.πŸ“ Note: For the immediately cleanup to take effect, the lazyPreview prop also needs to be enabled.

ContextMenuView Component: Event Props
Prop Name and TypeDescription
πŸ”€ onMenuWillShowβš›οΈ OnMenuWillShowEventEvent that gets called before the context menu is shown, i.e this event is immediately invoked when the menu is about to become visible.
πŸ”€ onMenuDidShowβš›οΈ OnMenuDidShowEventEvent that gets called after the context menu is shown, i.e this event is invoked after the menu entrance animation is finished.
πŸ”€ onMenuWillHideβš›οΈ OnMenuWillHideEventEvent that gets called before the context menu is hidden, i.e this event is immediately invoked when the menu is about to become hidden.
πŸ”€ onMenuDidHideβš›οΈ OnMenuDidHideEventEvent that gets called after the context menu is hidden, i.e this event is invoked after the menu exit animation is finished.
πŸ”€ onMenuWillCancelβš›οΈ OnMenuWillCancelEventEvent that gets called when the menu is cancelled and about to be hidden, i.e this event is immediately invoked when the context menu interaction is cancelled.
πŸ”€ onMenuDidCancelβš›οΈ OnMenuDidCancelEventEvent that gets called when the menu is cancelled and hidden, i.e. this event is invoked when the context menu is cancelled, and the menu exit transition is finished.
πŸ”€ onPressMenuItemβš›οΈ OnPressMenuItemEventEvent that gets called when a menu action is pressed. You can identify which action was pressed via nativeEvent.actionKey property in the nativeEvent object. Check out Example 1, and Example 9 for examples regarding the onPressMenuItem event prop. πŸ“ Note: If shouldWaitForMenuToHideBeforeFiringOnPressMenuItem prop is set to true (which it is by default), then this event will fire after onMenuDidHide is triggered.
πŸ”€ onPressMenuPreviewβš›οΈ OnPressMenuPreviewEventEvent that gets called when the menu's preview is pressed.
πŸ”€ onMenuAuxiliaryPreviewWillShowβš›οΈ OnMenuAuxiliaryPreviewWillShowEvent⚠️ Experimental: Please see Auxiliary Preview section.TBA
πŸ”€ onMenuAuxiliaryPreviewDidShowβš›οΈ OnMenuAuxiliaryPreviewDidShowEvent⚠️ Experimental: Please see Auxiliary Preview section.TBA
πŸ”€ onMenuAuxiliaryPreviewDidShowβš›οΈ DeferredElementProvider i.e. (deferredID, completion)Β =>Β voidThis event gets called whenever a UIDeferredMenuElement needs to be loaded. A deferred menu element can be created via a DeferredMenuElementConfig object.A deferred menu is a context menu is basically a placeholder β€” i.e. it appears as a loading indicator in the context menu. When you pass in a DeferredMenuElementConfig object to MenuConfig.menuItems, it means you want to load and add additional menu items once the context menu is opened.This event will provide a completion callback β€” use this to provide the additional context menu items you want to load.πŸ“ Note A: Deferred menu elements only work on iOS 14+.πŸ“ Note B: You can dynamically update the context menu items without using the prop β€” the difference is that deferred menu items will show a placeholder loading indicator when the additional menu items haven't been loaded yet.πŸ“ Note C: It is possible to have multiple deferred menu elements (e.g. deferred elements can also provide deferred elements, and so on).Just be sure to use a unique deferredID so you can tell them apart.πŸ“Œ Example Usage:β€’ ContextMenuViewExample19.
ContextMenuView Component: Properties/Methods
Prop Name and TypeDescription
πŸ”€ dismissMenuβš›οΈ Promise<Void>Allows you to programmatically dismiss the context menu. Only available on iOS 14 and above.
πŸ”€ presentMenuβš›οΈ Promise<Void>Allows you to programmatically show the context menu.
πŸ”€ showAuxiliaryPreviewAsPopoverβš›οΈ Promise<Void>Allows you to programmatically show the auxiliary preview as a popover.
ContextMenuView Component: Experimental - Auxiliary Preview

The context menu auxiliary preview is an experimental feature, and is not officially part of UIKit's "Menu and Shortcuts" API.

This is just a feature that I've implemented myself and added to the library β€” as such official support is limited and might break in a future iOS version. Please use at your own risk.

ContextMenuButton Component

For basic usage, please see Example 1 section.

  • The ContextMenuButton component is almost the same as the ContextMenuView component (It supports the same kind of props and events).

  • The only difference between them is that the ContextMenuButton component does not have a preview, and it can be immediately shown when its tapped instead of having to do a long press. See Example 2 for more details.

  • Note that ContextMenuButton is only available on iOS 14 and above. On iOS 13, it will use a ContextMenuButton, and on iOS 12 and below, it will use the ActionSheetFallback module to present a ActionSheetIOS menu.

  • If you want to add additional touch events, you can wrap this component inside a button component (e.g. TouchableOpacity). * When wrapping this component inside a button, please make sure to set the useActionSheetFallback prop to false.

ContextMenuButton Component: Props
Prop Name and TypeDescription
βš›οΈ ViewPropsThis component supports all the standard props from a <View/> component.
πŸ”€ menuConfigβš›οΈ MenuConfigSame as ContextMenuView.menuConfig prop.
πŸ”€ isMenuPrimaryActionβš›οΈ booleanWhen set to true, the context menu will be shown when its tapped instead of a long press.
πŸ”€ shouldUseDiscoverabilityTitleAsFallbackValueForSubtitleβš›οΈ boolean✳️ Default: trueTBA / Not Implented
πŸ”€ enableContextMenuβš›οΈ boolean✳️ Default: trueSame as ContextMenuView.enableContextMenu prop.
πŸ”€ useActionSheetFallbackβš›οΈ boolean✳️ Default: trueSame as ContextMenuView.useActionSheetFallback prop.
ContextMenuButton Component: Event Props
Prop Name and TypeDescription
πŸ”€ onMenuWillShowβš›οΈ OnMenuWillShowEventSame as ContextMenuView.onMenuWillShow event.
πŸ”€ onMenuDidShowβš›οΈ OnMenuDidShowEventSame as ContextMenuView.onMenuDidShow event.
πŸ”€ onMenuWillHideβš›οΈ OnMenuWillHideEventSame as ContextMenuView.onMenuWillHide event.
πŸ”€ onMenuDidHideβš›οΈ OnMenuDidHideEventSame as ContextMenuView.onMenuDidHide event.
πŸ”€ onMenuWillCancelβš›οΈ OnMenuWillCancelEventSame as ContextMenuView.onMenuWillCancel event.
πŸ”€ onMenuDidCancelβš›οΈ OnMenuDidCancelEventSame as ContextMenuView.onMenuDidCancel event.
πŸ”€ onMenuWillCreateβš›οΈ OnMenuWillCreateEventSame as ContextMenuView.onMenuWillCreate event.
πŸ”€ onPressMenuItemβš›οΈ OnPressMenuItemEventSame as ContextMenuView.onPressMenuItem event.
ContextMenuButton Component: Properties/Methods
Prop Name and TypeDescription
πŸ”€ dismissMenuβš›οΈ Promise<Void>Same as ContextMenuView.dismissMenu method.

ActionSheetFallback Module

A module to show a ActionSheetIOS menu based on a MenuConfig object.

This module attempts to approximate UIMenu behavior using ActionSheetIOS, so it's very limited (i.e. it does not support menu/action icons, etc.), but it does support things like submenu's, destructive actions/menu's, inline submenu's, and hidden actions.

  • Import the module like this: import { ActionSheetFallback } from "react-native-ios-context-menu";

  • To present a οΏΌοΏΌActionSheetIOS menu, call const selectedAction = await ActionSheetFallback.show(menuConfig)

FunctionDescription
πŸ”€ show βš›οΈ (menuConfig: MenuConfig):Promise<MenuAction Β¦ null>This function accepts a MenuConfig object and returns the selected MenuAction object or null if cancelled.

D.2. Context

ContextMenuViewContext Context

TBA

PropertyDescription
πŸ”€ isMenuVisibleβš›οΈ booleanTBA
πŸ”€ getRefToContextMenuViewβš›οΈ ()Β =>Β ContextMenuViewπŸ“Œ ContextMenuViewTBA

ContextMenuButtonContext Context

TBA

PropertyDescription
πŸ”€ isMenuVisibleβš›οΈ booleanTBA
πŸ”€ getRefToContextMenuButtonβš›οΈ ()Β =>Β ContextMenuViewπŸ“Œ ContextMenuButtonTBA

D.3. Hooks

useMenuContext Hook

A hook to use the ContextMenuViewContext context.

TBA

useMenuButtonContext Hook

A hook to use the ContextMenuButtonContext context.

TBA

D.4. Objects and Types

MenuConfig.ts

Object Type: MenuConfig

A container for grouping related menu elements in an app menu or contextual menu.

An object that is used to create and configure a context menu. Internally, this object is used to create a UIMenu instance (see apple docs for more information).

Name and TypeDescription
πŸ”€ typeβš›οΈ string, i.e"menu"TBA
πŸ”€ menuTitleβš›οΈ stringTBAπŸ“ Note: If you don't want a menu title to appear for your context menu, just pass in an empty string to this property.
πŸ”€ menuSubtitleβš›οΈ stringTBAπŸ“ Note: Requires iOS 15+.
πŸ”€ menuOptionsβš›οΈ Array<UIMenuOptions>πŸ“Œ UIMenuOptionsTBA
πŸ”€ menuPreferredElementSizeβš›οΈ MenuElementSizeTBA
πŸ”€ menuItemsβš›οΈ MenuElementConfig[] i.e. MenuConfig Β¦ MenuActionConfigΒ¦ DeferredMenuElementConfigπŸ“Œ MenuConfigπŸ“Œ MenuActionConfigπŸ“Œ DeferredMenuElementConfigTBA
πŸ”€ iconβš›οΈ IconConfig ¦ ImageItemConfigπŸ“Œ IconConfig (deprecated)πŸ“Œ ImageItemConfigTBA
Object Type: MenuActionConfig

An object that is used to create a menu action item in the context menu. Internally, this object is used to create a UIAction instance (see apple docs for more information),

Name and TypeDescription
πŸ”€ typeβš›οΈ string, i.e "action"TBA
πŸ”€ Required: actionKeyβš›οΈ stringTBA
πŸ”€ Required: actionTitleβš›οΈ stringTBA
πŸ”€ actionSubtitleβš›οΈ stringTBA
πŸ”€ menuStateβš›οΈ MenuStateTBA
πŸ”€ menuAttributesβš›οΈ Array<MenuAttributes>πŸ“Œ MenuAtrributesTBA
πŸ”€ discoverabilityTitleβš›οΈ stringTBA
πŸ”€ iconβš›οΈ IconConfig Β¦ ImageItemConfigπŸ“Œ IconConfig (deprecated)πŸ“Œ ImageItemConfigTBA
Object Type: DeferredMenuElementConfig

An object that is used to create a deferred menu element. Internally, this object is used to create a UIDeferredMenuElement instance (see apple docs for more information),

Name and TypeDescription
πŸ”€ Required: typeβš›οΈ string i.e. deferred.TBA
πŸ”€ Required: deferredIDβš›οΈ stringTBA
πŸ”€: shouldCacheβš›οΈ booleanTBA
String Union: MenuAttributes

Attributes that determine the style of the menu element.

A union string type that maps to UIMenuElement.Attributes enum (see apple docs for more information).

TypeDescription
βš›οΈ hiddenTBA
βš›οΈ disabledTBA
βš›οΈ destructiveTBA
βš›οΈ keepsMenuPresentedTBA
String Union: MenuState

Constants that indicate the state of an action- or command-based menu element.

A union string type that maps to UIMenuElement.State enum (see apple docs for more information).

TypeDescription
βš›οΈ onTBA
βš›οΈ offTBA
βš›οΈ mixedTBA
String Union: UIMenuOptions

Options for configuring a menu's appearance.

A union string type that maps to UIMenu.Options option set (see apple docs for more information).

TypeDescription
βš›οΈ destructiveTBA
βš›οΈ displayInlineTBA
String Union: MenuElementSize

Constants that determine the size of an element in a menu.

A union string type that maps to UIMenu.ElementSize enum (see apple docs for more information).

TypeDescription
βš›οΈ smallTBA
βš›οΈ mediumTBA
βš›οΈ largeTBA

MenuPreviewConfig.ts

Object Type: MenuPreviewConfig
Name and TypeDescription
πŸ”€ previewTypeβš›οΈ MenuPreviewType✳️ Default: DEFAULTTBA
πŸ”€ previewSizeβš›οΈ MenuPreviewSize✳️ Default: INHERITTBA
πŸ”€ isResizeAnimatedβš›οΈ boolean✳️ Default: trueTBA
πŸ”€ borderRadiusβš›οΈ numberTBA
πŸ”€ backgroundColorβš›οΈ DynamicColor ¦ stringπŸ“Œ DynamicColorTBA
πŸ”€ previewSizeβš›οΈ ContextMenuInteractionCommitStyle✳️ Default: dismissTBA
πŸ”€ targetViewNodeβš›οΈ numberTBA
String Union: ContextMenuInteractionCommitStyle
Name and TypeDescription
βš›οΈ dismissTBA
βš›οΈ popTBA
String Union: MenuPreviewSize
Name and TypeDescription
βš›οΈ INHERITTBA
βš›οΈ STRETCHTBA
String Union: MenuPreviewType
Name and TypeDescription
βš›οΈ DEFAULTTBA
βš›οΈ CUSTOMTBA

MenuAuxiliaryPreviewConfig.ts

Object Type: MenuAuxiliaryPreviewConfig
Name and TypeDescription
πŸ”€ heightβš›οΈ numberTBA
πŸ”€ anchorPositionβš›οΈ MenuAuxiliaryPreviewAnchorPosition✳️ Default: automaticTBA
πŸ”€ alignmentHorizontalβš›οΈ MenuAuxiliaryPreviewHorizontalAlignment✳️ Default: stretchPreviewTBA
πŸ”€ marginPreviewβš›οΈ numberTBA
πŸ”€ marginAuxiliaryPreviewβš›οΈ numberTBA
πŸ”€ transitionConfigEntranceβš›οΈ MenuAuxiliaryPreviewTransitionConfigTBA
πŸ”€ transitionEntranceDelayβš›οΈ MenuAuxiliaryPreviewTransitionEntranceDelayTBA
String Union Type: MenuAuxiliaryPreviewAnchorPosition
Name and TypeDescription
βš›οΈ topTBA
βš›οΈ bottomTBA
βš›οΈ automaticTBA
String Union Type: MenuAuxiliaryPreviewHorizontalAlignment
Name and TypeDescription
βš›οΈ stretchScreenTBA
βš›οΈ stretchPreviewTBA
βš›οΈ previewLeadingTBA
βš›οΈ previewTrailingTBA
βš›οΈ previewCenterTBA
String Union Type: UIViewAnimateOptions
Name and TypeDescription
βš›οΈ curveEaseInTBA
βš›οΈ curveEaseOutTBA
βš›οΈ curveEaseInOutTBA
βš›οΈ curveLinearTBA
Object Type: UIViewAnimateConfig
Name and TypeDescription
πŸ”€ durationβš›οΈ numberTBA
πŸ”€ delayβš›οΈ numberTBA
πŸ”€ optionsβš›οΈ UIViewAnimateOptions[]TBA
Object Type: MenuAuxiliaryPreviewBaseTransitionConfig

This type is an object tagged union type, with the transition property being the tag that separates the unions.

The table below defines the possible valid values that can be assigned to the type property (the subsequent tables are the different possible unions).

Name and TypeDescription
πŸ”€ transitionβš›οΈ string i.e. 'none' Β¦ 'fade''slide' Β¦ 'zoom' Β¦ 'zoomAndSlide'TBA
Name and TypeDescription
πŸ”€ transitionβš›οΈ string i.e. noneTBA
Name and TypeDescription
πŸ”€ transitionβš›οΈ string i.e. fadeTBA
Name and TypeDescription
πŸ”€ transitionβš›οΈ string i.e. slideTBA
πŸ”€ slideOffsetβš›οΈ numberTBA
Name and TypeDescription
πŸ”€ transitionβš›οΈ string i.e. zoomTBA
πŸ”€ zoomOffsetβš›οΈ numberTBA
Name and TypeDescription
πŸ”€ transitionβš›οΈ string i.e. zoomAndSlideTBA
πŸ”€ slideOffsetβš›οΈ numberTBA
πŸ”€ zoomOffsetβš›οΈ numberTBA
Object Union Type: MenuAuxiliaryPreviewTransitionConfig

This type is a union between the UIViewAnimateConfig object type, and the MenuAuxiliaryPreviewBaseTransitionConfig object type.

export type MenuAuxiliaryPreviewTransitionConfig = 
  | UIViewAnimateConfig
  | MenuAuxiliaryPreviewBaseTransitionConfig;
Mixed Union Type: MenuAuxiliaryPreviewTransitionEntranceDelay.
Name and TypeDescription
βš›οΈ numberTBA
βš›οΈ RECOMMENDEDTBA
βš›οΈ AFTER_PREVIEWTBA

MenuIconConfig.ts

Object Type: IconConfig

This has been deprecated and will be removed in a future version. Use ImageItemConfig instead. For documentation regarding IconConfig, please see the documentation in the old README.

ImageItemConfig.ts

Object Type: ImageItemConfig

This type is an object tagged union type, with the type property being the tag that separates the unions. The table below defines the possible valid values that can be assigned to the type property.

Name and TypeDescription
πŸ”€ Required: typeβš›οΈ ImageItemConfigType string union, i.e. 'IMAGE_ASSET' Β¦ 'IMAGE_SYSTEM' Β¦ 'IMAGE_REQUIRE'Β¦ 'IMAGE_EMPTY' Β¦ 'IMAGE_RECT' Β¦ 'IMAGE_GRADIENT'Β¦ 'IMAGE_REMOTE_URL'TBA
ImageItemConfig: IMAGE_ASSET
Name and TypeDescription
πŸ”€ Required: typeβš›οΈ string i.e 'IMAGE_ASSET'TBAπŸ“Œ Maps to UIImage.init(named:) constructor in the apple docs.
πŸ”€ Required: imageValueβš›οΈ stringTBA
πŸ”€ imageOptions?βš›οΈ ImageOptionsTBA
ImageItemConfig: IMAGE_SYSTEM
Name and TypeDescription
πŸ”€ Required: typeβš›οΈ string i.e 'IMAGE_SYSTEM'TBAπŸ“Œ Maps to UIImage.init(systemName:withConfiguration:) constructor in the apple docs.
πŸ”€ Required: imageValueβš›οΈ ImageSystemConfigTBAπŸ“Œ Maps to the withConfiguration argument label in the UIImage.init(systemName:withConfiguration:) constructor in the apple docs.
imageOptionsβš›οΈ ImageOptionsTBA
πŸ”€ imageLoadingConfigβš›οΈ ImageLoadingConfigTBA
ImageItemConfig: IMAGE_EMPTY
Name and TypeDescription
πŸ”€ Required: typeβš›οΈ string i.e 'IMAGE_EMPTY'TBA
ImageItemConfig: IMAGE_RECT
Name and TypeDescription
πŸ”€ Required: typeβš›οΈ string i.e 'IMAGE_RECT'TBAπŸ“ Note: Programmatically creates an image using UIGraphicsImageRenderer.
πŸ”€ Required: imageValueβš›οΈ ImageRectConfigTBA
ImageItemConfig: IMAGE_GRADIENT
Name and TypeDescription
πŸ”€ Required: typeβš›οΈ string i.e 'IMAGE_GRADIENT'TBAπŸ“ Note: Programmatically creates an image using UIGraphicsImageRenderer.
πŸ”€ imageValueβš›οΈ ImageGradientConfigTBA
imageOptionsβš›οΈ ImageOptionsTBA
ImageItemConfig: IMAGE_REMOTE_URL
Name and TypeDescription

| πŸ”€ **Required

2.5.1

2 months ago

2.5.0

2 months ago

2.5.0-3

2 months ago

2.5.0-4

2 months ago

2.4.4

2 months ago

2.5.0-2

3 months ago

2.4.3

3 months ago

2.4.2

3 months ago

2.5.0-1

3 months ago

2.5.0-0

3 months ago

2.4.1

3 months ago

2.4.0

3 months ago

2.3.2

4 months ago

2.3.1

4 months ago

2.2.1

6 months ago

2.0.3

7 months ago

2.0.0-6

7 months ago

2.2.0

6 months ago

2.0.2

7 months ago

2.0.0-5

7 months ago

2.0.5

7 months ago

2.0.0-4

7 months ago

2.0.4

7 months ago

2.0.0-3

7 months ago

2.0.0-2

7 months ago

2.0.0-1

7 months ago

2.0.0-0

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

2.3.0

6 months ago

2.1.0

6 months ago

1.15.3

1 year ago

1.15.2

1 year ago

1.15.0

2 years ago

1.15.1

2 years ago

1.12.3

2 years ago

1.14.0

2 years ago

1.12.2

2 years ago

1.13.0

2 years ago

1.12.1

2 years ago

1.12.0

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.6

2 years ago

1.7.5

2 years ago

1.9.2

2 years ago

1.11.0

2 years ago

1.10.1

2 years ago

1.10.0

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.1-0

2 years ago

1.7.4

2 years ago

1.6.2

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.0

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago