ccd
ccd

Reputation: 6918

React native popup menu can not navigate using navigation props

I have the Message react navigation stack screen.

...

class Message extends React.Component {
  static navigationOptions = ({ navigation }) => ({
    ...
    headerRight: <MessagePopupMenu navigation={navigation} />
  });

  render() {
    ...
  }
}

And I want to use react-native-popup-menu to navigate to another screen.

...

export const MessagePopupMenu = ({ navigation }) => (
  <View>
    <Menu>
      <MenuTrigger style={styles.menuTrigger}>
        <Icon name="ios-add" size={30} color="#757575" />
      </MenuTrigger>
      <MenuOptions optionsContainerStyle={{ marginTop: 40, width: 100 }}>
        <MenuOption style={styles.menuOption}>
          <Text
            style={styles.text}
            onSelect={() => navigation.navigate("AddUser")}
          >
            AddFriend
          </Text>
        </MenuOption>
        <MenuOption>
          <Divider />
        </MenuOption>
        <MenuOption style={styles.menuOption}>
          <Text
            style={styles.text}
            onSelect={() => navigation.navigate("AddGroup")}
          >
            AddGroup
          </Text>
        </MenuOption>
      </MenuOptions>
    </Menu>
  </View>
);

const styles = StyleSheet.create({
  menuOption: {
    ...
  },
  menuTrigger: {
     ...
  },
  text: {
    ...
  }
});

It seems the navigation props can not pass to the MessagePopupMenu component, When I click the AddFriend and AddGroup menu button.

The Message component is already tested as a correct navigation screen.

Upvotes: 0

Views: 1414

Answers (1)

sodik
sodik

Reputation: 4683

As per comment: onSelect should be bound to MenuOption component, e.g.

    <MenuOption style={styles.menuOption} onSelect={() => navigation.navigate("AddGroup")}>
      <Text style={styles.text}>
        AddGroup
      </Text>
    </MenuOption>

Upvotes: 1

Related Questions