我正在尝试在react-native中实现 anchor 滚动。 我可以通过使用ScrollView 和scrollTo 来做到这一点。
根据react-native's documentation scrollTo 方法不应在 ScrollView 中使用(已弃用)。
scrollTo 方法是否有其他替代方法来实现类似的功能?
最佳答案
实际上,scrollTo
并没有真正被弃用。
但是 scrollTo(([y]: number), object, ([x]: number), ([animated]: boolean))
是。
因此,您应该只使用 scrollTo({x: 0, y: 0,animated: true})
并将单个对象作为参数。
您提供的链接中有说明: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.
也许它具有误导性,但它只是带有单独参数的替代方案,已被弃用。
关于javascript - react native ScrollView 中的scrollTo 的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52967134/