onScroll animation with useNativeDriver on iOS doesn't work after re-render
See original GitHub issueRepro: https://snack.expo.io/SkkqUA4KG Possibly same as: #12543
The conditions to reproduce seem to be:
- You have a ScrollView and are using an Animated.event onScroll
- You are on iOS with useNativeDriver: true
- A parent of a Animated.View that uses the animated contentOffset value re-renders (in this case, resulting in the child being unmounted and mounted again)
Expected result is that the Animated.View always animates based on the Animated.Value which is linked to the scroll position.
Actual result is that the scroll-linked animation works initially, but after the component that uses the animated value is destroyed and recreated, it doesn’t work. This only happens with the native driver. It also doesn’t happen if the same animated value is used continuously elsewhere (see comment in repro), so that could be a potential clue and workaround.
Environment
Environment:
OS: macOS High Sierra 10.13.3
Node: 9.6.1
Yarn: 1.5.1
npm: 5.6.0
Watchman: Not Found
Xcode: Xcode 9.1 Build version 9B55
Android Studio: Not Found
Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: https://github.com/expo/react-native/archive/sdk-25.0.0.tar.gz => 0.52.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:13
Top Results From Across the Web
Having a rendering issue with React-Native Animation
1 Answer 1 · The main problem is because you don't store the state of each card properly (if it is flipped or...
Read more >Using Native Driver for Animated
This means it does not work with PanResponder but does work with things like ScrollView#onScroll . Native Animated has also been part of...
Read more >this.props.onscroll is not a function, react native animated ...
onScroll is not a function, it's an object if you pass { useNativeDriver: true } ... This is a PureComponent which means that...
Read more >React native scrollview cannot scroll to bottom
Android ScrollView doesn't support nested scrolling by default. so, you must delay it after the animation. It is impressive thinking about its wide-ranging ......
Read more >Building a Smooth Image Carousel with FlatList in React Native
renderItem - Accepts a function that determines how each item is ... the current index via a React ref since we don't need...
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 Free
Top 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
Aha! I think I have an idea what’s going on. A bug in the native animation driver.
Background (gleaned from reading the source): All AnimatedValues driven by the native driver get marked as “native” AnimatedValues. Native AnimatedValues have “native tags” which are id numbers used to look up nodes in the value graph on the native side of things, but they only have these tags when “attached.” AnimatedValues become attached when they are consumed, directly or transitively, such as by an Animated.View as a prop or style prop, and are detached when they stop being used. When they start being used again, they are attached again, but with a fresh native tag.
So, my theory is that Animated.event is setting up drivers in native land that identify AnimatedValues by their native tag, and when that native tag changes, the drivers stop working.
A workaround is to make sure the AnimatedValues that are the target of the Animated.event are never detached, which can be done by passing them as pretty much any prop to any component, e.g.
dummyProp={myAnimatedValue}
on your ScrollView. 😃 As far as I can tell, this doesn’t result in any extra work being done, it just keeps the child count of your AnimatedValue from going to zero, so it stays in memory in native land and has a stable native tag.Yup, give it a shot
On Tue, Mar 13, 2018 at 6:25 PM fxwan notifications@github.com wrote: