有没有办法让菜单从左到右而不是从右到左? 当从导航栏的右键单击时,它没关系; 而不是从左侧按钮,它被渲染出屏幕。
答案 0 :(得分:1)
以下是如何使用带有react-navigation的弹出菜单的简短示例。该菜单在headerRight
和headerLeft
占位符中呈现。它在两侧都能正确显示:
import React from 'react';
import { AppRegistry, Text } from 'react-native';
import { StackNavigator } from 'react-navigation';
import Menu, {
MenuContext,
MenuOptions,
MenuOption,
MenuTrigger
} from 'react-native-popup-menu';
const NavigatorMenu = ({ navigation }) => (
<Menu>
<MenuTrigger text='...' />
<MenuOptions>
<MenuOption
onSelect={() => navigation.navigate('Page2')}
text='Navigate Page 2'
/>
<MenuOption
onSelect={() => navigation.navigate('Page3')}
text='Navigate Page 3'
/>
</MenuOptions>
</Menu>
);
class Home extends React.Component {
static navigationOptions = ({ navigation }) => ({
title: 'Home',
headerRight: <NavigatorMenu navigation={navigation} />,
headerLeft: <NavigatorMenu navigation={navigation} />,
});
render() {
return <Text>Home Page</Text>;
}
}
const Page2 = () => <Text>2nd Page</Text>;
const Page3 = () => <Text>3rd Page</Text>;
const TopStackNavigator = StackNavigator({
Home: { screen: Home },
Page2: { screen: Page2 },
Page3: { screen: Page3 },
});
const App = () => (
<MenuContext>
<TopStackNavigator />
</MenuContext>
);
AppRegistry.registerComponent('examples', () => App);
它在Android上测试过:
答案 1 :(得分:0)
解决。在测试期间,我正在混合react-native-menu和react-native-popup-menu。我已经安装了。 Webstorm让我把两个图书馆的进口混合起来。