useAnimatedScrollHandler not working with <FlatList>
See original GitHub issueDescription
The events onBeginDrag
, onEndDrag
, onMomentumBegin
, and onMomentumEnd
don’t fire for my FlatList (created with Reanimated.createAnimatedComponent(FlatList)
). Only onScroll
works.
Screenshots
Steps To Reproduce
- Create animated FlatList using
Reanimated.createAnimatedComponent(FlatList)
- Create handler using
useAnimatedScrollHandler
:
const onScroll = useAnimatedScrollHandler<{ beginY?: number; endY?: number }>({
onScroll: (event, context) => {
Logger.debug(`[SCROLL] SCROLL! ${event.contentOffset.y}`);
scrollY.value = event.contentOffset.y;
},
onBeginDrag: (event) => {
Logger.debug(`[SCROLL] BEGIN DRAG! ${event.contentOffset.y}`);
},
onEndDrag: (event) => {
Logger.debug(`[SCROLL] END DRAG! ${event.contentOffset.y}`);
},
onMomentumBegin: (event) => {
Logger.debug(`[SCROLL] BEGIN MOMENTUM! ${event.contentOffset.y}`);
},
onMomentumEnd: (event) => {
Logger.debug(`[SCROLL] END MOMENTUM! ${event.contentOffset.y}`);
},
});
- Add to
FlatList
:<ReanimatedFlatList onScroll={onScroll} ... />
- See only
SCROLL!
in console, no begin/end events
Expected behavior
I expect the begin and end events to fire
Actual behavior
They don’t fire
Snack or minimal code example
const onScroll = useAnimatedScrollHandler<{ beginY?: number; endY?: number }>({
onScroll: (event, context) => {
Logger.debug(`[SCROLL] SCROLL! ${event.contentOffset.y}`);
scrollY.value = event.contentOffset.y;
},
onBeginDrag: (event) => {
Logger.debug(`[SCROLL] BEGIN DRAG! ${event.contentOffset.y}`);
},
onEndDrag: (event) => {
Logger.debug(`[SCROLL] END DRAG! ${event.contentOffset.y}`);
},
onMomentumBegin: (event) => {
Logger.debug(`[SCROLL] BEGIN MOMENTUM! ${event.contentOffset.y}`);
},
onMomentumEnd: (event) => {
Logger.debug(`[SCROLL] END MOMENTUM! ${event.contentOffset.y}`);
},
});
And
return <ReanimatedFlatList onScroll={onScroll} ... />
Package versions
- React: 16.13.1
- React Native: 0.63.2
- React Native Reanimated: 2.0.0-alpha.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
useAnimatedScrollHandler | React Native Reanimated
This is a convenience hook that returns an event handler reference which can be used with React Native's scrollable components.
Read more >how to implement the image rotary using flatlist in react native?
You can use reanimated, Flatlist achieve the animation: ... { useSharedValue, useAnimatedScrollHandler, useAnimatedStyle, interpolate, ...
Read more >React Native Reanimated 2 - Collapsing Header + FlatList Tips
Recently, I have been trying to animate a dynamic header like AirBnb has using React Native Reanimated 2. The Problem While I have ......
Read more >FlatList Animations in React Native with Reanimated 2
In this tutorial, we will implement FlatList animations in React Native ... technology choices expressed in this video are my own and do...
Read more >React Native FlatList Animation - The Javascript
import Animated, { interpolate, interpolateColor, useAnimatedScrollHandler, useAnimatedStyle, useSharedValue, withSpring, withTiming } from ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can safely use 1 or even 16 instead.
I’ve managed to get it working now (alpha7). No idea what the issue was, maybe it was some sort of cache issue (hot reload, metro, babel, whatever). Closing this