我试图通过FlatList加载大量数据,但我面临的问题是,在滚动过程中,它似乎是空白的,我在不同的地方也看到了这个问题,但没有一个人告诉我如何正确解决这个问题。
我通过API获取的数据
我当前的FlatList:
<FlatList
data={this.state.todayFixtures}
renderItem={this.renderTournaments}
extraData={this.state.refresh}
keyExtractor ={(item, index) => item.tournamentId}
/>和renderTournaments:
renderTournaments(fix) {
return <FootballDetail key={fix.tournamentId} todayFixture={fix} />;
}下面是FootballDetail:
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>
)
}
}发布于 2018-11-26 21:14:06
尝试玩FlatList的windowSize道具。如果这个值非常低,它可能会导致空白屏幕,如果这个值非常高,它可能会占用大量内存。
参考https://facebook.github.io/react-native/docs/virtualizedlist#windowsize
发布于 2018-11-28 15:30:47
当您大幅增加windowSize时,响应性可能会受到影响,因为呈现内容可能会干扰对按钮点击或其他交互的响应,因此最好采用一个适中的值,您可以对项目使用占位符,以便在加载数据之前,用户不会看到空白屏幕。

发布于 2019-02-08 17:09:01
https://stackoverflow.com/questions/53481598
复制相似问题