ReactNative之Navigator

首先需要明确一下Navigator已经被废弃了,也就是过时了,现在官方推荐使用 react-navigation。但是初学者在学习的时候通常都会接触到这个Navigator,作为有强迫症的程序员,我还是简单来说下使用Navigator踩的坑吧。
首先会提示

Invariant Violation: Navigator is deprecated and has been removed from this package. It can now be installed and imported from `react-native-deprecated-custom-components` instead of `react-native`. Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html

也就是说这个库已经被剥离了,所以我们需要安装react-native-deprecated-custom-components。

如果你需要继续使用Navigator,则需要先yarn add react-native-deprecated-custom-components安装,然后从这个模块中import,即import { Navigator } from 'react-native-deprecated-custom-components'.

但是等我们按照说明修改之后,发现还是跑不起来。

undefined is not an object (evaluating '_react3.default.PropTypes.shape')

这个是因为react和reactNative的版本太高的原因,需要在package.json里边把React 的版本还原到 "^16.0.0-alpha.12" 就可以了。

你可能感兴趣的:(ReactNative之Navigator)