@@ -172,11 +172,11 @@ export default class TextField extends BaseInput {
172
172
...this . state ,
173
173
value : props . value , // for floatingPlaceholder functionality
174
174
floatingPlaceholderState : new Animated . Value ( this . shouldFloatPlaceholder ( props . value ) ? 1 : 0 ) ,
175
- showExpandableModal : false
175
+ showExpandableModal : false ,
176
+ floatingPlaceholderTranslate : 0
176
177
} ;
177
178
178
179
this . generatePropsWarnings ( props ) ;
179
- this . calcPlaceholderLayout ( ) ;
180
180
}
181
181
182
182
UNSAFE_componentWillReceiveProps ( nextProps ) {
@@ -191,14 +191,10 @@ export default class TextField extends BaseInput {
191
191
}
192
192
}
193
193
194
- calcPlaceholderLayout = async ( ) => {
195
- if ( this . shouldFakePlaceholder ( ) ) {
196
- const { placeholder} = this . props ;
197
- const typography = this . getTypography ( ) ;
198
- const { width} = await Typography . measureTextSize ( placeholder , typography ) ;
199
- const translate = width / 2 - ( width * FLOATING_PLACEHOLDER_SCALE ) / 2 ;
200
- this . setState ( { floatingPlaceholderTranslate : translate / FLOATING_PLACEHOLDER_SCALE } ) ;
201
- }
194
+ onPlaceholderLayout = ( event ) => {
195
+ const { width} = event . nativeEvent . layout ;
196
+ const translate = width / 2 - ( width * FLOATING_PLACEHOLDER_SCALE ) / 2 ;
197
+ this . setState ( { floatingPlaceholderTranslate : translate / FLOATING_PLACEHOLDER_SCALE } ) ;
202
198
} ;
203
199
204
200
/** Actions */
@@ -364,14 +360,15 @@ export default class TextField extends BaseInput {
364
360
const typography = this . getTypography ( ) ;
365
361
const placeholderColor = this . getStateColor ( placeholderTextColor || PLACEHOLDER_COLOR_BY_STATE . default ) ;
366
362
367
- if ( this . shouldFakePlaceholder ( ) && floatingPlaceholderTranslate ) {
363
+ if ( this . shouldFakePlaceholder ( ) ) {
368
364
return (
369
365
< View absF left >
370
366
< Animated . Text
371
367
pointerEvents = "none"
372
368
numberOfLines = { 1 }
373
369
suppressHighlighting
374
370
accessible = { false }
371
+ onLayout = { this . onPlaceholderLayout }
375
372
style = { [
376
373
this . styles . placeholder ,
377
374
typography ,
0 commit comments