我遇到一个问题,在页面上有一个页眉,一个滚动选项卡,其主要内容是两个FlatList。 我使用动画,让页眉位于单个视图中,并使用绝对布局。此解决方案有问题,FlatList无法滚动,它只能滚动scrollView。当数据增长时,性能会变差。
这是解决方案代码:
<Animated.View style={{
width: "100%",
position: "absolute",
transform: [{
translateY: this.headerY
}],
backgroundColor:'red',
top: 50,
elevation: 0,
flex: 1,
zIndex: this.state.pullToRefresh ? -1 : 1,
}}>
<HeaderView />
</Animated.View>
<Animated.ScrollView
scrollEventThrottle={1}
bounces={false}
showsVerticalScrollIndicator={false}
style={{ zIndex: 0, height: DeviceUtils.deviceHeight, elevation: -1,
overflow: 'scroll' }}
contentContainerStyle={{ paddingTop: NAVBAR_HEIGHT }}
onScroll={
Animated.event(
[{ nativeEvent: { contentOffset: { y: this.scroll } } }],
{ useNativeDriver: true },
)
}
overScrollMode="never"
/>}
>
<Tabs
initialPage={0}
renderTabBar={(props) =>
<Animated.View
style={[{
transform: [{ translateY: tabY }],
zIndex: 1,
width: "100%",
}]}>
<ScrollableTab
{...props}
style={{ backgroundColor: '#e5e5e5'}}
underlineStyle={{
backgroundColor: "#2a82e4",
}}
>
</ScrollableTab>
</Animated.View>
}
>
<Tab heading={"one"}
<FlatList key={'one'}/>
</Tab>
<Tab heading={"two"}
<FlatList key={'two'}/>
</Tab>
</Tabs>
UI使用nativebase UI库
答案 0 :(得分:0)
最后,我将标题放入FlatList ListHeader中。并根据项目索引 呈现选项卡,当索引为0时,呈现选项卡。
<FlatList
data={DATA}
renderItem={this.renderItem}
keyExtractor={item => item.id}
ListHeaderComponent={header}
extraData={selected}
/>
....
renderItem = (item,index) => {
if(index == 0) {
return this.renderTabs()
} else {
return <Cell data=item/>
}
}
...
renderTabs = () => {
<View>
<Tab/> // the view for tabs, we have to handle the tab change by ourself
<Tab/>
</View
}
I use two data array to save for different tabs.