4

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?

Community
  • 1
  • 1
Gilad Novik
  • 4,546
  • 4
  • 41
  • 58

1 Answers1

5

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.

farwayer
  • 3,872
  • 3
  • 21
  • 23