Bluesky app fork with some witchin' additions 馃挮
witchsky.app
bluesky
fork
client
1import {createContext, useContext, useMemo} from 'react'
2import {type ScrollHandlers} from 'react-native-reanimated'
3
4const ScrollContext = createContext<ScrollHandlers<any>>({
5 onBeginDrag: undefined,
6 onEndDrag: undefined,
7 onScroll: undefined,
8 onMomentumEnd: undefined,
9})
10ScrollContext.displayName = 'ScrollContext'
11
12export function useScrollHandlers(): ScrollHandlers<any> {
13 return useContext(ScrollContext)
14}
15
16type ProviderProps = {children: React.ReactNode} & ScrollHandlers<any>
17
18// Note: this completely *overrides* the parent handlers.
19// It's up to you to compose them with the parent ones via useScrollHandlers() if needed.
20export function ScrollProvider({
21 children,
22 onBeginDrag,
23 onEndDrag,
24 onScroll,
25 onMomentumEnd,
26}: ProviderProps) {
27 const handlers = useMemo(
28 () => ({
29 onBeginDrag,
30 onEndDrag,
31 onScroll,
32 onMomentumEnd,
33 }),
34 [onBeginDrag, onEndDrag, onScroll, onMomentumEnd],
35 )
36 return (
37 <ScrollContext.Provider value={handlers}>{children}</ScrollContext.Provider>
38 )
39}