I have a horizontal flat list where each item is width:300
All I am trying to do is to get index of currently visible item.
In your case, I guess, you might ignore the padding
or margin
of items. The contentOffsetX
or contentOffsetY
should be firstViewableItemIndex
* (itemWidth
+ item padding or margin
).
As other answers, onViewableItemsChanged
would be a better choice to meet your requirement. I wrote an article about how to use it and how it is implemented.
https://suelan.github.io/2020/01/21/onViewableItemsChanged/