【发布时间】:2021-07-26 15:07:57
【问题描述】:
我是 React Native 的初学者。我经历了不同的相关主题。但失败了。这是我的问题,
我有一个底部导航器,有 4 个项目,比如仪表板、X、患者和 Y。这是优化的底部导航器代码。
const Stack = createStackNavigator();
const Bottom = createBottomTabNavigator();
const Main = () => {
return (
<Bottom.Navigator
initialRouteName="DashboardScreenStack"
tabBarOptions={{
style: {
height: 70,
paddingTop: 20,
backgroundColor: '#F3F6FF',
},
activeTintColor: colors.navigationTextActive,
inactiveTintColor: colors.navigationTextInactive,
labelStyle: {
fontSize: 15,
marginTop: 15,
paddingBottom: 10,
},
}}>
<Bottom.Screen
name="DashboardScreenStack"
component={DashboardScreenStack}
options={{
tabBarLabel: 'Dashboard',
}}
/>
<Bottom.Screen
name="X"
component={X}
options={{
tabBarLabel: 'X',
}}
/>
<Bottom.Screen
name="Patient"
component={Patient}
options={{
tabBarLabel: 'Patient',
}}
/>
<Bottom.Screen
name="Y"
component={Y}
options={{
tabBarLabel: 'Y',
}}
/>
</Bottom.Navigator>
);
};
这是我的患者菜单代码。
const Patient = (props) => {
let resultData = null;
var initialRoute = '';
if (
typeof props.route.params != 'undefined' &&
props.route.params.result != null
) {
resultData = props.route.params.result;
initialRoute = 'PatientDashboardScreen';
} else {
initialRoute = 'AddPatientScreen';
}
return (
<Stack.Navigator
initialRouteName={initialRoute }>
<Stack.Screen
name="PatientDashboardScreen"
component={PatientDashboardScreen}
initialParams={resultData}
options={{headerShown: false}}
/>
<Stack.Screen
name="TestScreen1"
component={TestScreen1}
options={{headerShown: false}}
/>
<Stack.Screen
name="TestScreen2"
component={TestScreen2}
options={{headerShown: false}}
/>
<Stack.Screen
name="AddPatientScreen"
component={AddPatientScreen}
options={{headerShown: false}}
/>
</Stack.Navigator>
);
};
患者菜单中应显示 4 个屏幕。其中,如果我在仪表板菜单中选择一个项目,我需要打开“PatientDashboardScreen”。 props 中也会有一些可用的数据。但是在直接点击“Patient”菜单时,我需要移动到没有数据传递的“AddPatientScreen”。
我尝试了上面的代码。但只有初始点击有效。如果我首先从列表中选择,则始终显示“PatientDashboardScreen”,如果我先直接选择 Patient 菜单,则始终在 Patient 菜单选择中显示“AddPatientScreen”。
任何帮助都会非常有用。谢谢
【问题讨论】:
-
你试过我在答案中提供的方法了吗?
-
正在努力。会尝试更新
标签: react-native react-navigation-bottom-tab