the scroll tab in the scrollView, which content is flatlist and has a header, how to resolve scroll conflict

情到浓时终转凉″ 提交于 2020-01-06 04:43:15

问题


I meet a problem, on the page it has a header, a scroll tab which the main content is two FlatList. I use animation, let the header in a single view and use absolute layout. this solution has a problem, the FlatList can not scroll, it only scrolls the scrollView. when the data grow, the performance is bad.

t it is the solution code:

         <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>

the UI use nativebase UI library


回答1:


Finally, I put the header in the FlatList ListHeader. and according to the item index to render the tabs, when the index is 0, render the tabs.

 <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.



来源:https://stackoverflow.com/questions/58074258/the-scroll-tab-in-the-scrollview-which-content-is-flatlist-and-has-a-header-ho

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!