1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ReactNativeでAndroidのPopupMenuを出す

Posted at

PopupMenu はAndroidの標準UIの一つで、ActionBarなどで使われている。

これをReactNativeから利用するには

onOpenMenu = () => {
  UIManager.showPopupMenu(
    ReactNative.findNodeHandle(this._menu),
    ['Option 1', 'Option 2'],
    () => console.log('something went wrong with the popup menu'),
    (e, i) => console.log(`${e} : ${i}`)
  );
};

のようにする。

Screen Shot 2017-10-31 at 7.12.26 PM.png

出典: facebook/react-native#3004


import React from 'react';
import ReactNative, { StyleSheet, Text, TouchableNativeFeedback, TouchableHighlight, View, UIManager} from 'react-native';

export default class App extends React.Component {

  onOpenMenu = () => {
    UIManager.showPopupMenu(
      ReactNative.findNodeHandle(this._button),
      ['Option 1', 'Option 2'],
      () => console.log('something went wrong with the popup menu'),
      (e, i) => console.log(`${e} : ${i}`)
    );
  };

  render() {
    return (
      <View style={styles.container}>
        <TouchableNativeFeedback
          ref={e => {this._button = e;}}
          onPress={this.onOpenMenu}
          background={TouchableNativeFeedback.Ripple('#d0d0d0')}>
          <Text>Click me!</Text>
        </TouchableNativeFeedback>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?