@@ -4,17 +4,14 @@ import {
44 StyleSheet ,
55 StyleProp ,
66 ViewStyle ,
7- Text ,
87 TouchableOpacity ,
9- Animated ,
108 NativeSyntheticEvent ,
119 TextInput ,
1210 TextInputFocusEventData ,
1311 TextInputProps ,
1412} from 'react-native' ;
1513import Icon , { IconsProps } from '../Icon' ;
1614import Button , { ButtonProps } from '../Button' ;
17- import RightButton from './RightButton' ;
1815
1916export interface SearchInputBarProps extends TextInputProps {
2017 /** 容器样式 */
@@ -38,8 +35,6 @@ export interface SearchInputBarProps extends TextInputProps {
3835interface SearchInputBarState {
3936 // isShow close icon
4037 showIcon : boolean ;
41- // close style
42- showIconLeft : number ;
4338}
4439
4540export default class SearchInputBar extends React . Component < SearchInputBarProps , SearchInputBarState > {
@@ -48,20 +43,19 @@ export default class SearchInputBar extends React.Component<SearchInputBarProps,
4843 super ( props ) ;
4944 this . state = {
5045 showIcon : false ,
51- showIconLeft : 0 ,
5246 } ;
5347 }
5448
5549 needFocus = ( type : 'search' | 'close' | 'actived' ) => {
5650 if ( type === 'close' ) {
5751 this . props . onClear ?.( ) ;
58- } else if ( type === 'search' ) {
52+ } else if ( type === 'search' && this . props . value ) {
5953 this . props . onSearch ?.( ) ;
54+ return ;
6055 }
6156 if ( type === 'actived' ) {
6257 this . setState ( { showIcon : true } ) ;
6358 }
64- console . log ( 'object' , type ) ;
6559 this . inputRef . current && this . inputRef . current . focus ( ) ;
6660 } ;
6761 render ( ) {
@@ -80,11 +74,9 @@ export default class SearchInputBar extends React.Component<SearchInputBarProps,
8074 return (
8175 < View style = { [ styles . centerFlex ] } >
8276 < View style = { StyleSheet . flatten ( [ styles . searchContainer , styles . centerFlex , containerStyle ] ) } >
83- < View >
84- < TouchableOpacity style = { { } } onPress = { ( ) => this . needFocus ( 'search' ) } >
85- < Icon name = "search" size = { 18 } color = "#999" height = { '100%' } { ...searchIcon } />
86- </ TouchableOpacity >
87- </ View >
77+ < TouchableOpacity style = { { } } onPress = { ( ) => this . needFocus ( 'search' ) } >
78+ < Icon name = "search" size = { 18 } color = "#999" height = { '100%' } { ...searchIcon } />
79+ </ TouchableOpacity >
8880 < TextInput
8981 { ...other }
9082 value = { value }
@@ -98,7 +90,9 @@ export default class SearchInputBar extends React.Component<SearchInputBarProps,
9890 other ?. onFocus ?.( e ) ;
9991 } }
10092 onBlur = { ( e : NativeSyntheticEvent < TextInputFocusEventData > ) => {
101- this . setState ( { showIcon : false } ) ;
93+ if ( showActionButton !== null && ! value ) {
94+ this . setState ( { showIcon : false } ) ;
95+ }
10296 other ?. onBlur ?.( e ) ;
10397 } }
10498 />
@@ -134,7 +128,7 @@ const styles = StyleSheet.create({
134128 marginRight : 10 ,
135129 } ,
136130 textInput : {
137- height : 40 ,
131+ height : '100%' ,
138132 flex : 1 ,
139133 fontSize : 18 ,
140134 paddingHorizontal : 8 ,
0 commit comments