gpt4 book ai didi

react-native - 如果使用react-native-vector-icons,则为react-navigation抽屉事件图标着色

转载 作者:行者123 更新时间:2023-12-02 00:08:20 26 4
gpt4 key购买 nike

我有这个 react 抽屉导航:

enter image description here

我想将事件图标像标签一样设置为绿色。

我使用react-native-vector-icons 作为图标。

代码:

const AddMenuIcon = ({ navigate }) => (
<View>
<Icon
name="plus"
size={30}
color="#FFF"
onPress={() => navigate('DrawerOpen')}
/>
</View>
)

const SearchMenuIcon = ({ navigate }) => (
<Icon
name="search"
size={30}
color="#FFF"
onPress={() => navigate('DrawerOpen')}
/>
)

const LoginMenuIcon = ({ navigate }) => (
<Icon
name="user"
size={30}
style={{ fontWeight: '900' }}
color="#FFF"
onPress={() => navigate('DrawerOpen')}
/>
)

const Stack = {
Login: {
screen: Login,
headerMode: 'none'
},
Search: {
screen: Search,
headerMode: 'none'
},
Add: {
screen: Add,
headerMode: 'none'
}
}

const DrawerRoutes = {
Login: {
name: 'Login',
screen: StackNavigator(Stack.Login, {
headerMode: 'none'
}),
headerMode: 'none',
navigationOptions: ({ navigation }) => ({
drawerIcon: LoginMenuIcon(navigation)
})
},
'Search Vegan': {
name: 'Search',
screen: StackNavigator(Stack.Search, {
headerMode: 'none'
}),
headerMode: 'none',
navigationOptions: ({ navigation }) => ({
drawerIcon: SearchMenuIcon(navigation)
})
},
'Add vegan': {
name: 'Add',
screen: StackNavigator(Stack.Add, {
headerMode: 'none'
}),
headerMode: 'none',
navigationOptions: ({ navigation }) => ({
drawerIcon: AddMenuIcon(navigation)
})
}
}

const CustomDrawerContentComponent = props => (
<SafeAreaView style={{ flex: 1, backgroundColor: '#3f3f3f', color: 'white' }}>
<DrawerItems {...props} />
</SafeAreaView>
)

const RootNavigator = StackNavigator(
{
Drawer: {
name: 'Drawer',
screen: DrawerNavigator(DrawerRoutes, {
initialRouteName: 'Login',
drawerPosition: 'left',
contentComponent: CustomDrawerContentComponent,
contentOptions: {
activeTintColor: '#27a562',
inactiveTintColor: 'white',
activeBackgroundColor: '#3a3a3a',
}
}),
headerMode: 'none',
initialRouteName: 'Login'
},
initialRouteName: 'Login'
},
{
headerMode: 'none',
initialRouteName: 'Drawer'
}
)

export default RootNavigator

如果使用react-native-vector-icons,有没有办法将事件图标的颜色与事件文本的颜色相同? activeTintColor 不适用于图标。我们可以以编程方式检查是否处于事件状态吗?另一个奇怪的事情是 rgba 颜色在 CustomDrawerContentComponent 上不起作用,所以我无法使背景半透明,这很烦人。如果您也能提供帮助,那就太好了!

最佳答案

在react-navigation版本中:5.x

使用颜色而不是tintColor providing-a-custom-drawercontent

    <Drawer.Screen name="settingscreen" component={Settings}
options={{
drawerLabel: "Settings",
drawerIcon: ({ color }) => <MaterialCommunityIcons name="settings" size={24} style={[styles.icon, { color: color }]} />
}}
/>

关于react-native - 如果使用react-native-vector-icons,则为react-navigation抽屉事件图标着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52603277/

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