diff options
author | Francesco Lodovici <2643961+frncs-eu@users.noreply.github.com> | 2024-06-10 17:19:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 17:19:28 +0200 |
commit | b688da8d5860569108a7f487dc97c5f0b403aee1 (patch) | |
tree | 73eed1b1dbc378efcf23acc0ccf2062969d0fbb9 /src/lib/hooks/useMinimalShellTransform.ts | |
parent | fd03ea3fe1d4f3c6a4079272b0dbd21c4e0d2b1b (diff) | |
download | voidsky-b688da8d5860569108a7f487dc97c5f0b403aee1.tar.zst |
* Fix (#4430): Use separate hooks for shell mode animated styles * Consolidate in one file --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src/lib/hooks/useMinimalShellTransform.ts')
-rw-r--r-- | src/lib/hooks/useMinimalShellTransform.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/lib/hooks/useMinimalShellTransform.ts b/src/lib/hooks/useMinimalShellTransform.ts new file mode 100644 index 000000000..9875840d6 --- /dev/null +++ b/src/lib/hooks/useMinimalShellTransform.ts @@ -0,0 +1,58 @@ +import {interpolate, useAnimatedStyle} from 'react-native-reanimated' + +import {useMinimalShellMode} from '#/state/shell/minimal-mode' +import {useShellLayout} from '#/state/shell/shell-layout' + +// Keep these separated so that we only pay for useAnimatedStyle that gets used. + +export function useMinimalShellHeaderTransform() { + const mode = useMinimalShellMode() + const {headerHeight} = useShellLayout() + + const headerTransform = useAnimatedStyle(() => { + return { + pointerEvents: mode.value === 0 ? 'auto' : 'none', + opacity: Math.pow(1 - mode.value, 2), + transform: [ + { + translateY: interpolate(mode.value, [0, 1], [0, -headerHeight.value]), + }, + ], + } + }) + + return headerTransform +} + +export function useMinimalShellFooterTransform() { + const mode = useMinimalShellMode() + const {footerHeight} = useShellLayout() + + const footerTransform = useAnimatedStyle(() => { + return { + pointerEvents: mode.value === 0 ? 'auto' : 'none', + opacity: Math.pow(1 - mode.value, 2), + transform: [ + { + translateY: interpolate(mode.value, [0, 1], [0, footerHeight.value]), + }, + ], + } + }) + return footerTransform +} + +export function useMinimalShellFabTransform() { + const mode = useMinimalShellMode() + + const fabTransform = useAnimatedStyle(() => { + return { + transform: [ + { + translateY: interpolate(mode.value, [0, 1], [-44, 0]), + }, + ], + } + }) + return fabTransform +} |