react-native-material-menu icon indicating copy to clipboard operation
react-native-material-menu copied to clipboard

Better solution to open the Menu when 3 dots are clicked in React Native

Open sharathm89 opened this issue 6 years ago • 6 comments

I am able to open menu when 3 dots icon is clicked for each item. But can the code be written in a better way..

Right now menu is getting created for each card item in a FlatList but ideally it would have been good to create single Menu View and dynamically associate it to some card where ever the 3 dots is clicked.

Expo Source Code Link

image

sharathm89 avatar Feb 15 '19 15:02 sharathm89

Hi there, I am just wondering how you added an image onto the menu button? I have added Image to the button (rather than Text), although my issue is that when the image is pressed, the menu does not appear.

button={<Image onPress={this.showMenu} style={styles.iconStyle} source={require('./assets/icons/dotsIcon.png')} > </Image>}

Hoping you may have experienced this and know the answer.

ghost avatar Mar 16 '19 01:03 ghost

@joniashton I've used a image like this and it works.

button = { <TouchableOpacity onPress = {this.showMenu}> <Image onPress = {this.showMenu} style = {{ margin: 20 }} resizeMode = 'contain' source = {require('../../assets/images/dot_menu.png')} /> </TouchableOpacity> }

snelanga avatar Apr 02 '19 08:04 snelanga

@sharathm89 I will rewrite this library using contexts so soon you can use only one modal overlay for each screen.

mxck avatar May 26 '19 16:05 mxck

@sharathm89 You can try out this package - https://www.npmjs.com/package/react-native-enhanced-popup-menu. It initially was based on this react-native-material-menu, but more flexible in terms of customizations.

You can select base component to which you will stick menu. Then, later, at pressing dots for other components, you can compute dynamic offsets (added to base position) - this offset will change menu position to appropriate new component.

const computeOffset = (left, top, width, height) => {
    // left, top - are positions of component to which menu is relative
    // width, height - are sizes of this component
    // do any dynamic computations to offset initial position of menu
    // they will be added to initial menu position
   return { bottom: 30 }
}
const showMenu = () => menuRef.show(textRef.current, stickTo = Position.BOTTOM_CENTER, computeOffset = computeOffset);

likern avatar Sep 05 '19 13:09 likern

@sharathm89 hey could you please share how ur able to get the popup menu alongside each card .. im trying to implement this but the menu is always displayed on the last element of the flat list.....thanks in advance

r-mhjn avatar Oct 05 '19 20:10 r-mhjn

did you tried react-native-popup-menu ?

ZeeshanAhmadKhalil avatar Mar 18 '21 11:03 ZeeshanAhmadKhalil