Skip to content

Commit 61bb46f

Browse files
committed
Add stretchable header example
1 parent ff55708 commit 61bb46f

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

example/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import ScrollOnHeader from './ScrollOnHeader'
2929
import ScrollableTabs from './ScrollableTabs'
3030
import Snap from './Snap'
3131
import StartOnSpecificTab from './StartOnSpecificTab'
32+
import StretchableHeader from './StretchableHeader'
3233
import UndefinedHeaderHeight from './UndefinedHeaderHeight'
3334
import { ExampleComponentType } from './types'
3435

@@ -49,6 +50,7 @@ const EXAMPLE_COMPONENTS: ExampleComponentType[] = [
4950
DynamicTabs,
5051
MinHeaderHeight,
5152
AnimatedHeader,
53+
StretchableHeader,
5254
AndroidSharedPullToRefresh,
5355
HeaderOverscrollExample,
5456
]

example/src/StretchableHeader.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React from 'react'
2+
import { StyleSheet, ImageBackground } from 'react-native'
3+
import { useHeaderMeasurements } from 'react-native-collapsible-tab-view'
4+
import Animated, { useAnimatedStyle } from 'react-native-reanimated'
5+
6+
import ExampleComponent from './Shared/ExampleComponent'
7+
import { ExampleComponentType } from './types'
8+
9+
const title = 'Stretchable Header'
10+
11+
export const Header = () => {
12+
const { top } = useHeaderMeasurements()
13+
14+
const backgroundStyle = useAnimatedStyle(() => {
15+
return {
16+
transform: [
17+
{
18+
translateY: Math.min(0, -top.value / 2),
19+
},
20+
{
21+
scale: Math.max(1, (250 + top.value) / 250),
22+
},
23+
],
24+
}
25+
})
26+
27+
return (
28+
<Animated.View style={[styles.root]} pointerEvents="none">
29+
<Animated.View style={[styles.background, backgroundStyle]}>
30+
<ImageBackground
31+
style={styles.image}
32+
source={require('../assets/album-art-2.jpg')}
33+
/>
34+
</Animated.View>
35+
</Animated.View>
36+
)
37+
}
38+
39+
const Example: ExampleComponentType = () => {
40+
return (
41+
<ExampleComponent renderHeader={() => <Header />} allowHeaderOverscroll />
42+
)
43+
}
44+
45+
const styles = StyleSheet.create({
46+
root: {
47+
justifyContent: 'center',
48+
alignItems: 'center',
49+
height: 250,
50+
},
51+
background: {
52+
position: 'absolute',
53+
width: '100%',
54+
height: '100%',
55+
},
56+
image: {
57+
width: '100%',
58+
height: '100%',
59+
},
60+
})
61+
62+
Example.title = title
63+
64+
export default Example

0 commit comments

Comments
 (0)