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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
import React from 'react';
import {
StyleSheet,
TextInput,
TouchableOpacity,
Text,
View,
TextInputProps,
Keyboard,
NativeSyntheticEvent,
TextInputSubmitEditingEventData,
} from 'react-native';
import Animated from 'react-native-reanimated';
import Icon from 'react-native-vector-icons/Feather';
import {normalize} from 'react-native-elements';
import {SCREEN_WIDTH} from '../../utils';
const AnimatedIcon = Animated.createAnimatedComponent(Icon);
interface SearchBarProps extends TextInputProps {
onCancel: () => void;
top: Animated.Value<number>;
}
const SearchBar: React.FC<SearchBarProps> = ({
onFocus,
onBlur,
onChangeText,
value,
onCancel,
style,
}) => {
const handleSubmit = (
e: NativeSyntheticEvent<TextInputSubmitEditingEventData>,
) => {
e.preventDefault();
Keyboard.dismiss();
};
return (
<>
<View style={[styles.container, style]}>
<Animated.View style={[styles.inputContainer]}>
<AnimatedIcon
name="search"
color={'#7E7E7E'}
size={25}
style={styles.searchIcon}
/>
<TextInput
style={[styles.input]}
placeholder={'Search'}
placeholderTextColor={'#828282'}
onSubmitEditing={handleSubmit}
clearButtonMode="while-editing"
autoCapitalize="none"
autoCorrect={false}
{...{value, onChangeText, onFocus, onBlur}}
/>
</Animated.View>
<View style={styles.cancelButtonView}>
<TouchableOpacity style={styles.cancelButton} onPress={onCancel}>
<Text style={styles.cancelText}>Cancel</Text>
</TouchableOpacity>
</View>
</View>
<Text style={styles.helperText}>
Try searching for "trending on tagg"
</Text>
</>
);
};
const styles = StyleSheet.create({
container: {
height: 40,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'stretch',
zIndex: 2,
},
inputContainer: {
flexGrow: 1,
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 8,
borderRadius: 20,
backgroundColor: '#F0F0F0',
},
searchIcon: {
marginRight: 8,
},
input: {
flex: 1,
fontSize: 16,
color: '#000',
letterSpacing: normalize(0.5),
},
cancelButtonView: {width: 70, flexDirection: 'row', justifyContent: 'center'},
cancelButton: {
position: 'absolute',
height: '100%',
justifyContent: 'center',
paddingHorizontal: 5,
},
cancelText: {
color: '#818181',
fontWeight: '600',
},
helperText: {
fontWeight: '400',
fontSize: 14,
lineHeight: normalize(16.71),
color: '#828282',
marginBottom: '2%',
marginHorizontal: '2.5%',
marginTop: '1%',
textAlign: 'center',
width: SCREEN_WIDTH * 0.74,
},
});
export default SearchBar;
|