@@ -11,136 +11,134 @@ import _ from 'lodash';
1111
1212
1313export default class InputGroup extends NativeBaseComponent {
14-
15- getInitialStyle ( ) {
16- return {
17- textInput : {
18- height : this . getTheme ( ) . inputHeightBase ,
19- backgroundColor : 'transparent' ,
20- flex : 1 ,
21- flexDirection : 'row' ,
22- borderColor : this . getTheme ( ) . inputBorderColor
23- } ,
24- outerBorder : {
25- position :'relative' ,
26- borderColor : 'white' ,
27- borderWidth : 1 / PixelRatio . get ( ) ,
28- borderTopWidth : 0 ,
29- borderRightWidth : 0 ,
30- borderLeftWidth : 0 ,
31- margin : 15 ,
32- marginTop : 5
33- } ,
34- darkborder : {
35- borderColor : '#000'
36- } ,
37- lightborder : {
38- borderColor : '#fff'
39- } ,
40- underline : {
41- position :'relative' ,
42- borderWidth : 1 / PixelRatio . get ( ) ,
43- borderTopWidth : 0 ,
44- borderRightWidth : 0 ,
45- borderLeftWidth : 0 ,
46- margin : 15 ,
47- marginTop : 5
48- } ,
49-
50- bordered : {
51- position :'relative' ,
52- borderWidth : 1 / PixelRatio . get ( ) ,
53- margin : 15 ,
54- marginTop : 5
55- } ,
56-
57- rounded : {
58- position :'relative' ,
59- borderWidth : 1 / PixelRatio . get ( ) ,
60- borderRadius : 30 ,
61- margin : 15 ,
62- marginTop : 5
63- }
64- }
65- }
66-
67- prepareRootProps ( ) {
68-
69- var type = {
70- paddingLeft : ( this . props . borderType === 'rounded' && ! this . props . children . type == Icon ) ? 15 :
71- ( this . props . children . type == Icon ) ? this . getTheme ( ) . inputPaddingLeftIcon : 10
72- }
73-
74- var defaultStyle = ( this . props . borderType === 'regular' ) ? this . getInitialStyle ( ) . bordered : ( this . props . borderType === 'rounded' ) ? this . getInitialStyle ( ) . rounded : this . getInitialStyle ( ) . underline ;
75-
76- type = _ . merge ( type , defaultStyle ) ;
77-
78- var addedProps = _ . merge ( this . getInitialStyle ( ) . textInput , type ) ;
79-
80- var defaultProps = {
81- style : addedProps
82- }
83-
84- return computeProps ( this . props , defaultProps ) ;
85- }
86-
87- getIconProps ( icon ) {
88- var defaultStyle = {
89- color : this . getTheme ( ) . inputColor ,
90- fontSize : 27
91- }
92-
93- var defaultProps = {
94- style : defaultStyle
95- }
96-
97- return computeProps ( icon . props , defaultProps ) ;
98- }
99-
100- renderIcon ( ) {
101- if ( ! Array . isArray ( this . props . children ) && this . props . children . type == Icon )
102- return React . cloneElement ( this . props . children , this . getIconProps ( this . props . children ) ) ;
103-
104- else {
105- var iconRender = _ . find ( this . props . children , function ( item ) {
106- if ( item && item . type == Icon ) {
107- return true ;
108- }
109- } ) ;
110- return < Text style = { { alignSelf : 'center' } } > { React . cloneElement ( iconRender , this . getIconProps ( iconRender ) ) } </ Text >
111- }
112- }
113-
114-
115- renderInput ( ) {
116- var inputProps = { } ;
117-
118- if ( ! Array . isArray ( this . props . children ) && this . props . children . type == undefined ) {
119- inputProps = computeProps ( this . props , this . props . children . props ) ;
120- }
121-
122- else {
123- var inp = _ . find ( this . props . children , function ( item ) {
124- if ( item && item . type == undefined ) {
125- return true ;
126- }
127- } ) ;
128-
129- if ( inp )
130- inputProps = computeProps ( this . props , inp . props ) ;
131- else
132- inputProps = this . props ;
133- }
134-
135- return < Input { ...inputProps } />
136- }
137-
138- render ( ) {
139- return (
140- < View { ...this . prepareRootProps ( ) } >
141- { this . renderIcon ( ) }
142- { this . renderInput ( ) }
143- </ View >
144- ) ;
145- }
146- }
14+
15+ getInitialStyle ( ) {
16+ return {
17+ textInput : {
18+ height : this . getTheme ( ) . inputHeightBase ,
19+ backgroundColor : 'transparent' ,
20+ flex : 1 ,
21+ flexDirection : 'row' ,
22+ borderColor : this . getTheme ( ) . inputBorderColor
23+ } ,
24+ outerBorder : {
25+ position :'relative' ,
26+ borderColor : 'white' ,
27+ borderWidth : this . getTheme ( ) . borderWidth ,
28+ borderTopWidth : 0 ,
29+ borderRightWidth : 0 ,
30+ borderLeftWidth : 0 ,
31+ marginTop : 5
32+ } ,
33+ darkborder : {
34+ borderColor : '#000'
35+ } ,
36+ lightborder : {
37+ borderColor : '#fff'
38+ } ,
39+ underline : {
40+ position :'relative' ,
41+ borderWidth : this . getTheme ( ) . borderWidth ,
42+ borderTopWidth : 0 ,
43+ borderRightWidth : 0 ,
44+ borderLeftWidth : 0 ,
45+ marginTop : 5
46+ } ,
47+
48+ bordered : {
49+ position :'relative' ,
50+ borderWidth : this . getTheme ( ) . borderWidth ,
51+ marginTop : 5
52+ } ,
53+
54+ rounded : {
55+ position :'relative' ,
56+ borderWidth : this . getTheme ( ) . borderWidth ,
57+ borderRadius : 30 ,
58+ marginTop : 5
59+ }
60+ }
61+ }
62+
63+ prepareRootProps ( ) {
64+
65+ var type = {
66+ paddingLeft : ( this . props . borderType === 'rounded' && ! this . props . children . type == Icon ) ? 15 :
67+ ( this . props . children . type == Icon ) ? this . getTheme ( ) . inputPaddingLeftIcon : 10
68+ }
69+
70+ var defaultStyle = ( this . props . borderType === 'regular' ) ? this . getInitialStyle ( ) . bordered : ( this . props . borderType === 'rounded' ) ? this . getInitialStyle ( ) . rounded : this . getInitialStyle ( ) . underline ;
71+
72+ type = _ . merge ( type , defaultStyle ) ;
73+
74+ var addedProps = _ . merge ( this . getInitialStyle ( ) . textInput , type ) ;
75+
76+ var defaultProps = {
77+ style : addedProps
78+ }
79+
80+ return computeProps ( this . props , defaultProps ) ;
81+ }
82+
83+ getIconProps ( icon ) {
84+ var defaultStyle = {
85+ color : this . getTheme ( ) . inputColor ,
86+ fontSize : 27
87+ }
88+
89+ var defaultProps = {
90+ style : defaultStyle
91+ }
92+
93+ return computeProps ( icon . props , defaultProps ) ;
94+ }
95+
96+ renderIcon ( ) {
97+ if ( ! Array . isArray ( this . props . children ) && this . props . children . type == Icon )
98+ return React . cloneElement ( this . props . children , this . getIconProps ( this . props . children ) ) ;
99+
100+ else {
101+ var iconRender = _ . find ( this . props . children , function ( item ) {
102+ if ( item && item . type == Icon ) {
103+ return true ;
104+ }
105+ } ) ;
106+ if ( iconRender ) {
107+ return < Text style = { { alignSelf : 'center' } } > { React . cloneElement ( iconRender , this . getIconProps ( iconRender ) ) } </ Text >
108+
109+ }
110+ }
111+ }
112+
113+
114+ renderInput ( ) {
115+ var inputProps = { } ;
116+ if ( ! Array . isArray ( this . props . children ) && this . props . children . type == undefined ) {
117+ inputProps = computeProps ( this . props , this . props . children . props ) ;
118+ }
119+
120+ else {
121+ var inp = _ . find ( this . props . children , function ( item ) {
122+ if ( item && item . type == undefined ) {
123+ return true ;
124+ }
125+ } ) ;
126+
127+ if ( inp )
128+ inputProps = computeProps ( this . props , inp . props ) ;
129+ else
130+ inputProps = this . props ;
131+ }
132+
133+ return < Input { ...inputProps } />
134+ }
135+
136+ render ( ) {
137+ return (
138+ < View { ...this . prepareRootProps ( ) } >
139+ { this . renderIcon ( ) }
140+ { this . renderInput ( ) }
141+ </ View >
142+ ) ;
143+ }
144+ }
0 commit comments