Popup menu component for React Native
Go to file
sodik 1d6c277340 fix #9: allow optional (null) menu options 2016-09-13 22:27:17 +02:00
__mocks__ slide in menu animation 2016-05-30 17:24:15 +02:00
__tests__ fix #9: allow optional (null) menu options 2016-09-13 22:27:17 +02:00
doc updated docu text 2016-07-27 16:08:20 +02:00
examples fix IOS example project after RN upgrade 2016-07-22 11:43:22 +02:00
src fix #9: allow optional (null) menu options 2016-09-13 22:27:17 +02:00
.babelrc initial version 2016-05-16 16:54:39 +02:00
.eslintignore linting rules for tests 2016-05-17 13:38:25 +02:00
.eslintrc different menu types 2016-05-30 16:24:43 +02:00
.gitignore jasmine reporters 2016-06-07 14:52:13 +02:00
.npmignore don't publish demo GIF to NPM 2016-06-23 13:35:31 +02:00
Jenkinsfile jenkins dev mail, refined pipeline 2016-06-08 13:50:39 +02:00
LICENSE Initial commit 2016-05-16 16:16:31 +02:00
README.md removed react native version 2016-08-18 13:28:24 +02:00
android.demo.gif slide-in menu - removed border radius 2016-05-31 14:37:08 +02:00
package.json release v 0.5.5 2016-08-30 11:45:47 +02:00
setup-jasmine-env.js jasmine reporters 2016-06-07 14:52:13 +02:00

README.md

react-native-popup-menu

Extensible popup menu component for React Native. It is inspired by react-native-menu component which has its limitations. Target platforms are both Android and iOS.

Installation

npm install react-native-popup-menu --save

Demo

![](./android.demo.gif)

Basic Usage

Context menu - uncontrolled

import React from 'react';
import { Text, AppRegistry } from 'react-native';
import Menu, {
  MenuContext,
  MenuOptions,
  MenuOption,
  MenuTrigger,
} from 'react-native-popup-menu';

export const App = () => (
  <MenuContext style={{flexDirection: 'column', padding: 30}}>
    <Text>Hello world!</Text>
    <Menu onSelect={value => alert(`Selected number: ${value}`)}>
      <MenuTrigger text='Select option' />
      <MenuOptions>
        <MenuOption value={1} text='One' />
        <MenuOption value={2}>
          <Text style={{color: 'red'}}>Two</Text>
        </MenuOption>
        <MenuOption value={3} disabled={true} text='Three' />
      </MenuOptions>
    </Menu>
  </MenuContext>
);

Context menu - controlled

export default class ControlledExample extends Component {

  constructor(props, ctx) {
    super(props, ctx);
    this.state = { opened: true };
  }

  onOptionSelect(value) {
    alert(`Selected number: ${value}`);
    this.setState({ opened: false });
  }

  render() {
    return (
      <MenuContext
        style={{flexDirection: 'column', padding: 30}}>
        <Text>Hello world!</Text>
        <Menu
          opened={this.state.opened}
          onBackdropPress={() => this.setState({ opened: false })}
          onSelect={value => this.onOptionSelect(value)}>
          <MenuTrigger
            onPress={() => this.setState({ opened: true })}
            text='Select option'/>
          <MenuOptions>
            <MenuOption value={1} text='One' />
            <MenuOption value={2}>
              <Text style={{color: 'red'}}>Two</Text>
            </MenuOption>
            <MenuOption value={3} disabled={true} text='Three' />
          </MenuOptions>
        </Menu>
      </MenuContext>
    );
  }

}

Slide-in menu

import { ..., renderers} from 'react-native-popup-menu';

// NOTE: `onSelect` handler can be also passed to `MenuOption`'s props
export const App = () => (
  <MenuContext style={{flexDirection: 'column', padding: 30}}>
    <Text>Hello world!</Text>
    <Menu renderer={renderers.SlideInMenu}>
      <MenuTrigger text='Select option' />
      <MenuOptions>
        <MenuOption onSelect={() => alert('option one')} text='One' />
        <MenuOption onSelect={() => alert('option two')} text='Two' />
      </MenuOptions>
    </Menu>
  </MenuContext>
);

Documentation