Gilad Novik
Gilad Novik

Reputation: 4604

React Native ListView: Scroll to a particular row with variable height

My ListView displays a feed of users, where each row is variable height (similar to Facebook).

A similar question suggests to scroll to rowIndex*rowHeight, but my rows are not the same height.

Any suggestions?

Upvotes: 4

Views: 2673

Answers (1)

farwayer
farwayer

Reputation: 4122

There is no simple way to do this. You can try to use onLayout event and save all rows height. But if part of rows before item you want scroll to was not rendered you can't calculate offset. One solution in this situation is render all items at once. But there may be performance issue.
Another is scrolling bit by bit and calculate height in runtime.

My advice is redesign your UX to prevent this operation. Or use ScrollView and onLayout if row count is not too big.

UPDATED: FlatList will be added in RN 0.43. It has scrollToItem method.

Upvotes: 5

Related Questions