Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know the state of scroll in FlatList?

Tags:

react-native

How to know the state of scroll in FlatList? Such as startScroll、Scrolling、endScroll

<FlatList
    onScroll={(e) => { }}
/>

there is onScroll mothed,but it only run when Scrolling. I want to listen scroll start and end,how can i do ?

I also tried use TouchableWithoutFeedback:

<TouchableWithoutFeedback
    onPressIn={() => console.log('in')}
    onPressOut={() => console.log('out')}>
    <View><FlatList/></View>
</TouchableWithoutFeedback>

But touch events will be intercepted by TouchableWithoutFeedback, FlatList can't scroll.

like image 473
Xzin Avatar asked May 08 '17 08:05

Xzin


People also ask

How do I get current scroll position React Native?

To get the current scroll position of ScrollView in React Native, we can set the onScroll prop of the ScrollView to a function that takes the scroll event object as an argument.

How do I scroll to the end of FlatList?

To scroll to end of FlatList after displaying the keyboard with React Native, we can set the onLayour prop to a function that calls scrollToEnd on the FlatList's ref. to set onLayout to a function that calls flatListRef. current. scrollToEnd to scroll the FlatList to the end.

Is FlatList scrollable?

Flatlist: The FlatList Component is an inbuilt react-native component that displays similarly structured data in a scrollable list. It shows only those elements that are currently being displayed on the screen.

How do you keep the scroll position with FlatList?

In Flatlist set scrollsToTop={false} this will retain position when you navigate back from detail screen. I am using Expo version 25.


1 Answers

since Flatlist inherits all ScrollView props, you can use onScrollEndDrag and onScrollBeginDrag to solve this issue:

<FlatList
    onScrollEndDrag={() => console.log("end")}
    onScrollBeginDrag={() => console.log("start")}/>

further information.

like image 129
Xzin Avatar answered Sep 19 '22 16:09

Xzin