npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@brnho/react-native-context-menu

v1.0.4

Published

React Native implementation of iOS context menu - replicates the full set of animations (bounce, haptics, background shrink and blur, etc.), and provides extensive support for customization of menu items and animations.

Downloads

31

Readme

react-native-context-menu

React Native implementation of iOS context menu - replicates the full set of animations (bounce, haptics, background shrink and blur, etc.), and provides extensive support for customization of menu items and animations.

https://user-images.githubusercontent.com/17365107/211397217-63fa501c-481e-4434-9e52-1e8b491f21c9.mov

Setup

The library is available on npm. Install with npm i @brnho/react-native-context-menu or yarn add @brnho/react-native-context-menu.

Usage

First, wrap the root view of your app with ContextMenuProvider. Then, wrap the component that you want to provide a context menu to with ContextMenuContainer.

import { ContextMenuProvider, ContextMenuContainer } from "@brnho/react-native-context-menu";

export default function App() {
  return (
    <ContextMenuProvider>
      <View style={styles.container}>
        <ContextMenuContainer menuItems={menuItems}>
          <MyExampleComponent />
        </ContextMenuContainer
      </View>
    </ContextMenuProvider>
  );
}

You can customize the context menu via the menuItems prop of ContextMenuContainer. For example:

const menuItems = [
  { text: "Action", isTitle: true },
  {
    text: "Edit",
    icon: {
      type: "Feather",
      name: "edit",
      size: 18,
    },
    onPress: () => {
      alert("Edit pressed");
    },
  },
  {
    text: "Delete",
    icon: {
      type: "Feather",
      name: "trash",
      size: 18,
    },
    withSeparator: true,
    isDestructive: true,
    onPress: () => {
      alert("Delete pressed");
    },
  },
];

Tips/Caveats

  • For the positioning of the animations to work properly, do not apply any margins to the target component. Instead, apply margins directly to the ContextMenuContainer wrapper via the margin props (see Props section).

  • If your target component has a nonzero border radius, then apply the same amount of border radius to ContextMenuContainer via the borderRadius prop. This ensures that ContextMenuContainer precisely covers the component.

  • If you are applying a context menu to an item in a Flatlist, to prevent the user from being able to scroll the list during a long press event, set the setScrollEnabled prop of ContextMenuProvider equal to a state function. For more details, refer to the following example:

export default function App() {
  const [scrollEnabled, setScrollEnabled] = useState(true);
  return (
    <ContextMenuProvider setScrollEnabled={setScrollEnabled}>
      <View style={styles.container}>
        <FlatList
          scrollEnabled={scrollEnabled}
          data={data}
          renderItem={({ item }) => <ListItem item={item} />}
          keyExtractor={(_, index) => index}
        />
      </View>
    </ContextMenuProvider>
  );
}

Props

ContextMenuProvider Props

| Name | Type | Default | Required | Description | | -- | -- | -- | -- | -- | | setScrollEnabled | function | null | No | Function executed on long press to prevent user from being able to scroll | | SCREEN_SHRINK_FACTOR | number | 0.97 | No | Amount by which to shrink the background when the component pops out | | EXPAND_FACTOR | number | 1.05 | No | Amount by which to expand the component when it pops out | | FADE_SPEED | number | 200 | No | Animation speed in MS of the component "un-popping" | | APPEAR_SPEED | number | 200 | No | Animation speed in MS of the component popping out | | BLUR_INTENSITY | number | 30 | No | Degree to which the background is blurred when the component pops out (value is in range [0, 100]) | | MENU_ITEM_HEIGHT | number | 40 | No | Height of a single context menu item | | DIVIDER_HEIGHT | number | 1 | No | Height of the dividers separating context menu items | | MENU_WIDTH | number | 200 | No | Width of a single context menu item | | MENU_MARGIN | number | 7 | No | Margin between the component and the context menu |

ContextMenuContainer Props

| Name | Type | Required | Description | | -- | -- | -- | -- | | marginTop | number | No | Amount of margin to apply to the top of the component | | marginRight | number | No | Amount of margin to apply to the right of the component | | marginBottom | number | No | Amount of margin to apply to the bottom of the component | | marginLeft | number | No | Amount of margin to apply to the left of the component | | borderRadius | number | No | Radius of component corners | | menuItems | array | Yes | See below for additional details |

menuItems (See Usage section for an example)

menuItems is an array of objects, each representing an item of the context menu. The fields of a menu item object are as follows:

| Name | Type | Required | Description | | -- | -- | -- | -- | | text | string | Yes | Menu item text | | icon | object | No | See below for additional details| | onPress | function | No | Function to be called when the menu item is pressed | | isTitle | string | No | Applies different styling to a menu item designated as the title | | isDestructive | boolean | No | Colors text and icon of item in red |

The icon prop is a object with the following fields:

| Name | Type | Required | Description | | -- | -- | -- | -- | | type | string | Yes | Icon family (must be one of 'AntDesign', 'Entypo', 'Feather', 'FontAwesome5', 'Ionicons', 'MaterialIcons') | | name | string | Yes | Name of icon | | size | number | Yes | Size of icon |

(See https://icons.expo.fyi/ for a list of icon types and names)