文章基于:https://blog.csdn.net/cream66/article/details/104650082/
**官方文档:reactnavigation
直接简单粗暴进入正题。
1.安装react-navigation/native
npm install @react-navigation/native
//yarn
yarn add @react-navigation/native
2.添加依赖库
npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view
但是在此步骤中出现了两个问题。
1.npm版本过高
提示
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
**省略部分**
peer react@"^16.0" from @react-native-community/masked-view@0.1.10
解决方法:
npm install npm@3.8.6 -g
此步参考:
https://blog.csdn.net/qq_37955704/article/details/115065415
2.添加依赖库未成功
按照官方的说法:React Native 0.60及更高版本开始,会自动链接,如果你版本是0.60及以上,这一步就可以跳过;而React Native 0.59以及更低版本则需要手动链接,安装react-native link。
我的生产环境为:“react-native”: “0.64.0”,满足条件。
实际操作中,依赖未添加并自动链接,跑后续代码中会提示:
“RNCSafeAreaProvider” was not found in the UIManager.
“RNSScreen" was not found in the UIManager. ”
解决办法:
npm install react-native-reanimated -save
npm install react-native-gesture-handler -save
npm react-native-screens -save
npm react-native-safe-area-context -save
npm install @react-native-community/masked-view -save
一条条安装 并依赖
react-native link react-native-reanimated
react-native link react-native-gesture-handler
react-native link react-native-screens
react-native link react-native-safe-area-context
以上是我使用 react-navigation 遇到的坑,如有错误请帮忙指正,谢谢。
具体使用实例代码请参考:React Navigation 5.x的依赖安装和基本使用