首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >滚动上的React原生FlatList生成空格

滚动上的React原生FlatList生成空格
EN

Stack Overflow用户
提问于 2018-11-26 20:55:24
回答 4查看 2.3K关注 0票数 1

我试图通过FlatList加载大量数据,但我面临的问题是,在滚动过程中,它似乎是空白的,我在不同的地方也看到了这个问题,但没有一个人告诉我如何正确解决这个问题。

我通过API获取的数据

我当前的FlatList:

代码语言:javascript
运行
复制
<FlatList
      data={this.state.todayFixtures}
      renderItem={this.renderTournaments}
      extraData={this.state.refresh}
      keyExtractor ={(item, index) => item.tournamentId}
    />

和renderTournaments:

代码语言:javascript
运行
复制
renderTournaments(fix) {
return <FootballDetail key={fix.tournamentId} todayFixture={fix} />;
}

下面是FootballDetail:

代码语言:javascript
运行
复制
sadasd
class FootballDetail extends Component {
state = {
fixtureToday: []
}
componentWillMount() {
//console.log(this.props.todayFixture.item);
this.setState({fixtureToday: this.props.todayFixture.item[0].matches});
}
constructor(props){
 super(props)
}
_onPressButton(fixture) {
Alert.alert(fixture.teamA + " - " + fixture.teamB)
}
renderTodayFixtures() {
  const { status, teams, teamResult } = styles;
  return this.state.fixtureToday.map((fixture) =>
    <CardSection>
      <View style={status} >
        {CommonFunctions.getStatus(fixture)}
      </View>
      <TouchableHighlight underlayColor="white" style={teams} onPress={() 
      => { this._onPressButton(fixture) }}>
        <View>
          <Text>{fixture.teamA}</Text>
          <Text>{fixture.teamB}</Text>
        </View>
      </TouchableHighlight>
      <View style={teamResult}>
        <Text>{fixture.teamAResult}</Text>
        <Text>{fixture.teamBResult}</Text>
      </View>
      <View style={{ justifyContent: 'center' }}>
        <Image source={require('../assets/img/notification_tab.png')} style={{width: 22, height: 22}} />
      </View>
    </CardSection>
)
}
render () {
 return (
  <Card>
    <CardSection>
      <View>
        <Text style={styles.tournamentTxt}>{this.props.todayFixture.item[0].tournamentName}: {this.props.todayFixture.item[0].tournamentStage}</Text>
      </View>
    </CardSection>
    {this.renderTodayFixtures()}
  </Card>
  )
 }
}
EN

回答 4

Stack Overflow用户

发布于 2018-11-26 21:14:06

尝试玩FlatList的windowSize道具。如果这个值非常低,它可能会导致空白屏幕,如果这个值非常高,它可能会占用大量内存。

参考https://facebook.github.io/react-native/docs/virtualizedlist#windowsize

票数 0
EN

Stack Overflow用户

发布于 2018-11-28 15:30:47

当您大幅增加windowSize时,响应性可能会受到影响,因为呈现内容可能会干扰对按钮点击或其他交互的响应,因此最好采用一个适中的值,您可以对项目使用占位符,以便在加载数据之前,用户不会看到空白屏幕。

票数 0
EN

Stack Overflow用户

发布于 2019-02-08 17:09:01

为什么在你的keyExtractor道具上,如果你不使用index,你还要添加它?

您应该尝试将FootballDetail组件放到PureComponent

它将避免组件的重新渲染,并提高性能。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53481598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档