Skip to content

Instantly share code, notes, and snippets.

@jbutko
Created September 10, 2018 06:28
Show Gist options
  • Select an option

  • Save jbutko/33832e50f3d95a73842e763b3791f586 to your computer and use it in GitHub Desktop.

Select an option

Save jbutko/33832e50f3d95a73842e763b3791f586 to your computer and use it in GitHub Desktop.
React Native: Detect ScrollView has reached the end
import React from 'react';
import {ScrollView, Text} from 'react-native';
const isCloseToBottom = ({layoutMeasurement, contentOffset, contentSize}) => {
const paddingToBottom = 20;
return layoutMeasurement.height + contentOffset.y >=
contentSize.height - paddingToBottom;
};
const MyCoolScrollViewComponent = ({enableSomeButton}) => (
<ScrollView
onScroll={({nativeEvent}) => {
if (isCloseToBottom(nativeEvent)) {
enableSomeButton();
}
}}
scrollEventThrottle={400}
>
<Text>Here is very long lorem ipsum or something...</Text>
</ScrollView>
);
export default MyCoolScrollViewComponent;
// via From https://stackoverflow.com/questions/41056761/detect-scrollview-has-reached-the-end
@thiennd99

Copy link
Copy Markdown

it is still a valuable detection in 2024 <3

@AkilUnik

Copy link
Copy Markdown

great

@shubham-cpp

Copy link
Copy Markdown

For people in 2025, please use onScrollEndDrag instead of onScroll so your "enableSomeButton()" would only trigger once instead of twice

@alwyntan

Copy link
Copy Markdown

For people in 2025, please use onScrollEndDrag instead of onScroll so your "enableSomeButton()" would only trigger once instead of twice

This won't work if your react-native is targeting web too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment