Poor performance with ScrollView's scrollY interpolation
See original GitHub issueDescription
I’m interpolating on the ScrollView’s scrollY
SharedValue to move my absolute positioned header around, and it has a noticeable delay (lag) when the user scrolls.
Screenshots
Here is a video demo (can’t upload here because file too large)
Steps To Reproduce
- Create
useAnimatedScrollHandler
- Bind
scrollY
toevent.contentOffset.y
- Interpolate absolute positioned header’s (above ScrollView)
translateY
to the negativescrollY
value - Notice that the header doesn’t move synchronized with the ScrollView, but rather lags behind
Expected behavior
I expect the header to move synchronously with the scroll view so it looks like one piece
Actual behavior
The header lags behind and looks like it has weight
Snack or minimal code example
const scrollY = useSharedValue(0);
const onScroll = useAnimatedScrollHandler({
onScroll: (event) => {
scrollY.value = event.contentOffset.y;
},
});
// ...
const headerY = useDerivedValue(() => {
return interpolate(scrollY.value, [0, HEADER_IMAGE_HEIGHT + 30], [0, -(HEADER_IMAGE_HEIGHT + 30)], Extrapolate.CLAMP);
});
const headerStyle = useAnimatedStyle(() => ({ transform: [{ translateY: headerY.value }] }));
// ...
return (
<Reanimated.ScrollView
scrollEventThrottle={1}
onScroll={onScroll}
...>
{/* ... */}
</Reanimated.ScrollView>
<Reanimated.View style={[styles.imagesContainer, headerStyle]}>
{/* children like image goes here */}
</Reanimated.View>
);
// ...
const styles = StyleSheet.create({
imagesContainer: {
position: 'absolute',
top: 0,
left: 0,
height: HEADER_IMAGE_HEIGHT,
width: SCREEN_WIDTH,
}
});
Package versions
- React: 16.13.2
- React Native: 0.63.2
- React Native Reanimated: 2.0.0-alpha.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
React Native : Bad performance animating the height of a view ...
the solution is to set Header position to absolute, i don't know why but it's working fine : import * as React from...
Read more >Ways to optimize scroll performance. Yes, after having a zillion ...
First of all, quick note about scroll views. As you all know, scrolling is not an animation. Scroll view works by just changing...
Read more >Scroll view 2D
Sets the acceleration of the node controlled by a Scroll View node while you drag that Scroll View node. Use low values when...
Read more >Wrap content inside a scroll view - Unity - Manual
However, the instructions on styling the scroll view also apply to runtime UI. Example overview. This example creates a custom Editor window with...
Read more >Reanimating Your React Native Experience | blog {callstack}
First, we need to figure out how to detect that we've finished scrolling. There are 2 callbacks provided by the ScrollView< component that...
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
scrollEventThrottle={16}
solved in my caseI still experience that issue in
2.2.2
(on iOS usingReanimated.createAnimatedComponent(MyScrollView)
. Shouldn’t that be fixed for versions above 2.0.0.alpha?