简体   繁体   English

React Native FlatList 滚动事件不起作用

[英]React Native FlatList scroll event doesn't work

This is my structure.这是我的结构。 Inside is a tab view with 3 screens.里面是一个带有 3 个屏幕的选项卡视图。 Each screen has a FlatList, the problem is here, the onEndReached of FlatList cannot be triggered ...每个屏幕都有一个FlatList,问题就在这里,FlatList的onEndReached无法触发...

<ScrollView
    showsVerticalScrollIndicator={false}
    stickyHeaderIndices={[1]}
    endFillColor='#fff'
>
    <AddrTop address={address} />
    <HomeInput />     
    <Carousel />
    <TabBar />
    <MemberBenefit />
    <PreferentialArea />
    <HomeList /> 
</ScrollView>

HomeList , use react-native-tab-view HomeList ,使用 react-native-tab-view

  <TabView
            navigationState={{index, routes}}
            renderScene={renderScene}
            onIndexChange={setIndex}
            renderTabBar={TabBar}
            lazy
            removeClippedSubviews
        />

screen屏幕

  <FlatList
            style={{marginTop: 5}}
            data={list}
            renderItem={({item}) => <ListItem data={item} />}
            keyExtractor={((item, index) => index.toString())}
            onEndReached={() =>console.log('cannot trigger)}
        />

As per React-Native Docs , onEndReached is called once when the scroll position gets within onEndReachedThreshold of the rendered content.根据 React-Native Docswhen the scroll position gets within onEndReachedThreshold of the rendered content.onEndReached被调用一次when the scroll position gets within onEndReachedThreshold of the rendered content.

So, you'll need to add onEndReachedThreshold as well.因此,您还需要添加onEndReachedThreshold

Something like就像是

<FlatList
    onEndReached={() => console.log('onEndReached')}
    onEndReachedThreshold={0.5}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM