Skip to content

Instantly share code, notes, and snippets.

@jbutko
Created September 10, 2018 06:28
Show Gist options
  • Save jbutko/33832e50f3d95a73842e763b3791f586 to your computer and use it in GitHub Desktop.
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
@pencilcheck
Copy link

Still works on react native 0.72.6

@lasithalakmal
Copy link

This is not working for some of the screen sizes for Android

@selin33-sl
Copy link

Allah razı olsun çok uğraştım ama oldu sonunda. God bless you bro!

@thiennd99
Copy link

it is still a valuable detection in 2024 <3

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