diff options
author | dan <dan.abramov@gmail.com> | 2024-11-12 17:19:52 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-12 17:19:52 +0000 |
commit | b2e11d31717884f87c4e42ffedc645de46664456 (patch) | |
tree | 90e2f0af1e0edb7cbe43e1170dd9d69120044864 | |
parent | d7841037f19a58a9641d1a9ef9f1bcf805bb461b (diff) | |
download | voidsky-b2e11d31717884f87c4e42ffedc645de46664456.tar.zst |
Reduce Reanimated serialization traffic (#6219)
-rw-r--r-- | src/view/com/util/MainScrollProvider.tsx | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/view/com/util/MainScrollProvider.tsx b/src/view/com/util/MainScrollProvider.tsx index 23dffc561..193d07d72 100644 --- a/src/view/com/util/MainScrollProvider.tsx +++ b/src/view/com/util/MainScrollProvider.tsx @@ -3,6 +3,7 @@ import {NativeScrollEvent} from 'react-native' import { cancelAnimation, interpolate, + makeMutable, useSharedValue, withSpring, } from 'react-native-reanimated' @@ -20,6 +21,18 @@ function clamp(num: number, min: number, max: number) { return Math.min(Math.max(num, min), max) } +const V0 = makeMutable( + withSpring(0, { + overshootClamping: true, + }), +) + +const V1 = makeMutable( + withSpring(1, { + overshootClamping: true, + }), +) + export function MainScrollProvider({children}: {children: React.ReactNode}) { const {headerHeight} = useShellLayout() const {headerMode} = useMinimalShellMode() @@ -31,9 +44,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) { (v: boolean) => { 'worklet' cancelAnimation(headerMode) - headerMode.value = withSpring(v ? 1 : 0, { - overshootClamping: true, - }) + headerMode.value = v ? V1.value : V0.value }, [headerMode], ) |