ScrollTo does not work on reanimated ScrollView
See original GitHub issueWhen using scrollTo on a reanimated ScrollView ref, an error is thrown: “TypeError: node.scrollTo is not a function”. I have reproduced it in a snack:
https://snack.expo.io/@jacobarvidsson/2c7078
const App = () => {
const scrollViewRef = useRef(null);
useEffect(() => {
if (scrollViewRef.current) {
const node = scrollViewRef.current;
if (node) {
node.scrollTo({ x: 0, y: 0 });
}
}
}, [])
return (
<View style={styles.container}>
<Animated.ScrollView ref={scrollViewRef}>
<Text>Test</Text>
</Animated.ScrollView>
</View>
);
};
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6 (2 by maintainers)
Top Results From Across the Web
scrollTo | React Native Reanimated
Provides synchronous scroll on the UI thread to a given offset using an animated ref to a scroll view. This allows performing smooth...
Read more >Attach ref to Reanimated ScrollView to access .scrollTo
It seems getNode is not available. I was able to to do ref.current._component.scrollTo it was weird. – Noitidart. Apr 9, 2021 ...
Read more >Attach ref to Reanimated ScrollView to access .scrollTo- ...
React-native ScrollView scrollTo not working as it should · Detect scroll end event when calling scrollTo on ScrollView · How to access ref...
Read more >reanimated-masonry-list
The FlatList won't offer you to draw MansonryList because when you provide numColumns bigger than 1 , the native view will switch to...
Read more >Jelly Scroll with Reanimated 2 - YouTube
In this video, we are building the Jelly Scroll effect from the Cuberto agency with Reanimated v2 and v1.Wanna learn the fundamentals of ......
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
I’m facing the same issue. @jacobarvidsson did you find any workaround for this?
Edit: Actually the same problem occurs also when using default Animated API from react-native. The problem is that you get reference to the Animated component, not to the wrapped one. To access reference to ScrollView you can use
getNode
method. In your case it will look like this:Hi guys, you can solve it by using the getNode() method
There are two ways to solve this issue depending on how you are creating ref.-
The difference between the above two solution is , in one you can get the getNode() method inside the current and the other you can access it without current