Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

React-native Flatlist, Run function when ScroolToTop or ScroolToBottom

I want to run function1() when scrollToTop and run function when scrollToBottom in flatlist. can i do that ?

  <FlatList
     
          data={data}
          keyExtractor={(key) => key.id}
          numColumns={2}
          renderItem={({ item, index }) => {
            return (
              <View
                style={{
                  alignItems: 'center',
                  justifyContent: 'center',
                  flex: 1,
                  marginTop: index == 0 || 1 ? 33 : 13,
                  paddingBottom: 20,
                }}
              >
                {selectCard(item)}
              </View>
            );
          }}
        />

thing what i want to do that, when i want to scrolldown in flatlist, i want to hide top bar and when i want to scrollup i want to show top bar.

question from:https://stackoverflow.com/questions/65916939/react-native-flatlist-run-function-when-scrooltotop-or-scrooltobottom

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This post answers your question. When the event.nativeEvent.contentOffset.y inside onScroll method be negative the FlatList is scrolling to the bottom and vice-versa.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...