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.

Poor performance with ScrollView's scrollY interpolation

See original GitHub issue

Description

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

  1. Create useAnimatedScrollHandler
  2. Bind scrollY to event.contentOffset.y
  3. Interpolate absolute positioned header’s (above ScrollView) translateY to the negative scrollY value
  4. 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:closed
  • Created 3 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
craftzdogcommented, May 16, 2022

scrollEventThrottle={16} solved in my case

0reactions
SudoPlzcommented, Sep 20, 2021

I still experience that issue in 2.2.2 (on iOS using Reanimated.createAnimatedComponent(MyScrollView). Shouldn’t that be fixed for versions above 2.0.0.alpha?

Read more comments on GitHub >

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

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