I have given an idea of how you can go without using a library, you can define menutypes and use them as props to populate data as required, and other things will help as stated below.
export default Menu extends Component {
constructor(props) {
super(props)
this.state={
menuItems:[] //Define your menuitems as per props
}
}
renderItem({item,index}){
return <Text>{item.title}</Title>
}
render() {
var {menuItems} = this.state;
var {x,y,width} = this.props.dimension;
var height=120
var left=x-(width+5)
return (
<View style={[styles.menuContainer,{top:positionY,left,width,height}]}>
<FlatList
data={menuItems}
renderItem={this.renderItem.bind(this)}
keyExtractor={(item, index) => index.toString()}
/>
</View>
);
}
}
const styles=StyleSheet.create({
menuContainer:{
flex: 1,
backgroundColor:'white',
position:'absolute',
borderRadius:5,
shadowColor: '#000000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.2,
shadowRadius: 2,
elevation: 2,
}
});
Here is how you call the menu
<TouchableOpacity onPress={this.handleMenuOpen} ref={this.menuRef}>
<Text>{"Open Menu"}</Text>
</TouchableOpacity>
handleMenuOpen(){
this.menuRef.current.measure((fx, fy, width, height, px, py)=>{
//Use width, px and py to determine dimension of the menu
this.setState({dimension:{x:px,y:py,width}})
});
}
{
this.state.dimension?
<Menu dimension={this.state.dimension} onSelection={(menuItem)=>{
//Process your selection
}/>
:null
}
Cheers.