I am using scrollTo along with animation. I want run a function after the animation is finished. How can I do that?
ref.current.scrollToOffset({ animated: true, offset: 0 })
I am using scrollTo along with animation. I want run a function after the animation is finished. How can I do that?
ref.current.scrollToOffset({ animated: true, offset: 0 })
2
Answers
New answer
To run a function after the scroll animation is finished, you have to use the
onScrollAnimationEnd
in case you’re using a FlatList or ScrollView.For example:
Simply as that.
Old answer
Since the question did not have a lot of information, I thought the question was about an standalone animation, then I replied this:
If you’re using the normal React Native Animated you can simply achieve that by adding a callback to the
.start()
function:From the docs:
I can’t find anything about it in the docs in current latest version 0.71.
However, there’s seems to be a workaround.
If you can keep track of the position and listen to onScroll event of ScrollView, then it can be done.
Here is the example code.(Click the button to test)
Note: You may need to click again if first time click doesn’t work.