Reduce Reanimated serialization traffic (#6219)
This commit is contained in:
@@ -3,6 +3,7 @@ import {NativeScrollEvent} from 'react-native'
|
|||||||
import {
|
import {
|
||||||
cancelAnimation,
|
cancelAnimation,
|
||||||
interpolate,
|
interpolate,
|
||||||
|
makeMutable,
|
||||||
useSharedValue,
|
useSharedValue,
|
||||||
withSpring,
|
withSpring,
|
||||||
} from 'react-native-reanimated'
|
} from 'react-native-reanimated'
|
||||||
@@ -20,6 +21,18 @@ function clamp(num: number, min: number, max: number) {
|
|||||||
return Math.min(Math.max(num, min), max)
|
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}) {
|
export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||||
const {headerHeight} = useShellLayout()
|
const {headerHeight} = useShellLayout()
|
||||||
const {headerMode} = useMinimalShellMode()
|
const {headerMode} = useMinimalShellMode()
|
||||||
@@ -31,9 +44,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
|||||||
(v: boolean) => {
|
(v: boolean) => {
|
||||||
'worklet'
|
'worklet'
|
||||||
cancelAnimation(headerMode)
|
cancelAnimation(headerMode)
|
||||||
headerMode.value = withSpring(v ? 1 : 0, {
|
headerMode.value = v ? V1.value : V0.value
|
||||||
overshootClamping: true,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
[headerMode],
|
[headerMode],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user