gpt4 book ai didi

react-native - 将自定义图标添加到抽屉导航

转载 作者:行者123 更新时间:2023-12-03 09:49:48 28 4
gpt4 key购买 nike

我正在尝试向我的 CustomDrawerComponent 添加自定义图标,但没有任何 react ......

应用程序.js:

const navigationOptions = {
headerTintColor: colors.white,
};

const drawerNavigationOption = ({ navigation }) => ({
...navigationOptions,
headerLeft: (
<TouchableOpacity onPress={() => navigation.toggleDrawer()}>
<View>
<Icon name="menu" size={24} color={colors.white} />
</View>
</TouchableOpacity>
),
});

const MapsStackNavigator = createStackNavigator({
MapsNavigator: {
screen: MapsScreen,
navigationOptions: drawerNavigationOption,
},
});

const AppDrawerNavigator = createDrawerNavigator(
{
Plans: MapsStackNavigator,
},
{
contentComponent: CustomDrawerMenu,
contentOptions: {
inactiveTintColor: colors.doveGrey,
activeTintColor: colors.doveGrey,
},
}
);

我的 CustomDrawerMenu.js :
export default class CustomDrawerMenu extends Component {
render() {
return (
<ScrollView
contentContainerStyle={{
flex: 1,
flexDirection: "column",
justifyContent: "space-between",
}}
>
<SafeAreaView forceInset={{ top: "always", horizontal: "never" }}>
{...}
<DrawerItems {...this.props} />
</SafeAreaView>
{...}
</ScrollView>
);
}
}

我的 map 屏幕:
export default class MapsScreen extends React.Component {
static navigationOptions = {
drawerIcon: (
<Image
style={{ width: 24, height: 24 }}
source={require("../../assets/icons/plan.png")}
/>
),
title: "Plans",
};

render() {
return (
<Text>My map screen</Text>
);
}
}

但绝对没有发生任何事情......我试图添加 drawerIcon到我的 App.js > const navigationOptions但什么也没发生。

我真的不知道把 drawerIconm 放在哪里,因为我搜索了文档、一些 YouTube 视频,当我复制相同的视频时,它不起作用。

谢谢你。

最佳答案

在新版react-navigation(5.x)
你必须要做 :

1-

import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
import Icon from 'react-native-vector-icons/Ionicons';

2- 而不是使用 createDrawerNavigator您必须使用 Drawer.Navigator如下 :
<NavigationContainer>
<Drawer.Navigator
initialRouteName="Products">

<Drawer.Screen name="Products" component={YOUR COMPONENT OR YOUR STACKNAVIGATOR} options={{
drawerIcon: config => <Icon
size={23}
name={Platform.OS === 'android' ? 'md-list' : 'ios-list'}></Icon>
}} />

<Drawer.Screen name="Orders" component={YOUR COMPONENT OR YOUR STACKNAVIGATOR} options={{
drawerIcon: config => <Icon
size={23}
name={Platform.OS === 'android' ? 'md-create' : 'ios-create'}></Icon>
}} />

</Drawer.Navigator>
</NavigationContainer>

关于react-native - 将自定义图标添加到抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54236423/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com