React Navigation 5.x 的安装使用遇到的坑

文章基于: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的依赖安装和基本使用

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值