Ben Clayton
Ben Clayton

Reputation: 82209

React Native ListView: How to scroll to a particular row

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

Upvotes: 5

Views: 6982

Answers (1)

jamesfzhang
jamesfzhang

Reputation: 4473

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

Upvotes: 4

Related Questions