Is it possible to keep a ScrollView scrolled to the bottom?

前端 未结 16 1325
误落风尘
误落风尘 2020-12-04 17:13

For a chat-like app, I want to keep a ScrollView component scrolled to the bottom, because newest messages appear under the older ones. Can we adjust the scroll

16条回答
  •  一个人的身影
    2020-12-04 17:43

    Use onContentSizeChange to keep track of the bottom Y of the scroll view (height)

    https://facebook.github.io/react-native/docs/scrollview.html#oncontentsizechange

    var _scrollToBottomY
    
    {
        _scrollToBottomY = contentHeight;
        }}>
    
    

    then use the ref name of the scroll view like

    this.refs.scrollView.scrollTo(_scrollToBottomY);
    

提交回复
热议问题