6
6
* other elements (leading/trailing accessories). It usually best to set lineHeight with undefined
7
7
*/
8
8
import React , { useMemo } from 'react' ;
9
+ import { StyleSheet } from 'react-native' ;
9
10
import { isEmpty , trim , omit } from 'lodash' ;
10
11
import { asBaseComponent , forwardRef } from '../../commons/new' ;
11
12
import View from '../../components/view' ;
@@ -70,6 +71,7 @@ const TextField = (props: InternalTextFieldProps) => {
70
71
// Input
71
72
placeholder,
72
73
children,
74
+ centered = false ,
73
75
...others
74
76
} = usePreset ( props ) ;
75
77
const { ref : leadingAccessoryRef , measurements : leadingAccessoryMeasurements } = useMeasure ( ) ;
@@ -96,14 +98,16 @@ const TextField = (props: InternalTextFieldProps) => {
96
98
const fieldStyle = [ fieldStyleProp , dynamicFieldStyle ?.( context , { preset : props . preset } ) ] ;
97
99
const hidePlaceholder = shouldHidePlaceholder ( props , fieldState . isFocused ) ;
98
100
const retainTopMessageSpace = ! floatingPlaceholder && isEmpty ( trim ( label ) ) ;
101
+ const centeredContainerStyle = centered && styles . centeredContainer ;
102
+ const centeredLabelStyle = centered && styles . centeredLabel ;
99
103
100
104
return (
101
105
< FieldContext . Provider value = { context } >
102
- < View style = { [ margins , positionStyle , containerStyle ] } >
106
+ < View style = { [ margins , positionStyle , containerStyle , centeredContainerStyle ] } >
103
107
< Label
104
108
label = { label }
105
109
labelColor = { labelColor }
106
- labelStyle = { labelStyle }
110
+ labelStyle = { [ labelStyle , centeredLabelStyle ] }
107
111
labelProps = { labelProps }
108
112
floatingPlaceholder = { floatingPlaceholder }
109
113
validationMessagePosition = { validationMessagePosition }
@@ -122,7 +126,7 @@ const TextField = (props: InternalTextFieldProps) => {
122
126
< View style = { [ paddings , fieldStyle ] } row centerV >
123
127
{ /* <View row centerV> */ }
124
128
{ leadingAccessoryClone }
125
- < View flexG /* flex row */ >
129
+ < View flex = { ! centered } flexG = { centered } /* flex row */ >
126
130
{ floatingPlaceholder && (
127
131
< FloatingPlaceholder
128
132
placeholder = { placeholder }
@@ -188,3 +192,12 @@ export default asBaseComponent<TextFieldProps, StaticMembers>(forwardRef(TextFie
188
192
color : true
189
193
}
190
194
} ) ;
195
+
196
+ const styles = StyleSheet . create ( {
197
+ centeredContainer : {
198
+ alignSelf : 'center'
199
+ } ,
200
+ centeredLabel : {
201
+ textAlign : 'center'
202
+ }
203
+ } ) ;
0 commit comments