Skip to content

Instantly share code, notes, and snippets.

@MrToph
Last active May 5, 2020 15:29
Show Gist options
  • Save MrToph/1bcd0daa99035e63f427dd2b08256bd9 to your computer and use it in GitHub Desktop.
Save MrToph/1bcd0daa99035e63f427dd2b08256bd9 to your computer and use it in GitHub Desktop.
import React, { Component, PropTypes } from 'react'
import { View, UIManager, findNodeHandle, TouchableOpacity } from 'react-native'
import Icon from 'react-native-vector-icons/MaterialIcons'
const ICON_SIZE = 24
export default class PopupMenu extends Component {
static propTypes = {
// array of strings, will be list items of Menu
actions: PropTypes.arrayOf(PropTypes.string).isRequired,
onPress: PropTypes.func.isRequired
}
constructor (props) {
super(props)
this.state = {
icon: null
}
}
onError () {
console.log('Popup Error')
}
onPress = () => {
if (this.state.icon) {
UIManager.showPopupMenu(
findNodeHandle(this.state.icon),
this.props.actions,
this.onError,
this.props.onPress
)
}
}
render () {
return (
<View>
<TouchableOpacity onPress={this.onPress}>
<Icon
name='more-vert'
size={ICON_SIZE}
color={'grey'}
ref={this.onRef} />
</TouchableOpacity>
</View>
)
}
onRef = icon => {
if (!this.state.icon) {
this.setState({icon})
}
}
}
@kabitacode
Copy link

Can you add component views in options?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment