diff options
Diffstat (limited to 'src/lib/hooks/useOnMainScroll.ts')
-rw-r--r-- | src/lib/hooks/useOnMainScroll.ts | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/lib/hooks/useOnMainScroll.ts b/src/lib/hooks/useOnMainScroll.ts index 250ef3a36..2eab4b250 100644 --- a/src/lib/hooks/useOnMainScroll.ts +++ b/src/lib/hooks/useOnMainScroll.ts @@ -1,8 +1,8 @@ import {useState, useCallback, useRef} from 'react' import {NativeSyntheticEvent, NativeScrollEvent} from 'react-native' -import {RootStoreModel} from 'state/index' import {s} from 'lib/styles' import {useWebMediaQueries} from './useWebMediaQueries' +import {useSetMinimalShellMode, useMinimalShellMode} from '#/state/shell' const Y_LIMIT = 10 @@ -19,12 +19,12 @@ export type OnScrollCb = ( ) => void export type ResetCb = () => void -export function useOnMainScroll( - store: RootStoreModel, -): [OnScrollCb, boolean, ResetCb] { +export function useOnMainScroll(): [OnScrollCb, boolean, ResetCb] { let lastY = useRef(0) let [isScrolledDown, setIsScrolledDown] = useState(false) const {dyLimitUp, dyLimitDown} = useDeviceLimits() + const minimalShellMode = useMinimalShellMode() + const setMinimalShellMode = useSetMinimalShellMode() return [ useCallback( @@ -33,13 +33,10 @@ export function useOnMainScroll( const dy = y - (lastY.current || 0) lastY.current = y - if (!store.shell.minimalShellMode && dy > dyLimitDown && y > Y_LIMIT) { - store.shell.setMinimalShellMode(true) - } else if ( - store.shell.minimalShellMode && - (dy < dyLimitUp * -1 || y <= Y_LIMIT) - ) { - store.shell.setMinimalShellMode(false) + if (!minimalShellMode && dy > dyLimitDown && y > Y_LIMIT) { + setMinimalShellMode(true) + } else if (minimalShellMode && (dy < dyLimitUp * -1 || y <= Y_LIMIT)) { + setMinimalShellMode(false) } if ( @@ -54,13 +51,19 @@ export function useOnMainScroll( setIsScrolledDown(false) } }, - [store.shell, dyLimitDown, dyLimitUp, isScrolledDown], + [ + dyLimitDown, + dyLimitUp, + isScrolledDown, + minimalShellMode, + setMinimalShellMode, + ], ), isScrolledDown, useCallback(() => { setIsScrolledDown(false) - store.shell.setMinimalShellMode(false) + setMinimalShellMode(false) lastY.current = 1e8 // NOTE we set this very high so that the onScroll logic works right -prf - }, [store, setIsScrolledDown]), + }, [setIsScrolledDown, setMinimalShellMode]), ] } |