Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flatlist scroll position onScroll

Tags:

react-native

I am building a header that animates/hides as the user scrolls down a Flatlist. Is there any way to find out the scroll position of the Flatlist in pixels?

I'm using react native 0.59.8. I've tried using onScroll hoping it passes a value to the callback - it doesn't. I've also tried onScrollBeginDrag, onScrollEndDrag and onMomentumScrollEnd.. None of them provide information of the current scroll position.

onSroll={(info)=>{console.log(info)}

I would expect to get some information about the scroll, but none is passed.

like image 352
SirCameron Avatar asked May 15 '26 20:05

SirCameron


1 Answers

Use:

<FlatList onScroll={this.handleScrollView} />

e.g.

handleScrollView: function(event: Object) {
 this.setState({ scrollPosition: event.nativeEvent.contentOffset.y });
}
like image 133
Kirtan Dudhat Avatar answered May 18 '26 09:05

Kirtan Dudhat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!