55 * 3. Passing typography preset that includes lineHeight usually cause alignment issues with
66 * other elements (leading/trailing accessories). It usually best to set lineHeight with undefined
77 */
8+ import { isEmpty , trim , omit } from 'lodash' ;
89import React , { useMemo } from 'react' ;
910import { StyleSheet } from 'react-native' ;
10- import { isEmpty , trim , omit } from 'lodash' ;
1111import { asBaseComponent , Constants , forwardRef } from '../../commons/new' ;
1212import View from '../view' ;
1313import Text from '../text' ;
@@ -92,6 +92,7 @@ const TextField = (props: InternalTextFieldProps) => {
9292 showMandatoryIndication,
9393 ...others
9494 } = usePreset ( props ) ;
95+
9596 const { ref : leadingAccessoryRef , measurements : leadingAccessoryMeasurements } = useMeasure ( ) ;
9697 const { onFocus, onBlur, onChangeText, fieldState, validateField, checkValidity} = useFieldState ( others ) ;
9798
@@ -118,28 +119,23 @@ const TextField = (props: InternalTextFieldProps) => {
118119 const colorStyle = useMemo ( ( ) => color && { color} , [ color ] ) ;
119120 const _floatingPlaceholderStyle = useMemo ( ( ) => [ typographyStyle , floatingPlaceholderStyle ] ,
120121 [ typographyStyle , floatingPlaceholderStyle ] ) ;
121-
122122 const fieldStyle = [ fieldStyleProp , dynamicFieldStyle ?.( context , { preset : props . preset } ) ] ;
123123 const hidePlaceholder = shouldHidePlaceholder ( props , fieldState . isFocused ) ;
124124 const retainTopMessageSpace = ! floatingPlaceholder && isEmpty ( trim ( label ) ) ;
125125 const centeredContainerStyle = centered && styles . centeredContainer ;
126- const _labelStyle = useMemo ( ( ) => ( centered ? [ labelStyle , styles . centeredLabel ] : labelStyle ) ,
127- [ labelStyle , centered ] ) ;
128- const _validationMessageStyle = useMemo ( ( ) => {
129- return centered ? [ validationMessageStyle , styles . centeredValidationMessage ] : validationMessageStyle ;
130- } , [ validationMessageStyle , centered ] ) ;
126+ const centeredTextStyle = centered && styles . centeredText ;
127+ const _labelStyle = useMemo ( ( ) => [ labelStyle , centeredTextStyle ] , [ labelStyle , centeredTextStyle ] ) ;
128+ const _validationMessageStyle = useMemo ( ( ) => [ validationMessageStyle , centeredTextStyle ] ,
129+ [ validationMessageStyle , centeredTextStyle ] ) ;
131130 const hasValue = fieldState . value !== undefined ;
132- const inputStyle = useMemo ( ( ) => {
133- return [ typographyStyle , colorStyle , others . style , hasValue && centered && styles . centeredInput ] ;
134- } , [ typographyStyle , colorStyle , others . style , centered , hasValue ] ) ;
135- const dummyPlaceholderStyle = useMemo ( ( ) => {
136- return [ inputStyle , styles . dummyPlaceholder ] ;
137- } , [ inputStyle ] ) ;
131+ const inputStyle = useMemo ( ( ) => [ typographyStyle , colorStyle , others . style , hasValue && centeredTextStyle ] ,
132+ [ typographyStyle , colorStyle , others . style , centeredTextStyle , hasValue ] ) ;
133+ const dummyPlaceholderStyle = useMemo ( ( ) => [ inputStyle , styles . dummyPlaceholder ] , [ inputStyle ] ) ;
138134
139135 return (
140136 < FieldContext . Provider value = { context } >
141137 < View { ...containerProps } style = { [ margins , positionStyle , containerStyle , centeredContainerStyle ] } >
142- < View row spread >
138+ < View row spread centerV = { Constants . isAndroid } style = { centeredContainerStyle } >
143139 < Label
144140 label = { label }
145141 labelColor = { labelColor }
@@ -161,7 +157,7 @@ const TextField = (props: InternalTextFieldProps) => {
161157 testID = { `${ props . testID } .validationMessage` }
162158 />
163159 ) }
164- { topTrailingAccessory }
160+ { topTrailingAccessory && < View > { topTrailingAccessory } </ View > }
165161 </ View >
166162 < View style = { [ paddings , fieldStyle ] } row centerV centerH = { centered } >
167163 { /* <View row centerV> */ }
@@ -259,6 +255,7 @@ export {
259255 MandatoryIndication as TextFieldMandatoryIndication ,
260256 TextFieldValidators
261257} ;
258+
262259export default asBaseComponent < TextFieldProps , StaticMembers , TextFieldRef > ( forwardRef ( TextField as any ) , {
263260 modifiersOptions : {
264261 margins : true ,
@@ -273,13 +270,7 @@ const styles = StyleSheet.create({
273270 centeredContainer : {
274271 alignSelf : 'center'
275272 } ,
276- centeredLabel : {
277- textAlign : 'center'
278- } ,
279- centeredInput : {
280- textAlign : 'center'
281- } ,
282- centeredValidationMessage : {
273+ centeredText : {
283274 textAlign : 'center'
284275 } ,
285276 dummyPlaceholder : {
0 commit comments