我认为它是一个错误,问题是休闲:
我有这个(在选项卡导航器中堆叠导航器):
- 一个选项卡
- 堆栈
- 抗体堆栈
在哪里:
- 抗体堆栈
- Aba 组件
- Abb 组件
当我在 Abb 组件中使用 navigation.goBack() 函数时,goBack 函数将我发送到 Aa 堆栈而不是 Aba 组件。
这是一个奇怪的行为,因为如果我按下 Android 后退按钮将我发送到 Aba 组件,我认为这就是 navigation.goBack 应该如何工作。
这是我的 Ab 堆栈
const ComplementFormStack = ({ navigation, route, onSetGoToSyncData }) => {
return (
<Stack.Navigator
initialRouteName="ComplementForms"
screenOptions={{
...stackScreenOptions({
onPressLeftIcon:
route?.state?.index > 0 ? navigation.goBack : navigation.openDrawer,
onPressRightIcon: onSetGoToSyncData,
index: route?.state?.index
})
}}
>
<Stack.Screen
name="ComplementForms"
component={ComplementForms}
options={{
title: "Formularios"
}}
/>
<Stack.Screen
name="FilterIndividualTable"
component={FilterIndividualTable}
options={{
title: "Filtros de busqueda"
}}
/>
</Stack.Navigator>
);
};
这是我的 A 标签:
const SettingsTab = () => (
<Tab.Navigator initialRouteName="DataRecorded" backBehavior="order">
<Tab.Screen
name="DataRecorded"
component={DataRecordedStack}
options={{
title: "Registros"
}}
/>
<Tab.Screen
name="ComplementForms"
component={ComplementFormsStack}
options={{
title: "Formularios"
}}
/>
</Tab.Navigator>
);
这是 stackScreenOptions ,如果您想知道:
const stackScreenOptions = ({
onPressLeftIcon = () => {},
onPressRightIcon = () => {},
index
}) => {
return {
headerStyle: {
backgroundColor: "white",
height: hp(8.3)
},
headerTintColor: Color.primary.dark,
headerTitleStyle: {
fontSize: hp(2.6),
},
headerLeft: () => {
if (index > 0) {
return <GoBackBtn onPress={onPressLeftIcon} />;
}
return <ButtonDrawer onPress={onPressLeftIcon} />;
},
headerRight: () => {
return <SyncButton onPress={onPressRightIcon} />;
}
};
};