Skip to content

Wrong initial state using useNativeDriver: true and production bundle #16003

@ferrannp

Description

@ferrannp

Is this a bug report?

Yes.

Have you read the Contributing Guidelines?

Yes.

Environment

  1. react-native -v: 0.48.3
  2. node -v: 8.4.0
  3. npm -v: 5.4.2
  4. yarn --version: 1.0.2

Then, specify:

  • Target Platform: Android O

  • Development Operating System: macOS

Steps to Reproduce

  1. Use onScroll event on FlatList
onScroll={Animated.event(
  [{ nativeEvent: { contentOffset: { y: scrollY } } }],
  { useNativeDriver: true }
)}
  1. Use the value for some interpolations:
const imageTranslate = scrollY.interpolate({
  inputRange: [0, bannerHeight],
  outputRange: [0, -bannerHeight],
  extrapolate: 'clamp',
});

const opacityInterpolator = scrollY.interpolate({
  inputRange: [bannerHeight-56-24-24, bannerHeight-56-24],
  outputRange: [0, 1],
  extrapolate: 'clamp',
});

const fontScale = scrollY.interpolate({
  inputRange: [0.0, bannerHeight-56-24],
  outputRange: [1.5, 1.0],
  extrapolate: 'clamp',
});

const fontTranslateX = scrollY.interpolate({
  inputRange: [0, bannerHeight-56-24],
  outputRange: [0, -24],
  extrapolate: 'clamp',
});

const fontTranslateY = scrollY.interpolate({
  inputRange: [0, bannerHeight - 56 - 24],
  outputRange: [0, -bannerHeight + 56 + 24],
  extrapolate: 'clamp',
});
  1. Apply them to Animated.View and Animated.Text. With state scrollY: new Animated.Value(0), the View should have 0 opacity and the text should be big (initial state).

Expected Behavior

See gif:

expected

Actual Behavior

actual

The issue happens only in production and in my real device (Nexus 5X) which is now using Android O. I cannot reproduce it in Genymotion. Initial state is wrong and it goes ok just when touching and scrolling a bit.

Temporal solution

this.state = {
  scrollY: new Animated.Value(0),
  useNativeDriver: true,
};

componentDidMount() {
  setTimeout(() => this.setState({ useNativeDriver: true }), 10);
}

Metadata

Metadata

Labels

Issue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.StaleThere has been a lack of activity on this issue and it may be closed soon.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions