saleel / react-native-super-grid

Responsive Grid View for React Native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get current index while scrolling

fukemy opened this issue · comments

commented

Hi, thanks for useful library.
I want to get the current index while scrolling, can u give me some advices

commented

This is not implemented inside the library.
You can probably use the onScroll event. Getting the index would require you to calculate it dividing top offset by itemHeight. But one row can have multiple item. You can get itemsPerRow from onItemsPerRowChange prop if needed.
Something like : (top / itemHeight) * itemsPerRow

commented

the biggest problem => I can not get each section + items height, I have only itemPerRow which defined before, can u suggest me how to do it? I am stucking with this since a few days

commented

onScroll callback has a parameter that contains offset from the top. You can use this to determine how long has been scrolled. Since you define the itemHeight beforehand and you know it, you can divide the offset from top by the itemHeight