diff options
Diffstat (limited to 'src/screens/Profile/Header/StatusBarShadow.tsx')
-rw-r--r-- | src/screens/Profile/Header/StatusBarShadow.tsx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/screens/Profile/Header/StatusBarShadow.tsx b/src/screens/Profile/Header/StatusBarShadow.tsx new file mode 100644 index 000000000..587b41051 --- /dev/null +++ b/src/screens/Profile/Header/StatusBarShadow.tsx @@ -0,0 +1,56 @@ +import Animated, {SharedValue, useAnimatedStyle} from 'react-native-reanimated' +import {useSafeAreaInsets} from 'react-native-safe-area-context' +import {LinearGradient} from 'expo-linear-gradient' + +import {isIOS} from '#/platform/detection' +import {usePagerHeaderContext} from '#/view/com/pager/PagerHeaderContext' +import {atoms as a} from '#/alf' + +const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient) + +export function StatusBarShadow() { + const {top: topInset} = useSafeAreaInsets() + const pagerContext = usePagerHeaderContext() + + if (isIOS && pagerContext) { + const {scrollY} = pagerContext + return <StatusBarShadowInnner scrollY={scrollY} /> + } + + return ( + <LinearGradient + colors={['rgba(0,0,0,0.5)', 'rgba(0,0,0,0)']} + style={[ + a.absolute, + a.z_10, + {height: topInset, top: 0, left: 0, right: 0}, + ]} + /> + ) +} + +function StatusBarShadowInnner({scrollY}: {scrollY: SharedValue<number>}) { + const {top: topInset} = useSafeAreaInsets() + + const animatedStyle = useAnimatedStyle(() => { + return { + transform: [ + { + translateY: Math.min(0, scrollY.get()), + }, + ], + } + }) + + return ( + <AnimatedLinearGradient + colors={['rgba(0,0,0,0.5)', 'rgba(0,0,0,0)']} + style={[ + animatedStyle, + a.absolute, + a.z_10, + {height: topInset, top: 0, left: 0, right: 0}, + ]} + /> + ) +} |