Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to load a ScrollView from the bottom

I have the following ScrollView. I would like it to initially load content from the bottom, showing the last elements first so that you first scroll from bottom upwards :

<ScrollView
  vertical
  showsVerticalScrollIndicator={false}
  showsHorizontalScrollIndicator={false}>
  {chatMsgs.map(ChatMsg => (
    <ChatMsg key={Math.random()} />
  ))}
</ScrollView>  

How can I go about implementing this scenario?

I have tried display: 'flex', flexDirection: 'column', alignItems: 'flex-end', but to no success. I did not expect it to work anyway.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you all in advance.

>Solution :

You can use contentOffset props and set arbitrary y value.

 <ScrollView
  vertical
  showsVerticalScrollIndicator={false}
  showsHorizontalScrollIndicator={false}
  contentOffset={{x: 0, y: 9999}} />
  ))}>
  {chatMsgs.map(ChatMsg => (
    <ChatMsg key={Math.random()} />
  ))}
</ScrollView> 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading