Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sharathm89 opened this issue Feb 15, 2019 · 6 comments

Comments

@sharathm89
Copy link

sharathm89 commented Feb 15, 2019

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

@ghost
Copy link

ghost commented Mar 16, 2019

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.

@snelanga
Copy link

snelanga commented Apr 2, 2019

@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> }

@mxck
Copy link
Owner

mxck commented May 26, 2019

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

@likern
Copy link

likern commented Sep 5, 2019

@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);

@r-mhjn
Copy link

r-mhjn commented Oct 5, 2019

@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

@ZeeshanAhmadKhalil
Copy link

did you tried react-native-popup-menu ?

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

No branches or pull requests

6 participants