scrollTo is undefined on animated ScrollView

前端 未结 5 1856
不知归路
不知归路 2021-02-02 08:03

When using Animated.createAnimatedComponent(ScrollView) to create an animated ScrollView it\'s not longer possible to use scrollTo.

<
5条回答
  •  有刺的猬
    2021-02-02 08:24

    @max23_ 's answer might work for now, but is not the correct way of doing it - as a rule of thumb, we should never access private variables directly as these are often subject to change. (edit: no disrespect :-) )

    Due to this pull request, the new and future-proof way of getting the wrapped component's ref is to use the getNode() utility method, as accessing private variables (prepended with _) is not safe from future API changes.

    So, the new way of doing it is

    ref={c => (this.myRef = c)}
    

    and then when calling the method, doing

    this.myRef.getNode().scrollTo({
      y: 0,
      animated: true,
    });
    

    :-)

提交回复
热议问题