diff options
author | Eric Bailey <git@esb.lol> | 2023-11-07 13:37:47 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 11:37:47 -0800 |
commit | bfe196bac5e618bfbeab4f6fabef3e5a18194868 (patch) | |
tree | f3fd74b8472f5bcd3bbcf3b111a0f19b059de404 /src/lib/hooks/useOnMainScroll.ts | |
parent | 7158157f5fe07b8f97842736ea87b598baabb7da (diff) | |
download | voidsky-bfe196bac5e618bfbeab4f6fabef3e5a18194868.tar.zst |
Extract shell state into separate context (#1824)
* WIP * Add shell state * Integrate new shell state for drawer and minimal shell mode * Replace isDrawerSwipeDisabled * Split shell state into separate contexts to avoid needless re-renders * Fix typo --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
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]), ] } |