Skip to content

Instantly share code, notes, and snippets.

@nazrdogan
Created October 26, 2021 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazrdogan/12cbcc1085ea3d27358e3f1e25107836 to your computer and use it in GitHub Desktop.
Save nazrdogan/12cbcc1085ea3d27358e3f1e25107836 to your computer and use it in GitHub Desktop.
const App = () => {
const lastContentOffset = useSharedValue(0);
const isScrolling = useSharedValue(false);
const renderItem = ({ item }) => <Item title={item.title} />;
const scrollHandler = useAnimatedScrollHandler({
onScroll: (event) => {
if (lastContentOffset.value > event.contentOffset.y) {
if (isScrolling.value) {
console.log("UP");
}
} else if (lastContentOffset.value < event.contentOffset.y) {
if (isScrolling.value) {
console.log("DOWN");
}
}
lastContentOffset.value = event.contentOffset.y;
},
onBeginDrag: (e) => {
isScrolling.value = true;
},
onEndDrag: (e) => {
isScrolling.value = false;
},
});
return (
<SafeAreaView style={styles.container}>
<AnimatFlatList
data={DATA}
onScroll={scrollHandler}
renderItem={renderItem}
keyExtractor={(item) => item.id}
/>
</SafeAreaView>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment