我在React Native屏幕上工作。它有两个选项卡。我们将其命名为Tab 1
和Tab 2
每个标签都会显示一个Flatlist,其中包含该标签专用的数据。
我控制每个Flatlist的显示或隐藏。
这是奇怪的行为:
Tab 1
是显示的默认设置。 Flatlist 1
Tab 2
,显示Flatlist 2
Tab 1
,滚动位置将回到列表的开头! 该如何解决?
这是我的render()的回报:
// Need to have two different components (and show/hide them accordingtly)
// so that they each maintain their own scroll position, etc.
const youActivityStyle = activityTabIndex === 0 ? { display: 'flex' } : {display: 'none'}
const followingActivityStyle = activityTabIndex === 0 ? { display: 'none'} : {display: 'flex' }
return (
<React.Fragment>
<View style={youActivityStyle}>
<FlatList
data={activityDataMe}
renderItem={this.renderItem}
keyExtractor={this.activityKeyExtractor}
ListHeaderComponent={this.renderHeader}
ListFooterComponent={this.renderFooter}
contentContainerStyle={styles.flatListContentContainerStyle}
onRefresh={this.onRefresh}
refreshing={activityRefreshing}
onEndReached={this.flatListOnEndReached}
onEndReachedThreshold={0.5}
onMomentumScrollBegin={this.flatListOnMomentumScrollBegin} />
</View>
<View style={followingActivityStyle}>
<FlatList
data={activityDataFollowing}
renderItem={this.renderItem}
keyExtractor={this.activityKeyExtractor}
ListHeaderComponent={this.renderHeader}
ListFooterComponent={this.renderFooter}
contentContainerStyle={styles.flatListContentContainerStyle}
onRefresh={this.onRefresh}
refreshing={activityRefreshing}
onEndReached={this.flatListOnEndReached}
onEndReachedThreshold={0.5}
onMomentumScrollBegin={this.flatListOnMomentumScrollBegin} />
</View>
</React.Fragment>
)