diff options
author | dan <dan.abramov@gmail.com> | 2023-11-09 20:15:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-09 12:15:05 -0800 |
commit | 7a55ca613347680cd94add01faa5dc3f216b9bd2 (patch) | |
tree | d9fa7951b43a8148b44e12a93452e214e1c4a798 /src/lib/hooks/useMinimalShellMode.tsx | |
parent | 1dcf882619bc2d6b3eefebf83e76f4b21871b791 (diff) | |
download | voidsky-7a55ca613347680cd94add01faa5dc3f216b9bd2.tar.zst |
Sync top/bottom bar disappearance to the scroll (#1855)
* Disable existing code that toggles shell * Make shell mode a float * Translate based on the gesture * Track header and footer heights * Add web support * Fix types and cleanup * Add back isScrolled logic * Add comments
Diffstat (limited to 'src/lib/hooks/useMinimalShellMode.tsx')
-rw-r--r-- | src/lib/hooks/useMinimalShellMode.tsx | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/src/lib/hooks/useMinimalShellMode.tsx b/src/lib/hooks/useMinimalShellMode.tsx index 4738b8e2c..e81fc434f 100644 --- a/src/lib/hooks/useMinimalShellMode.tsx +++ b/src/lib/hooks/useMinimalShellMode.tsx @@ -1,45 +1,29 @@ -import { - AnimatableValue, - interpolate, - useAnimatedStyle, - withTiming, - Easing, -} from 'react-native-reanimated' - +import {interpolate, useAnimatedStyle} from 'react-native-reanimated' import {useMinimalShellMode as useMinimalShellModeState} from '#/state/shell/minimal-mode' - -function withShellTiming<T extends AnimatableValue>(value: T): T { - 'worklet' - return withTiming(value, { - duration: 125, - easing: Easing.bezier(0.25, 0.1, 0.25, 1), - }) -} +import {useShellLayout} from '#/state/shell/shell-layout' export function useMinimalShellMode() { const mode = useMinimalShellModeState() + const {footerHeight, headerHeight} = useShellLayout() + const footerMinimalShellTransform = useAnimatedStyle(() => { return { - pointerEvents: mode.value ? 'none' : 'auto', - opacity: withShellTiming(interpolate(mode.value ? 1 : 0, [0, 1], [1, 0])), + pointerEvents: mode.value === 0 ? 'auto' : 'none', + opacity: Math.pow(1 - mode.value, 2), transform: [ { - translateY: withShellTiming( - interpolate(mode.value ? 1 : 0, [0, 1], [0, 25]), - ), + translateY: interpolate(mode.value, [0, 1], [0, footerHeight.value]), }, ], } }) const headerMinimalShellTransform = useAnimatedStyle(() => { return { - pointerEvents: mode.value ? 'none' : 'auto', - opacity: withShellTiming(interpolate(mode.value ? 1 : 0, [0, 1], [1, 0])), + pointerEvents: mode.value === 0 ? 'auto' : 'none', + opacity: Math.pow(1 - mode.value, 2), transform: [ { - translateY: withShellTiming( - interpolate(mode.value ? 1 : 0, [0, 1], [0, -25]), - ), + translateY: interpolate(mode.value, [0, 1], [0, -headerHeight.value]), }, ], } @@ -48,9 +32,7 @@ export function useMinimalShellMode() { return { transform: [ { - translateY: withShellTiming( - interpolate(mode.value ? 1 : 0, [0, 1], [-44, 0]), - ), + translateY: interpolate(mode.value, [0, 1], [-44, 0]), }, ], } |