React Native学习过程遇到的一些坑

1、Image source size {42, 32} does not match loaded image size {21, 16}
假设图片的名称叫a.png

错误截图

错误原因
检查资源文件aa@2x.png分辨率不是a.png的两倍,修改资源文件确保@2x是其两倍,@3x分辨率是其三倍之后,问题解决。
----2016-06-16
2、TabBarIOS.Item onPress方法调用,但是界面并没有跟着一起发生变化,示例如下:

class XXXXXX extends Component {
  constructor(props) {
    super(props);
    this.state = {
      menuItems: [{
        title: '新闻',
        icon: require('./App/resources/night_tabbar_icon_news_normal.png'),
        highlight: require('./App/resources/night_tabbar_icon_bar_normal.png'),
        backgroundColor: '#ff0000',
        tag: 'news'
      },
      {
        title: '阅读',
        icon: require('./App/resources/night_tabbar_icon_reader_normal.png'),
        highlight: require('./App/resources/night_tabbar_icon_bar_normal.png'),
        backgroundColor: 'white',
        tag: 'reading'
      },
      {
        title: '视频',
        icon: require('./App/resources/night_tabbar_icon_media_normal.png'),
        highlight: require('./App/resources/night_tabbar_icon_bar_normal.png'),
        backgroundColor: 'blue',
        tag: 'media'
      },
      {
        title: '话题',
        icon: require('./App/resources/night_tabbar_icon_bar_normal.png'),
        highlight: require('./App/resources/night_tabbar_icon_bar_normal.png'),
        backgroundColor: 'yeallow',
        tag: 'bar'
      },
      {
        title: '我',
        icon: require('./App/resources/night_tabbar_icon_me_normal.png'),
        highlight: require('./App/resources/night_tabbar_icon_bar_normal.png'),
        tag: 'me'
      }],
      selectedTag: ''
    };
    this.state.selectedTag = this.state.menuItems[0].tag;
  }
  render() {
    var items = this.state.menuItems.map((itemValue) => {
      return (
        <TabBarIOS.Item
        key = {itemValue.tag}
        selected = {this.state.selectedTag === itemValue.tag}
        title = {itemValue.title}
        icon = {itemValue.icon}
        selectedIcon = {itemValue.highlight}
        onPress = {() => {
          this.state.selectedTag = itemValue.tag;
        }}
        >
        <View style = {{flex: 1, backgroundColor: '#FF0000'}}>
          <Text style = {styles.welcome}>
            {itemValue.title}
          </Text>
        </View>
        </TabBarIOS.Item>
      )
    });
    return (
      <TabBarIOS
      unselectedTintColor = 'gray'
      tintColor = 'red'
      barTintColor = 'white'>
      {items}
      </TabBarIOS>
    );
  }
}

解决办法:

....
onPress = {() => {
          this.setState({
            selectedTag: itemValue.tag
          });
        }}
....

----2016-06-17
3、TabBarIOS.Item初始化代码规范正常,但是界面不显示:
检查原因:

<TabBarIOS.Item
        key = {itemValue.tag}
        selected = {this.state.selectedTag === itemValue.tag}
        title = {itemValue.title}
        icon = {itemValue.icon}
        onPress = {() => {
          this.setState({
            selectedTag: itemValue.tag
          });
        }}
        >
        //这里面是空的!!!!!!!
        </TabBarIOS.Item>

加上视图就可以显示了。
----2016-06-17
4、this.setStateis not a function
检查一下,调用这个地方的函数是不是没有XXX.bind(this)
----2016-06-19
5、onScrollfunction 只调用了一次,虽然已经设置了scrollEventThrottle参数,不管是设置其大于(or <=)16均无任何效果,控制台没有任何报错。

检查一下 onScroll回调函数里是不是执行了些不符合规则的东西
----2016-06-20

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,688评论 0 17
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,126评论 25 709
  • 《裕语言》速成开发手册3.0 官方用户交流:iApp开发交流(1) 239547050iApp开发交流(2) 10...
    叶染柒丶阅读 28,085评论 5 19
  • 暑假快结束的时候,带儿子去了趟上海。之所以说圆梦,一是去上海结束了我长达一年的求医之路,二是终于兑现了对儿子的承诺...
    明明似我阅读 257评论 1 2
  • 这是我在西藏过得第三个中秋节,吃着甜甜的月饼,看着那一轮怎么都觉得好看的月亮,挺惬意的,整个人的心情都舒畅。 正好...
    一访文阅读 446评论 0 8