question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useAnimatedScrollHandler not working with <FlatList>

See original GitHub issue

Description

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

  1. Create animated FlatList using Reanimated.createAnimatedComponent(FlatList)
  2. 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}`);
	},
});
  1. Add to FlatList: <ReanimatedFlatList onScroll={onScroll} ... />
  2. 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:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
terrysahaidakcommented, Sep 19, 2020

You can safely use 1 or even 16 instead.

1reaction
mrousavycommented, Sep 24, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found