微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

react-native ListView的属性flexWrap为wrap不起作用解决之道

最近在参照某些例子学习react-native 开发ios和Android的app时,碰到如标题所示的问题:
ListView的属性flexWrap为wrap不起作用。
如下可以看到每一行的其实是有10个图标的,自动换行之后,第一页的下满三个不见了:

代码如下:
大家可以看:
flexDirection:'row',
flexWrap:'wrap',

采取了,横向,自动换行,效果是达到了了,可是,下面的换行后的图标确是不见了!!

import React,{ Component } from 'react';
import {
  AppRegistry,StyleSheet,Text,View,Image,ListView
} from 'react-native';

import Dimensions from 'Dimensions';
var {width,height} = Dimensions.get('window');

export default class TopListView extends Component{

    static defaultProps ={
        dataArr : []
    }

    constructor(props){
        super(props);
        var ds = new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2}); this.state={ dataSource:ds.cloneWithRows(this.props.dataArr),} } render() { return ( <ListView dataSource = {this.state.dataSource} renderRow={this.renderRow.bind(this)} contentContainerStyle={styles.contentViewStyle} scrollEnabled={false} /> ) } renderRow(rowData){ return ( <View style={styles.cellStyle}> <Image source={{uri:rowData.image}} style={{width:52,height:52}}/> <Text>{rowData.title}</Text> </View> ); } } const styles = StyleSheet.create({ contentViewStyle:{ flexDirection:'row',flexWrap:'wrap',// 屏幕宽度 width:width,},cellStyle:{ } });

踩坑之后的解决方法
解释原因:由于在rn 0.28之后的版本上官方已经修改flexWrap:'wrap'的工作方式了,之前版本的是flexWrap:'wrap'认的alignItems: 'stretch'是一起工作的;如果是0.28之后的版本,你需要加上alignItems: 'flex-start'
如下:

contentViewStyle:{ flexDirection:'row',alignItems:'flex-start',// 屏幕宽度 width:width,},

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐