-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigationHeader.tsx
92 lines (85 loc) · 2.56 KB
/
NavigationHeader.tsx
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from 'react';
import {Dimensions, View, TextInput} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Ionicons from 'react-native-vector-icons/Ionicons';
import IconWithBadge from './IconWithBadge';
import Animated, {
useAnimatedStyle,
interpolateColor,
} from 'react-native-reanimated';
import {brandColors} from './colors';
const padding = 8;
const {width} = Dimensions.get('window');
// height of this is 51!
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
const NavigationHeader = ({
scrollPosY,
}: {
scrollPosY: Animated.SharedValue<number>;
}) => {
const insets = useSafeAreaInsets();
const navigationAniamtedStyle = useAnimatedStyle(() => {
return {
paddingTop: insets.top + padding,
paddingHorizontal: padding,
paddingBottom: padding,
backgroundColor: interpolateColor(
scrollPosY.value,
[0, 1],
['rgba(255,255,255,0)', 'rgba(255,255,255,1)'],
),
position: 'absolute',
top: 0,
zIndex: 999,
width: width,
};
});
const searchBoxStyle = useAnimatedStyle(() => {
return {
backgroundColor: interpolateColor(
scrollPosY.value,
[0, 1],
['rgba(255,255,255,1)', '#E5E7EB'],
),
flexDirection: 'row',
flex: 1,
justifyContent: 'space-between',
alignItems: 'center',
marginHorizontal: padding,
paddingHorizontal: padding,
paddingVertical: 4,
};
});
return (
<Animated.View style={navigationAniamtedStyle}>
<View style={{flexDirection: 'row', alignItems: 'center'}}>
<Animated.View style={searchBoxStyle}>
<Ionicons name="search-outline" size={20} />
<View style={{flex: 1, paddingHorizontal: padding}}>
<TextInput
placeholderTextColor={brandColors.main}
style={{paddingVertical: 0}}
placeholder="Eucerin: RM90 Off Voucher + Free Shipping + GUGUBIRD"
/>
</View>
<Ionicons name="camera-outline" size={20} />
</Animated.View>
<View style={{paddingHorizontal: padding}}>
<IconWithBadge
iconName="cart-outline"
badgeLabel="6"
scrollPosY={scrollPosY}
/>
</View>
<View style={{paddingHorizontal: padding}}>
<IconWithBadge
iconName="chatbubbles-outline"
badgeLabel="6"
scrollPosY={scrollPosY}
/>
</View>
</View>
</Animated.View>
);
};
export default NavigationHeader;