Skip to content

Instantly share code, notes, and snippets.

@Stringsaeed
Created February 19, 2022 20:09
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 Stringsaeed/3556d4982896fd6490f023c4dc864099 to your computer and use it in GitHub Desktop.
Save Stringsaeed/3556d4982896fd6490f023c4dc864099 to your computer and use it in GitHub Desktop.
react native reanimated scroll handler in y axies only
import {
useSharedValue,
useAnimatedScrollHandler,
} from 'react-native-reanimated';
const useScrollHandler = () => {
const scrollY = useSharedValue(0);
const onScroll = useAnimatedScrollHandler(event => {
scrollY.value = event.contentOffset.y;
});
return [scrollY, onScroll] as const;
};
export default useScrollHandler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment