about summary refs log tree commit diff
path: root/src/screens/Profile/Header/StatusBarShadow.tsx
blob: 7180e62bbeb188b183e416e26108971b7ac01ca8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Animated, {
  type 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},
      ]}
    />
  )
}