node.js - 如何从 React StackNavigator 返回到上一个屏幕到特定选项卡
问题描述
我正在使用具有如下结构的 React StackNavigator:
-----BottomNavigator
-------TabNavigator (has 3 screens)
---------StackNavigator
所以我想从 stackNavigator 返回到上一个屏幕到 TabNavigator(屏幕 2)。
这是我的 TabNavigator 代码:
const ServiceTabNavigator = createMaterialTopTabNavigator(
{
screenone: screenone,
screentwo: screentwo,
screenthree: screenthree
},
{
tabBarOptions: {
activeTintColor: "#1B5357",
inactiveTintColor: "gray",
style: {
backgroundColor: "#fff",
color: "#1B5357"
},
indicatorStyle: {
backgroundColor: "#1e90ff"
}
},
navigationOptions: {
tabBarLabel: "ESTH",
tabBarIcon: ({ tintColor }) => (
<Icon name="bars" color={tintColor} size={24} />
)
}
}
);
这是 StackNavigator 的代码,它有类似这样的代码,但它没有转到 tabNavigator 的 screen2 而不是 screen1。
static navigationOptions = ({ navigation }) => ({
title: "Request Service",
headerLeft: (
<TouchableOpacity
onPress={() => {
() =>
navigation.dispatch(
NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: "MainNavigator" }) //MainNavigator is bottomNavigator
]
})
);
navigation.navigate("screentwo");
}}
>
<Icon
name="times"
type="font-awesome"
iconStyle={{ color: "#000" }}
containerStyle={{ marginLeft: 16 }}
/>
</TouchableOpacity>
),
headerTitleStyle: {
color:'#00CA9D',
fontWeight: 'bold',
},
headerStyle: { borderBottomWidth:0 }
});
谢谢
解决方案
我使用 react-navigator .. 有一个jumpToIndex
为此命名的属性。我以这种方式解决了它,因为我需要打开一个模态而不是跳转到给定的选项卡。也许您可以修改以满足您的需求:
<TabBarBottom
{...props}
jumpToIndex={(index) => {
if (index === 5) {
// This is the MORE-Tab-Button. Don't switch to tab, but open the Modal
props.navigation.navigate('Menu_Screen');
} else {
jumpToIndex(index);
}
}}
/>
推荐阅读
- django - 在引导模型中始终禁用下拉列表?
- javascript - 将表单从“只读”更改为 PATCH
- jenkins - 用于 Jenkins 的 Kubernetes 云代理在管道执行期间始终离线
- python - 当我尝试通过 for 循环修改数组时,为什么数组没有改变
- javascript - 隐藏/显示元素功能未定义?
- javascript - 打字稿问题:“元素隐式具有'任何'类型”
- node.js - TypeError: Object.entries(...).flatMap is not a function at Array.forEach (
) - flutter - Flutter go-flutter windows 使用 sqflite 插件批量操作
- sql - 子查询(大查询)中的 SQL 脚本?
- java - 方法的ArrayList,方法引用静态方法报错