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

前端 未结 16 1309
误落风尘
误落风尘 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:41

    Here is the simplest solution I could muster:

      (this.listView = ref)}
    onLayout={event => {
        this.listViewHeight = event.nativeEvent.layout.height;
    }}
    onContentSizeChange={() => {
        this.listView.scrollTo({
            y: this.listView.getMetrics().contentLength - this.listViewHeight
        });
    }}
    />;
    

提交回复
热议问题