Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the current section that is in the viewport in React-Native sectionlist

I want to detect which section of the react-native sectionlist is in the viewport. enter image description here

Is there any solution?

like image 725
Hamid Avatar asked Sep 22 '18 10:09

Hamid


People also ask

How do I show the section list in react native?

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.

How do I refresh a section list in react native?

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.

How Flatlists and Sectionlists are used in react native?

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.

Which interface do FlatList and SectionList extend from?

We use Sectionlist and Flatlist in our react native project and we use websocket to receive/update data.


1 Answers

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)
      }
like image 168
Haider Ali Avatar answered Nov 15 '22 00:11

Haider Ali