Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native ListView: How to scroll to a particular row

Tags:

react-native

In NativeiOS you can make a UITableView scroll to a particular UITableViewCell using:

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:87 inSection:0] 
         atScrollPosition:UITableViewScrollPositionMiddle animated:NO];

.. or similar.

For example, if the ListView held 100 items and I wanted to scroll such that the 87th item is visible.

Looking at the React Native ListView Docs there's nothing obvious there.

Has anyone managed to achieve this? I realise that ListView does not wrap UITableView so we can't just expose the method.

EDIT: Looks like some support for this is in the 0.19-rc release, check this https://github.com/facebook/react-native/releases

https://github.com/facebook/react-native/commit/33e05a11f00d1455f39b6dfef1c76c4130df02e5

like image 365
Ben Clayton Avatar asked Sep 25 '22 16:09

Ben Clayton


1 Answers

Use a ScrollView with contentOffset={{ x: offsetX, y: offsetY }} and calculate the offset variables depending on which row you want to scroll to.

like image 174
jamesfzhang Avatar answered Sep 29 '22 00:09

jamesfzhang