react-native-reanimated: Animated ScrollView _this.props.OnScroll is not a function
Description
I would like to animate a React Navigation header based on scrolling an Animated.ScrollView. Initially this works perfect. Although, when developing and the application is hot reloading, the scrolling seems to breaks. It looks like the props.onScroll method all of a sudden removed from the ScrollView (see screenshot).
It’s hard to debug what to do about this, so I was hoping anyone here has any clue?
In the repository these are the relevant files:
Expected behavior
On refresh (Hot Reload) the scroll behaviour should be exactly the same as before hot reloading.
Actual behavior & steps to reproduce
- Download the repo
npm install && cd ios && pod install- Open xcode
- Run project in simulator with scheme “Test - Debug”
- On the Onboarding screen press “Go”
- Next page “Dashboard” is as explained above
Snack or minimal code example
See the repository, branch moti-tryout
Package versions
- React Native: “react-native”: “0.65.1”,
- React Native Reanimated: “react-native-reanimated”: “2.2.2”,
- NodeJS: v14.16.0
- Xcode: Version 13.0 (13A233)
- Java & Gradle: - (only iOS for now)
React Navigation:
- “@react-navigation/bottom-tabs”: “6.0.7”,
- “@react-navigation/native”: “6.0.4”,
- “@react-navigation/stack”: “6.0.9”,
Affected platforms
- Android
- iOS
- Web
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 15
Check if you’re importing Animated from react-native-reanimated and not react-native. After changing that I stopped getting this error.
For those facing the same issue recently, try to set
useNativeDriverto false inAnimated.event’s config like this:This solved the issue on my side, but I don’t know what triggered this exactly.
it’s a default export so you have to do something like this :
import Animated, { useAnimatedScrollHandler, useAnimatedStyle, useSharedValue, withSpring, withTiming } from 'react-native-reanimated'or just
import Animated from 'react-native-reanimated'Here’s one case that can lead into this error :
Here SectionList is from react-native but the scroll handler is from react-native-reanimated so it will throw an error
I just had this error with
Animated.FlatList. I updated the package to2.4.1, tried creating animated component with Animated.createAnimatedComponent but it still didn’t work. I tried using multiple events likeconst scrollHandler = useAnimatedScrollHandler({ onScroll: event => { scrollY.value = event.contentOffset.y; }, onBeginDrag: e => { scrollY.value = true; }, onEndDrag: e => { scrollY.value = false; } });and tried using single
onScrollevent but still, I got this error. I didn’t try it onScrollViewsince I really depend onpullToRefreshandonEndReachedwhichScrollViewdoesn’t have. The only thing I was able to find is thatuseAnimatedScrollHandlerreturns an object instead of a function which creates this error. When I tried logging the object I got this:{"current": {"eventNames": ["onScroll"], "listeners": {}, "reattachNeeded": false, "registrations": [], "viewTag": undefined, "worklet": [Function _f]}}Maybe someone can elaborate what is going on and help with the issue. Thanks in advance.
Make sure to import
Animatedfromreact-native-reanimatedinstead ofreact-native!Use <Animated.ScrollView> instead of just regular ScrollView
Tip: Make sure the component you’re using
onScrollcomes fromAnimated(ref)