11import React from 'react' ;
22import { NativeModules , StyleSheet , TextInput , View } from 'react-native' ;
33import { withNavigation } from 'react-navigation' ;
4+ import Touchable from 'react-native-platform-touchable' ;
5+
6+ import { Icon } from 'expo' ;
47
58@withNavigation
69export default class SearchBar extends React . PureComponent {
@@ -16,8 +19,8 @@ export default class SearchBar extends React.PureComponent {
1619
1720 render ( ) {
1821 let searchInputStyle = { } ;
19- if ( this . props . tintColor ) {
20- searchInputStyle . color = this . props . tintColor ;
22+ if ( this . props . textColor ) {
23+ searchInputStyle . color = this . props . textColor ;
2124 }
2225
2326 return (
@@ -31,15 +34,35 @@ export default class SearchBar extends React.PureComponent {
3134 value = { this . state . text }
3235 autoCapitalize = "none"
3336 autoCorrect = { false }
37+ selectionColor = { this . props . selectionColor }
3438 underlineColorAndroid = { this . props . underlineColorAndroid || '#ccc' }
3539 onSubmitEditing = { this . _handleSubmit }
3640 onChangeText = { this . _handleChangeText }
3741 style = { [ styles . searchInput , searchInputStyle ] }
3842 />
43+ < View
44+ style = { { width : 50 , alignItems : 'center' , justifyContent : 'center' } } >
45+ { this . state . text
46+ ? < Touchable
47+ onPress = { this . _handleClear }
48+ hitSlop = { { top : 15 , left : 10 , right : 15 , bottom : 15 } }
49+ style = { { padding : 5 } }
50+ background = { Touchable . Ripple ( this . props . tintColor , true ) } >
51+ < Icon . Ionicons
52+ name = "md-close"
53+ size = { 25 }
54+ color = { this . props . tintColor }
55+ />
56+ </ Touchable >
57+ : null }
58+ </ View >
3959 </ View >
4060 ) ;
4161 }
4262
63+ _handleClear = ( ) => {
64+ this . setState ( { text : '' } ) ;
65+ } ;
4366 _handleChangeText = text => {
4467 this . setState ( { text } ) ;
4568 this . props . onChangeQuery && this . props . onChangeQuery ( text ) ;
0 commit comments