mxck / react-native-material-menu

Pure JavaScript material menu component for React Native
MIT License
512 stars 91 forks source link

MenuItem onPress not working #106

Closed netsnatch closed 2 years ago

netsnatch commented 3 years ago

TouchableHighlight onPress not working on iOS 14.4 react-native-material-menu: v1.2.0

<TouchableHighlight onPress={() => alert('hello')}><Text>Example</Text></TouchableHighlight>

And alert is not called.

StCyr commented 3 years ago

Got this:

class HeaderBar extends React.Component {

    constructor(props) {
        super(props)
        this.logout = this.logout.bind(this);
    }

    render() {
        return (
            <View style={styles.container}>
                <Text>
                    {this.props.children}
                </Text>
                <Menu
                    button={
                        <Image
                            style={{ width: 24, height: 24 }}
                            source={require('../assets/more.png')}
                        />
                    }
                >
                    <MenuItem OnPress={this.logout} >
                        Logout
                    </MenuItem>
                </Menu>
            </View>
        )
    }

    logout() {
        this.props.setToken(null)
        this.props.setServer(null)  
        this.props.navigation.navigate('Home')
    }
}

Doesn't work neither

StCyr commented 3 years ago

Got this:

class HeaderBar extends React.Component {

    constructor(props) {
        super(props)
        this.logout = this.logout.bind(this);
    }

    render() {
        return (
            <View style={styles.container}>
                <Text>
                    {this.props.children}
                </Text>
                <Menu
                    button={
                        <Image
                            style={{ width: 24, height: 24 }}
                            source={require('../assets/more.png')}
                        />
                    }
                >
                    <MenuItem OnPress={this.logout} >
                        Logout
                    </MenuItem>
                </Menu>
            </View>
        )
    }

    logout() {
        this.props.setToken(null)
        this.props.setServer(null)  
        this.props.navigation.navigate('Home')
    }
}

Doesn't work neither

Got it working nevermind (needed a around my and OnPress to be onPress)