@@ -125,7 +125,7 @@ export default class TextField extends BaseInput {
125
125
*/
126
126
transformer : PropTypes . func ,
127
127
/**
128
- * Pass to render a prefix text as part of the input
128
+ * Pass to render a prefix text as part of the input (doesn't work with floatingPlaceholder)
129
129
*/
130
130
prefix : PropTypes . string ,
131
131
/**
@@ -172,7 +172,11 @@ export default class TextField extends BaseInput {
172
172
iconColor : PropTypes . string ,
173
173
onPress : PropTypes . func ,
174
174
style : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number ] )
175
- } )
175
+ } ) ,
176
+ /**
177
+ * Pass to render a leading icon to the TextInput value. Accepts Image props (doesn't work with floatingPlaceholder)
178
+ */
179
+ leadingIcon : PropTypes . shape ( Image . propTypes )
176
180
} ;
177
181
178
182
static defaultProps = {
@@ -310,8 +314,7 @@ export default class TextField extends BaseInput {
310
314
}
311
315
312
316
getTopPaddings ( ) {
313
- const { floatingPlaceholder} = this . getThemeProps ( ) ;
314
- return floatingPlaceholder ? ( this . shouldShowTopError ( ) ? undefined : 25 ) : undefined ;
317
+ return this . shouldFakePlaceholder ( ) ? ( this . shouldShowTopError ( ) ? undefined : 25 ) : undefined ;
315
318
}
316
319
317
320
isDisabled ( ) {
@@ -345,8 +348,9 @@ export default class TextField extends BaseInput {
345
348
}
346
349
347
350
shouldFakePlaceholder ( ) {
348
- const { floatingPlaceholder, centered} = this . getThemeProps ( ) ;
349
- return Boolean ( floatingPlaceholder && ! centered && ! this . shouldShowTopError ( ) ) ;
351
+ const { floatingPlaceholder, centered, leadingIcon, prefix} = this . getThemeProps ( ) ;
352
+
353
+ return ! leadingIcon && ! prefix && Boolean ( floatingPlaceholder && ! centered && ! this . shouldShowTopError ( ) ) ;
350
354
}
351
355
352
356
shouldShowError ( ) {
@@ -389,6 +393,9 @@ export default class TextField extends BaseInput {
389
393
style = { [
390
394
this . styles . placeholder ,
391
395
typography ,
396
+ // TODO: we need to exclude completely any dependency on line height
397
+ // in this component since it always breaks alignments
398
+ { lineHeight : undefined } ,
392
399
{
393
400
transform : [
394
401
{
@@ -627,7 +634,7 @@ export default class TextField extends BaseInput {
627
634
}
628
635
629
636
render ( ) {
630
- const { expandable, containerStyle, underlineColor, useTopErrors, hideUnderline} = this . getThemeProps ( ) ;
637
+ const { expandable, containerStyle, underlineColor, useTopErrors, hideUnderline, leadingIcon } = this . getThemeProps ( ) ;
631
638
const underlineStateColor = this . getStateColor ( underlineColor || UNDERLINE_COLOR_BY_STATE ) ;
632
639
633
640
return (
@@ -642,6 +649,7 @@ export default class TextField extends BaseInput {
642
649
{ paddingTop : this . getTopPaddings ( ) }
643
650
] }
644
651
>
652
+ { leadingIcon && < Image { ...leadingIcon } /> }
645
653
{ this . renderPrefix ( ) }
646
654
{ this . renderPlaceholder ( ) }
647
655
{ expandable ? this . renderExpandableInput ( ) : this . renderTextInput ( ) }
0 commit comments