加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – 使用ListHeaderComponent在FlatList的屏幕中央

发布时间:2020-12-15 20:44:02 所属栏目:百科 来源:网络整理
导读:我使用的是React-Native版本0.43.0,它不支持FlatList的ListEmptyComponent.因此,当列表为空时,我使用ListHeaderComponent渲染视图, import React,{ Component } from 'react';import { Text,View,StyleSheet,FlatList } from 'react-native';class App exten
我使用的是React-Native版本0.43.0,它不支持FlatList的ListEmptyComponent.因此,当列表为空时,我使用ListHeaderComponent渲染视图,
import React,{ Component } from 'react';
import { Text,View,StyleSheet,FlatList } from 'react-native';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      listData: []
    }
  }
  render() {
    return (
      <View style={styles.container}>
        <FlatList
          renderItem={() => null}
          data={this.state.listData}
          ListHeaderComponent={() => (!this.state.listData.length? 
            <Text style={styles.emptyMessageStyle}>The list is empty</Text>  
            : null)
          }
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex:1
  },emptyMessageStyle: {
    textAlign: 'center',//My current hack to center it vertically
    //Which does not work as expected
    marginTop: '50%',}
});

As you can see from the image the text is not centered vertically

知道如何在FlatList中垂直居中吗?

我已经尝试过应用justifyContent,alignItems等但没有用.

这是snack.expo – https://snack.expo.io/S16dDifZf的链接

他们在这个pr https://github.com/facebook/react-native/pull/18206中修复了ListEmptyComponent.但它们将以0.56发货.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读