I want to detect which section of the react-native sectionlist is in the viewport.
Is there any solution?
Add SectionList to your React Native appOpen your app. js file and add the following data (for the purpose of this demonstration): This is our dummy data to be used in the SectionList . As you can see, we passed some dummy data into a sections prop as a single array.
This component is used inside a ScrollView or ListView to add pull to refresh functionality. When the ScrollView is at scrollY: 0 , swiping down triggers an onRefresh event.
SectionList s are like FlatList s, but they can have section headers to separate groups of rows. SectionList s render each item in their input sections using the renderSectionHeader and renderItem prop. Each item in sections should be an object with a unique id (the key), and an array data of row data.
We use Sectionlist and Flatlist in our react native project and we use websocket to receive/update data.
This is what you can do
render () {
return (
<SectionList
onViewableItemsChanged={this.onCheckViewableItems}
viewabilityConfig={{
itemVisiblePercentThreshold: 50 //means if 50% of the item is visible
}}
/>
)
}
onCheckViewableItems = ({ viewableItems, changed }) => {
console.log("Visible items :", viewableItems)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With