How to get currently visible index in RN flat list

前端 未结 5 1113
温柔的废话
温柔的废话 2021-02-01 01:54

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.



        
5条回答
  •  灰色年华
    2021-02-01 02:46

    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/

提交回复
热议问题