-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FlatList] onScroll's event is "stuttering" #14037
Comments
I have a similar issue. I have a header(Animated.View) that has an absolute position above the FlatList. When I tried to animate the header by onScroll of FlatList, the animation stuttered. I also tried useNativeDriver: true, but the problem remained same. |
I am having the same issues here. I'm animating an absolute header at the top by FlatList onScroll event and it's just not there. ScrollView is smooth butter. |
I migrated a This was very noticeable when testing my worst case scenario iOS device (iPhone 5S). Android didn't seem to suffer, but the test device is much more recent (Motorola G4 Plus). |
To fix this you need to set FlatList's However there is an issue where the value of I tested it in v0.45-rc2 and when setting |
Hey, thanks for reporting this issue! It looks like your description is missing some necessary information. Can you please add all the details specified in the template? This is necessary for people to be able to understand and reproduce the issue being reported. I am going to close this, but feel free to open a new issue with the additional information provided. Thanks! |
Hi! I think the issue has reappeared. However, in my case, both the Animated.ScrollView and Animated.FlatList has the same issue. I have opened an issue #15769 for this. |
|
Issue with RN 0.51 Using onScroll to animate an Header is not smooth on Android ONLY (emulator and real device). scrollY = new Animated.Value(0);
///...
// in render method:
const headerHeight = this.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [HEADER_MAX_HEIGHT, HEADER_MIN_HEIGHT],
extrapolate: 'clamp',
});
const titleTopPadding = this.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [HEADER_MAX_HEIGHT * 2 / 3, 0],
extrapolate: 'clamp',
});
const titleTextSize = this.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [32, 18],
extrapolate: 'clamp',
});
const listMarginTop = this.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [HEADER_MAX_HEIGHT, HEADER_MIN_HEIGHT],
extrapolate: 'clamp',
});
// jsx:
{/* header */}
<Animated.View style={[styles.header, { height: headerHeight }]}>
<View style={styles.bar}>
<Animated.Text
style={[
styles.title,
{
paddingTop: titleTopPadding,
fontSize: titleTextSize,
},
]}
>
{I18n.t('EVENTS_LIST')}
</Animated.Text>
</View>
</Animated.View>
{/* list */}
<Animated.View style={[styles.container, { marginTop: listMarginTop }]}>
<FlatList
data={events}
scrollEventThrottle={16}
onScroll={Animated.event([
{ nativeEvent: { contentOffset: { y: this.scrollY } } },
])}
keyExtractor={this.eventsKeyExtractor}
renderItem={this.renderEventsItem}
ListHeaderComponent={this.renderHeader}
indicatorStyle="default"
/>
</Animated.View/ |
I fixed my issue by:
// interpolations
const headerHeight = this.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [HEADER_MAX_HEIGHT, HEADER_MIN_HEIGHT],
extrapolate: 'clamp',
});
const titleTopPadding = this.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [HEADER_MAX_HEIGHT * 2 / 3, 0],
extrapolate: 'clamp',
});
const titleTextSize = this.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [32, 18],
extrapolate: 'clamp',
});
// returned jsx
{/* header */}
<Animated.View style={[styles.header, { height: headerHeight }]}>
<View style={styles.bar}>
<Animated.Text
style={[
styles.title,
{ paddingTop: titleTopPadding, fontSize: titleTextSize },
]}
>
{I18n.t('EVENTS_LIST')}
</Animated.Text>
</View>
</Animated.View>
{/* list */}
<Animated.View style={[styles.container]}>
<SectionList
data={events}
sections={[{ title: '', data: events }]}
scrollEventThrottle={1}
onScroll={Animated.event([
{ nativeEvent: { contentOffset: { y: this.scrollY } } },
// { useNativeDriver: true },
])}
keyExtractor={this.eventsKeyExtractor}
renderItem={this.renderEventsItem}
indicatorStyle="default"
renderSectionHeader={({ section }) => (
<View style={{ height: HEADER_MAX_HEIGHT }} />
)}
/>
</Animated.View> |
@MacKentoch your code works very well despite setting |
I'm trying to implement a ScrollView that animates the Y position of a slider.
My
ScrollView
is actually aFlatList
, and I'm usingonScroll
to animate the position of my slider.I tried to use a
Animated.View
and useposition.setValue
in theonScroll
event.I also tried to use
ref.setNativeProps
to see if that speeds things up a bit, but the result is exactly the same.It made me understand that it's not the animation that is slow, but the
onScroll
event that is "stuttering".Here's the result with a
ListView
(smooth as a baby's butt)And here's what's happening with
FlatList
It's even more striking when looking at the app at 60 fps.
Is there some kind of optimizations on
FlatList
that throttles theonScroll
event ? Maybe there is or there should be a way to opt-out of some of those ?The text was updated successfully, but these errors were encountered: