-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathStretchableHeader.tsx
More file actions
65 lines (56 loc) · 1.49 KB
/
StretchableHeader.tsx
File metadata and controls
65 lines (56 loc) · 1.49 KB
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
60
61
62
63
64
65
import React from 'react'
import { StyleSheet, ImageBackground } from 'react-native'
import { useHeaderMeasurements } from 'react-native-collapsible-tab-view'
import Animated, { useAnimatedStyle } from 'react-native-reanimated'
import ExampleComponent from './Shared/ExampleComponent'
import { ExampleComponentType } from './types'
const title = 'Stretchable Header'
const HEADER_HEIGHT = 250
export const Header = () => {
const { top } = useHeaderMeasurements()
const backgroundStyle = useAnimatedStyle(() => {
return {
transform: [
{
translateY: Math.min(0, -top.value / 2),
},
{
scale: Math.max(1, (HEADER_HEIGHT + top.value) / HEADER_HEIGHT),
},
],
}
})
return (
<Animated.View style={[styles.root]} pointerEvents="none">
<Animated.View style={[styles.background, backgroundStyle]}>
<ImageBackground
style={styles.image}
source={require('../assets/album-art-2.jpg')}
/>
</Animated.View>
</Animated.View>
)
}
const Example: ExampleComponentType = () => {
return (
<ExampleComponent renderHeader={() => <Header />} allowHeaderOverscroll />
)
}
const styles = StyleSheet.create({
root: {
justifyContent: 'center',
alignItems: 'center',
height: HEADER_HEIGHT,
},
background: {
position: 'absolute',
width: '100%',
height: '100%',
},
image: {
width: '100%',
height: '100%',
},
})
Example.title = title
export default Example