SearchBar.js
1.51 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
66
67
68
69
70
71
72
'use strict';
import React from 'react';
import ReactNative from 'react-native';
const {
Component,
} = React;
const {
TouchableHighlight,
Alert,
Dimensions,
StyleSheet,
View,
Text,
Image,
Platform,
TextInput,
} = ReactNative;
export default class SearchBar extends Component{
constructor(props) {
super (props);
this._onSubmitEditing = this._onSubmitEditing.bind(this);
this._onChangeText = this._onChangeText.bind(this);
}
_onSubmitEditing(event){
let value = event.nativeEvent.text;
this.props.onSearch && this.props.onSearch(value);
}
_onChangeText(text){
this.props.searchChangeText && this.props.searchChangeText(text);
}
render(){
let {placeholder} = this.props;
return (
<View style={styles.container}>
<TextInput style={styles.inputText}
placeholder={placeholder?placeholder:'搜索'}
onSubmitEditing={this._onSubmitEditing}
onChangeText={this._onChangeText}
/>
<Image source={require('../../images/tabbar/home.png')} style={styles.searchIcon}/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
height: 40,
backgroundColor: 'white',
alignItems: 'center'
},
inputText:{
flex:1,
backgroundColor:'transparent',
fontSize:15,
marginLeft: 10,
},
searchIcon: {
marginLeft: 5,
marginRight: 20,
width: 15,
height: 20,
resizeMode: 'stretch'
},
});