Reputation: 441
I am trying to implement anchor scrolling in react-native. I am able to do so by using ScrollView and scrollTo.
According to react-native's documentation scrollTo method should not be used in ScrollView(deprecated).
Is there any alternative for the scrollTo method to achieve similar functionality?
Upvotes: 0
Views: 1832
Reputation: 1217
Actually, scrollTo
is not really deprecated.
But scrollTo(([y]: number), object, ([x]: number), ([animated]: boolean))
is.
Thus you should just use scrollTo({x: 0, y: 0, animated: true})
with a single object as parameter.
It is stated in the link you provided: https://facebook.github.io/react-native/docs/scrollview#scrollto:
The weird function signature is due to the fact that, for historical reasons, the function also accepts separate arguments as an alternative to the options object. This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.
Perhaps it is misleading but it's only the alternative with separate arguments which is deprecated.
Upvotes: 2