react-native - React Navigation (V2):如何在 Drawer Navigator 中设置 Stack Navigator 的 Icon 和 label?
问题描述
我正在尝试在 DrawerNavigator 中自定义 StackNavigator。
这是我的代码:
const HomeStack = createStackNavigator(
{
HomeScreen,
HomeDetailScreen,
InteriorScreen,
InteriorDetailScreen
},
{
initialRouteName: "HomeScreen",
navigationOptions: {
headerTitleStyle: {
color: headerColor
},
headerBackTitleStyle: {
color: headerColor
},
headerTintColor: headerColor
}
}
const MainStack = createStackNavigator(
{
HomeStack,
ChooseLocationScreen,
FilterHomesScreen
},
{
initialRouteName: "HomeStack",
mode: "modal",
navigationOptions: ({ navigation }) => {
const options = {
headerTitleStyle: {
color: headerColor
},
headerBackTitleStyle: {
color: headerColor
},
headerTintColor: headerColor,
drawerLabel: SCREEN_TEXT_HOME_HEADER,
drawerIcon: ({ tintColor }) => (
<Image
source={require("../assets/icons/home.png")}
resizeMode="contain"
style={{ width: 20, height: 20, tintColor: tintColor }}
/>
)
};
if (navigation.state.routeName === "HomeStack") options["header"] = null;
return options;
}
}
);
const MainDrawer = createDrawerNavigator(
{ MainStack },
{
initialRouteName: "MainStack",
drawerBackgroundColor: backgroundColor,
contentOptions: {
inactiveTintColor: headerColor,
activeTintColor: activeTintColor
}
}
);
我的问题是,在 DrawerNavigator 中,该项目仍然只是说“MainStack”。但我希望它说“Home”(这是 的值SCREEN_TEXT_HOME_HEADER
),并且我希望它有“home.png”图标。如您所见,我尝试根据文档更改导航选项,但不知何故不起作用。如何获得正确的图标和标签?
解决方案
找到了解决方案。在愚蠢的尝试和错误之后,这是我如何使它工作的:
{
Main: {
screen: MainStack,
navigationOptions: {
drawerLabel: SCREEN_TEXT_HOME_HEADER,
drawerIcon: ({ tintColor }) => (
<Image
source={require("../assets/icons/home.png")}
resizeMode="contain"
style={{ width: 20, height: 20, tintColor: tintColor }}
/>
)
}
}
}
推荐阅读
- php - 未检测到 Symfony/Doctrine ORM 映射
- javascript - 从反应导航中的嵌套导航器重置堆栈
- java - java.lang.IncompatibleClassChangeError:在读取形状文件时实现类
- python - 如何解决覆盆子中的这些错误?
- html - 背景图像未显示在 div 中
- bpf - 函数“bpf”的隐式声明
- java - 如何在 char 数组 Java 中找到一个字符后跟一个字符?
- mongodb - 如何将一个字段与mongodb中的组合字段进行比较
- c# - 如何将 windows.form 的起始位置设置为底部?
- windows - 密码策略的 WMI 类和实例