Popup menu component for React Native
Go to file
Stanislav Miklik e24c49a568 test + demo for user defined menu options 2016-05-31 10:02:02 +02:00
__mocks__ unique native commponents mocks 2016-05-23 17:09:15 +02:00
__tests__ test + demo for user defined menu options 2016-05-31 10:02:02 +02:00
doc refined docu 2016-05-30 09:17:00 +02:00
examples test + demo for user defined menu options 2016-05-31 10:02:02 +02:00
src fix problem with possible multiple onOpen/onClose callbacks 2016-05-27 14:40:19 +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 linting rules for tests 2016-05-17 13:38:25 +02:00
.gitignore jest tests setup 2016-05-17 12:52:47 +02:00
.npmignore initial version 2016-05-16 16:54:39 +02:00
LICENSE Initial commit 2016-05-16 16:16:31 +02:00
README.md refined docu 2016-05-30 09:17:00 +02:00
android.demo.gif updated preview image 2016-05-20 13:08:37 +02:00
package.json release v 0.3 2016-05-30 09:54:01 +02:00

README.md

react-native-popup-menu

Popup menu component for React Native. It is inspired by react-native-menu component which has some limitations. Target platforms are both Android and iOS. The library is prepared for React Native 0.26.

Installation

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

Demo

Basic Usage

Uncontrolled example

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='Two' />
        <MenuOption value={3} disabled={true}>
          <Text style={{color: '#ccc'}}>Three</Text>
        </MenuOption>
      </MenuOptions>
    </Menu>
  </MenuContext>
);

Controlled example

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='Two' />
            <MenuOption value={3} disabled={true}>
              <Text style={{color: '#ccc'}}>Three</Text>
            </MenuOption>
          </MenuOptions>
        </Menu>
      </MenuContext>
    );
  }

}

Documentation