我试图使用菜单从React原生纸内我的头部,但当按下按钮,应该显示菜单,它不工作,它只是什么都不做。但当我做了我的头部以外,我按下按钮,应该显示菜单,它的工作和显示所需的所有项目。有人知道我如何可以修复吗?这里是我的代码:
const [visible, setVisible] = React.useState(false);
const openMenu = () => setVisible(false);
const closeMenu = () => setVisible(false);
return (
<Drawer.Navigator initialRouteName="Home"
screenOptions={({ navigation }) => ({
headerStyle: {
backgroundColor: 'white',
},
headerTitleStyle: {
color: 'black',
},
headerLeft: () => <FontAwesome5 name='user-circle' style={{right: -15}} onPress={navigation.toggleDrawer} size={28} solid/>,
})}>
<Drawer.Screen name="Home" component={BottomTab}
options={{
title: '',
headerTitleAlign: 'center',
headerRight: () => (
<View>
<View style={{flexDirection: 'row'}}>
<View style={{left: -60}}>
<Provider>
<View
style={{
paddingTop: 0,
left: 0,
flexDirection: 'row',
textAlign: 'center',
top: 0,
}}>
<Menu
visible={visible}
onDismiss={closeMenu}
anchor={<Pressable onPress={openMenu}>
<Text style={{fontSize: 20, fontWeight: 'bold', backgroundColor: 'red', paddingRight: 30}}>
Popular
</Text>
</Pressable>}>
<Menu.Item onPress={() => {}} title="Item 1" />
<Menu.Item onPress={() => {}} title="Item 2" />
<Divider />
<Menu.Item onPress={() => {}} title="Item 3" />
</Menu>
</View>
</Provider>
{/*<Pressable onPress={() => console.log('Pressed Popular')}>
<Text style={{fontSize: 20, fontWeight: 'bold', backgroundColor: 'white', paddingRight: 30}}>
Popular
</Text>
</Pressable>*/}
</View>
<MaterialIcons
onPress={() => console.log('Pressed Popular')}
name="expand-more"
size={30}
style={{left: -80}}
/>
<Feather
onPress={() => props.navigation.navigate('Create')}
name="plus-circle"
color="black"
size={30}
style={{right: 15, top: 0}}
/>
</View>
</View>
),
}}
/>
1条答案
按热度按时间yfjy0ee71#
我也遇到过同样的问题,当您在屏幕文件中使用setOptions与useLayoutEffect组合时,它似乎可以工作。