警告信息
WARN Found screens with the same name nested inside one another. Check:
DrawerNavigator > MainTabNavigator > ServiceScreen, DrawerNavigator > MainTabNavigator > ServiceScreen > ServiceScreen
This can cause confusing behavior during navigation. Consider using unique names for each screen instead.
BaseNavigationContainer@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.ywh:147787:28
ThemeProvider@http://localhost:8081/index.bundle?platform=ios&dev=true
原因分析
通过这个层级关系可以看出,写代码的过程中出现名称相同的Screen组件。
- DrawerNavigator > MainTabNavigator > ServiceScreen,
- DrawerNavigator > MainTabNavigator > ServiceScreen > ServiceScreen
虽然是一个警告,但是看着还是很难受的。
解决办法
因为我用Stack把ServiceScreen又嵌套了一层,让它能有header。但是写的时候忘记修改名称了。
const ServiceStackScreen = ({navigation}: any) => {
return (
<StackScreen
navigation={navigation}
title={'服务'}
backgroundColor={tabColor3}
{}
screenName={'ServiceStackScreen'}
component={ServiceScreen}
/>
);
};
screenName={‘ServiceScreen’}修改成screenName={‘ServiceStackScreen’}
问题解决。
总结
粗心导致的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)