Performance drop using useAnimatedScrollHandler
See original GitHub issueDescription
I am noticing quite a considerable amount of lost frames when using the new useAnimatedScrollHandler hook as opposed to the ReanimatedV1 method, it is especially noticeable when pulling down on iOS and letting go to have the bounce back effect, or scrolling quickly.
Steps To Reproduce
reanimatedV2
import React from 'react';
import { Dimensions, View } from 'react-native';
import Animated, {
useAnimatedScrollHandler,
useAnimatedStyle,
useSharedValue,
} from 'react-native-reanimated';
const { width } = Dimensions.get('window');
export default function Facets() {
const translationY = useSharedValue(0);
const scrollHandler = useAnimatedScrollHandler((event) => {
translationY.value = event.contentOffset.y;
});
const stylez = useAnimatedStyle(() => {
return {
transform: [
{
translateY: -translationY.value,
},
],
};
});
return (
<View style={{ flex: 1 }}>
<Animated.View
style={[stylez, { position: 'absolute', zIndex: 10, width, height: 200, backgroundColor: 'red' }]}
/>
<Animated.ScrollView
contentContainerStyle={{ paddingBottom: 50, paddingTop: 150 }}
onScroll={scrollHandler}
scrollEventThrottle={1}
>
<View style={{ height: 1000, width }} />
</Animated.ScrollView>
</View>
);
}
reanimatedV1
import React from 'react';
import { Dimensions, View } from 'react-native';
import Animated from 'react-native-reanimated';
const { width } = Dimensions.get('window');
export default function Facets() {
const scrollOffset = React.useRef(new Animated.Value(0));
const stylez = {
transform: [{ translateY: Animated.multiply(scrollOffset.current, -1) }],
};
return (
<View style={{ flex: 1 }}>
<Animated.View
style={[stylez, { position: 'absolute', zIndex: 10, width, height: 200, backgroundColor: 'red' }]}
/>
<Animated.ScrollView
contentContainerStyle={{ paddingBottom: 50, paddingTop: 150 }}
onScroll={Animated.event([{ nativeEvent: { contentOffset: { y: scrollOffset.current } } }])}
scrollEventThrottle={1}
>
<View style={{ height: 1000, width }} />
</Animated.ScrollView>
</View>
);
}
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:6 (4 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 >Animated Collapsible Header Using React Native Reanimated 2
The reason we see frame drops by using react-native's built-in ... useAnimatedScrollHandler This is a convenience hook that returns an event ...
Read more >React Native Reanimated | FlashList - Shopify
React Native Reanimated is an alternative animation library to the LayoutAnimation API provided by React Native.
Read more >Getting started with Reanimated 2 for React native Part-1
Reanimated saves us from the frame drop hell in react native ... useSharedValue(0);const scrollHandler = useAnimatedScrollHandler({
Read more >React Native Animations: a Guide on Creating ... - UpsilonIT
Learn how to make animations in React Native using Reanimated 2 in this guide. ... are easier to use and run on the...
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
is there a callback or listener to useAnimatedScrollHandler in ReaminatedV2? Like we have in regular Animated:
Yep, Terry is right. You can try using prebuilt package (under NOTE section) but please, try it tomorrow 😄 We had some problems with creating the package due to case-sensitivity issues and it should be resolved in the next build.
Closing this for now, feel free to reopen if update doesn’t fix it.