0

I am using scrollview in react native but it's onendreached not working how can i use onendreached in horizontal scroll view

<Animated.ScrollView
        horizontal
        scrollEventThrottle={1}
        showsHorizontalScrollIndicator={false}
        snapToInterval={CARD_WIDTH}></Animated.ScrollView>

I need horizontal flatlist in this if i use horizontal in the scroll view. then flatlist onendreached not working. If i remove horizotal from scroll view then onscroll not working in the scrollview. So i am looking for a function that will load more data as it will reach on the end of scrollview.

Rover
  • 661
  • 2
  • 18
  • 39

1 Answers1

1

U can use map function inside the scroll view to render your items. Then u can use this method inside a ScrollView

onScroll={({ nativeEvent }) => {
  if (isCloseToBottom(nativeEvent)) {
      ///// your code goes here
  }
}}

where isCloseToBottom functions is as follows

    isCloseToBottom = ({ layoutMeasurement, contentOffset, contentSize }) => {
        const paddingToright = 20;
        return layoutMeasurement.width + contentOffset.x >= contentSize.width - paddingToright;
    };
Sardar Usama
  • 97
  • 1
  • 11
  • Hello @SardarUsama. i tried to use this. but it is not working. i am using horizontal scrolling – Rover Jan 01 '20 at 04:59