saleel / react-native-super-grid

Responsive Grid View for React Native
MIT License
1.43k stars 153 forks source link

get current index while scrolling #204

Closed fukemy closed 1 year ago

fukemy commented 1 year ago

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

saleel commented 1 year ago

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

fukemy commented 1 year ago

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

saleel commented 1 year ago

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