react-native项目,Flatlist组件封装后,引用时在页面中不渲染。
之前子组件是这样写的
render() {
const { evaluationAllList } = this.props.evaluationReducer;
console.log("evaluationAllList",evaluationAllList);
return (
<View>
<FlatList
style={{flex: 1}}
data={evaluationAllList}
renderItem={this._renderItem}
showsVerticalScrollIndicator={false}
keyExtractor={(item, index) => index.toString()}
refreshControl={
<RefreshControl
tintColor="#2b2b2b"
refreshing={this.state.loadinging}
colors={['#2b2b2b', '#2b2b2b', '#2b2b2b']}
onRefresh={() => {
this._queryEvaluationList();
}}
/>
}
onEndReachedThreshold={0.01}
onEndReached={() => this._onLoadMore()}
ListEmptyComponent={() => this._returnEmptyComponent()}
ListFooterComponent={this._createListFooter()}
/>
</View>
);
之前父组件引用是这样的
<View style={styles.commonStyle}>
<Text style={styles.comItem}>最新评论:</Text>
<EvaluationItem communityCode={communityCode}></EvaluationItem>
</View>
commonStyle样式
commonStyle: {
backgroundColor:'#ffffff',
marginTop:px2dp(30),
borderRadius:px2dp(10),
paddingBottom:px2dp(40),
},
更改后:
子组件 将Flatlist的 style={{flex: 1}} 放到外部View中
render() {
const { evaluationAllList } = this.props.evaluationReducer;
console.log("evaluationAllList",evaluationAllList);
return (
<View style={{flex: 1}}>
<FlatList
data={evaluationAllList}
renderItem={this._renderItem}
showsVerticalScrollIndicator={false}
keyExtractor={(item, index) => index.toString()}
refreshControl={
<RefreshControl
tintColor="#2b2b2b"
refreshing={this.state.loadinging}
colors={['#2b2b2b', '#2b2b2b', '#2b2b2b']}
onRefresh={() => {
this._queryEvaluationList();
}}
/>
}
onEndReachedThreshold={0.01}
onEndReached={() => this._onLoadMore()}
ListEmptyComponent={() => this._returnEmptyComponent()}
ListFooterComponent={this._createListFooter()}
/>
</View>
);
父组件的样式加了个flex:1
commonStyle: {
flex:1,
backgroundColor:'#ffffff',
marginTop:px2dp(30),
borderRadius:px2dp(10),
paddingBottom:px2dp(40),
},
就显示出来啦,但只显示指定高度的一丢丢,后来我在父组件外部加了ScrollView,但ScrollView套在Flatlist外面是有问题的,会报黄字VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead.
目前先这样写,等我知道怎么解决了再补充。