import React, {createContext, useContext, useMemo} from 'react' import {ScrollHandlers} from 'react-native-reanimated' const ScrollContext = createContext>({ onBeginDrag: undefined, onEndDrag: undefined, onScroll: undefined, onMomentumEnd: undefined, }) export function useScrollHandlers(): ScrollHandlers { return useContext(ScrollContext) } type ProviderProps = {children: React.ReactNode} & ScrollHandlers // Note: this completely *overrides* the parent handlers. // It's up to you to compose them with the parent ones via useScrollHandlers() if needed. export function ScrollProvider({ children, onBeginDrag, onEndDrag, onScroll, onMomentumEnd, }: ProviderProps) { const handlers = useMemo( () => ({ onBeginDrag, onEndDrag, onScroll, onMomentumEnd, }), [onBeginDrag, onEndDrag, onScroll, onMomentumEnd], ) return ( {children} ) }