diff options
author | dan <dan.abramov@gmail.com> | 2023-11-07 16:46:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 08:46:39 -0800 |
commit | 7b2a7db83c08cd149d791382c25545ceb243490f (patch) | |
tree | bb84387e800ce5de484f88b4445b231c49296313 /src/view/com/pager/PagerWithHeader.tsx | |
parent | fa821943da1789ae53d17ff1739a2073ca6c8abb (diff) | |
download | voidsky-7b2a7db83c08cd149d791382c25545ceb243490f.tar.zst |
Pull animated scroll handler down from pager (#1827)
Diffstat (limited to 'src/view/com/pager/PagerWithHeader.tsx')
-rw-r--r-- | src/view/com/pager/PagerWithHeader.tsx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index 842a4574e..701b52871 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -1,9 +1,13 @@ import * as React from 'react' -import {LayoutChangeEvent, StyleSheet, View} from 'react-native' +import { + LayoutChangeEvent, + NativeScrollEvent, + StyleSheet, + View, +} from 'react-native' import Animated, { Easing, useAnimatedReaction, - useAnimatedScrollHandler, useAnimatedStyle, useSharedValue, withTiming, @@ -12,13 +16,12 @@ import Animated, { import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager' import {TabBar} from './TabBar' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' -import {OnScrollCb} from 'lib/hooks/useOnMainScroll' const SCROLLED_DOWN_LIMIT = 200 interface PagerWithHeaderChildParams { headerHeight: number - onScroll: OnScrollCb + onScroll: (e: NativeScrollEvent) => void isScrolledDown: boolean } @@ -140,12 +143,18 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>( ], ) - // props to pass into children render functions - const onScroll = useAnimatedScrollHandler({ - onScroll(e) { + // Ideally we'd call useAnimatedScrollHandler here but we can't safely do that + // due to https://github.com/software-mansion/react-native-reanimated/issues/5345. + // So instead we pass down a worklet, and individual pages will have to call it. + const onScroll = React.useCallback( + (e: NativeScrollEvent) => { + 'worklet' scrollY.value = e.contentOffset.y }, - }) + [scrollY], + ) + + // props to pass into children render functions const childProps = React.useMemo<PagerWithHeaderChildParams>(() => { return { headerHeight, |