|
| 1 | +import { |
| 2 | + Animated, |
| 3 | + ImageBackground, |
| 4 | + StyleSheet, |
| 5 | + useWindowDimensions, |
| 6 | + View, |
| 7 | +} from 'react-native'; |
1 | 8 | import React from 'react'; |
2 | | -import { StyleSheet, Animated } from 'react-native'; |
3 | | -import { useAnimateNavbar } from '../hooks/useAnimateNavbar'; |
4 | 9 | import type { AnimatedHeaderProps } from '../types'; |
5 | 10 |
|
6 | | -const AnimatedHeader = ({ |
7 | | - scroll, |
8 | | - imageHeight, |
9 | | - OverflowHeaderComponent, |
| 11 | +export const AnimatedHeader = ({ |
10 | 12 | HeaderComponent, |
11 | | - headerHeight, |
| 13 | + headerImage, |
| 14 | + imageHeight, |
| 15 | + translateYUp, |
| 16 | + translateYDown, |
| 17 | + scale, |
| 18 | + imageStyle, |
12 | 19 | }: AnimatedHeaderProps) => { |
13 | | - const [headerOpacity, overflowHeaderOpacity] = useAnimateNavbar( |
14 | | - scroll, |
15 | | - imageHeight, |
16 | | - headerHeight |
17 | | - ); |
18 | | - |
| 20 | + const { width } = useWindowDimensions(); |
| 21 | + const AnimatedImageBackground = |
| 22 | + Animated.createAnimatedComponent(ImageBackground); |
19 | 23 | return ( |
20 | | - <> |
21 | | - <Animated.View |
22 | | - style={[ |
23 | | - styles.container, |
24 | | - styles.header, |
25 | | - { |
26 | | - zIndex: headerOpacity, |
27 | | - height: headerHeight, |
28 | | - opacity: headerOpacity, |
29 | | - }, |
30 | | - ]} |
31 | | - > |
32 | | - {HeaderComponent} |
33 | | - </Animated.View> |
34 | | - <Animated.View |
35 | | - style={[ |
36 | | - styles.container, |
37 | | - styles.overflowHeader, |
38 | | - { |
39 | | - zIndex: overflowHeaderOpacity, |
40 | | - height: headerHeight, |
41 | | - opacity: overflowHeaderOpacity, |
42 | | - }, |
43 | | - ]} |
44 | | - > |
45 | | - {OverflowHeaderComponent} |
46 | | - </Animated.View> |
47 | | - </> |
| 24 | + <View |
| 25 | + style={[ |
| 26 | + styles.imgContainer, |
| 27 | + { |
| 28 | + marginTop: -imageHeight * 4, |
| 29 | + paddingTop: imageHeight * 4, |
| 30 | + }, |
| 31 | + ]} |
| 32 | + > |
| 33 | + {HeaderComponent ? ( |
| 34 | + <> |
| 35 | + {headerImage ? ( |
| 36 | + <AnimatedImageBackground |
| 37 | + source={headerImage} |
| 38 | + style={[ |
| 39 | + { height: imageHeight, width: width * 1.2 }, |
| 40 | + { |
| 41 | + transform: [ |
| 42 | + { scale: scale }, |
| 43 | + { translateY: translateYUp }, |
| 44 | + { translateY: translateYDown }, |
| 45 | + ], |
| 46 | + }, |
| 47 | + imageStyle, |
| 48 | + ]} |
| 49 | + > |
| 50 | + {HeaderComponent} |
| 51 | + </AnimatedImageBackground> |
| 52 | + ) : ( |
| 53 | + <Animated.View |
| 54 | + style={[ |
| 55 | + { height: imageHeight, width: width * 1.2 }, |
| 56 | + { |
| 57 | + transform: [ |
| 58 | + { scale }, |
| 59 | + { translateY: translateYUp }, |
| 60 | + { translateY: translateYDown }, |
| 61 | + ], |
| 62 | + }, |
| 63 | + ]} |
| 64 | + > |
| 65 | + {HeaderComponent} |
| 66 | + </Animated.View> |
| 67 | + )} |
| 68 | + </> |
| 69 | + ) : ( |
| 70 | + <Animated.Image |
| 71 | + source={headerImage} |
| 72 | + style={[ |
| 73 | + { height: imageHeight, width: width * 1.2 }, |
| 74 | + { |
| 75 | + transform: [ |
| 76 | + { scale }, |
| 77 | + { translateY: translateYUp }, |
| 78 | + { translateY: translateYDown }, |
| 79 | + ], |
| 80 | + }, |
| 81 | + imageStyle, |
| 82 | + ]} |
| 83 | + /> |
| 84 | + )} |
| 85 | + </View> |
48 | 86 | ); |
49 | 87 | }; |
50 | 88 |
|
51 | 89 | const styles = StyleSheet.create({ |
52 | | - container: { |
53 | | - paddingTop: 32, |
54 | | - position: 'absolute', |
55 | | - elevation: 2, |
56 | | - top: 0, |
57 | | - width: '100%', |
58 | | - backgroundColor: 'white', |
| 90 | + imgContainer: { |
59 | 91 | alignItems: 'center', |
60 | | - justifyContent: 'center', |
61 | | - }, |
62 | | - header: { |
63 | | - borderBottomWidth: StyleSheet.hairlineWidth, |
64 | | - borderBottomColor: '#a4a4a4', |
65 | | - }, |
66 | | - overflowHeader: { |
67 | | - backgroundColor: 'transparent', |
| 92 | + overflow: 'hidden', |
68 | 93 | }, |
69 | 94 | }); |
70 | | - |
71 | | -export default AnimatedHeader; |
|
0 commit comments