React Native开发错误警告处理总结(持续更新)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_19678579/article/details/73467355
注:
本文是我在开发过程中遇到问题解决方法的总结,文中有不妥的地方希望指出共同学习,之后会持续更新,希望帮助到更多的学习者。

一 . Error Set

Error1 : 本地静态图片无法加载展示


  1. 这是因为没有找到所需要的图片资源导致的. 需要把图片资源导入RN 项目中(在项目的 Images 文件中).
  2. 引用图片资源
<Image  style={styles.localImage}
        source={require("./Images/waitToDesign1.png")}
  />

或者是安装了 yarn 包导致了冲突
卸载并删除安装yarn包



Error2 : 本地静态图片无法加载展示



  1. 修改引用图片资源代码
<Image  style={styles.localImage}
        source={require("./Images/waitToDesign1.png")}
  />



Error3 : react-native构建项目 run-ios 时失败: Does Not Exist


原因是有可能是 react-native 和 react 版本问题

//修改项目的react版本

npm install –save [email protected]

//修改react-native版本

npm install –save [email protected]

//根据修改后的版本信息修改配置

rm -rf node_modules && npm install

//然后再运行项目即可

react-native run-ios




Error 4: 使用了第三方库失败

'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/d

1.在 终端中 导入依赖包

 &emsp;  npm install react-native-deprecated-custom-components --save

2.然后在使用的js 文件中

import {Navigator} from react-native-deprecated-custom-components






Error 5 : 关于导航问题

我使用的react-native的版本是0.44,这个版本里面移除了Navigator这个组件,所以在非正式版本里面出现问题,需要优先查看是不是版本问题导致的

1、npm install React-native-deprecated-custom-components --save
2import Navigator from 'react-native-deprecated-custom-components';
3、用到的地方使用
   <Navigator.Navigator
              initialRoute={{ name: defaultName, component: defaultComponent }}
              configureScene={(route) => {
                return Navigator.Navigator.SceneConfigs.VerticalDownSwipeJump;
              }}
              renderScene={(route, navigator) => {
                let Component = route.component;
                return <Component {...route.params} navigator={navigator} />
              }} />
4、千万记得使用Navigator.Navigator,我一直直接使用<Navigator></Navigator>,总是报错,
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) 
but got: object.这表明没有找到Navigator组件,查了好半天才找到问题所在。





二 . Bug Set

Bug 1 : ListView/ScrollView偏移问题

在使用了下拉刷新,上提加载功能后出现了偏移问题:
  要把他们的自动布局功能关闭就可以了:
  automaticallyAdjustContentInsets={false}

例如:
<ListView
automaticallyAdjustContentInsets={false}
style={{backgroundColor: 'white'}}
renderRow={this._renderRow}
renderSectionHeader={this._renderSectionHeader}
dataSource={ds.cloneWithRowsAndSections(dataBlob, sectionIDs, rowIDs)}
/>

猜你喜欢

转载自blog.csdn.net/qq_19678579/article/details/73467355