参考文章:
1、https://medium.com/swlh/making-a-collapsible-sticky-header-animations-with-react-native-6ad7763875c3
2、https://github.com/netguru/sticky-parallax-header
最终实现方案,利用FlatList的stickyHeaderIndices属性,android和ios测试都能实现悬浮tab,重要是必要赋值第一个为空对象用来存放tab;缺点不能实现左右水平切换tab分页。参考代码如下:
this.state = {
tabIndex: 0,
refreshing: false,
dataList: [{}]
};
每次更新数据需要数组第一个加入空对象:
this.setState({
refreshing: false,
dataList: [{}].concat(cacheList)
});
<FlatList
style={{ flex: 1 }}
showsVerticalScrollIndicator={false}
ListHeaderComponent={this.renderListHeader()}
stickyHeaderIndices={[1]}
data={dataList}
renderItem={({ item, index }) => {
return <View>{index == 0 ? <View style={{ backgroundColor: '#FF0', height: 50 }} /> : <Goods item={item} />}</View>
}}
ListFooterComponent={this.renderNetWorkError()}
keyExtractor={(__, k) => `${k}`}
onRefresh={this.onRefresh}
onEndReached={this.onEndReached}
refreshing={refreshing}
onEndReachedThreshold={10} />
网友评论