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

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

    Actually @Aniruddha answer doesn't worked for me because I'm using "react-native": "0.59.8" and this.scrollView.root.scrollToEnd also is undefined

    but I figured it out and this works this.scrollView.scrollResponderScrollToEnd({animated: true});

    If you are using 0.59.8 this will work OR if you are using later version and this works for you. please add versions in this answer so others wont get trouble.

    Full Code here

     this.scrollView = ref}
        onContentSizeChange={(contentWidth, contentHeight)=>{        
            this.scrollView.scrollResponderScrollToEnd({animated: true});
        }}>
    
    

提交回复
热议问题