|
8 | 8 | import React, {useMemo} from 'react';
|
9 | 9 | import {StyleSheet} from 'react-native';
|
10 | 10 | import {isEmpty, trim, omit} from 'lodash';
|
11 |
| -import {asBaseComponent, forwardRef} from '../../commons/new'; |
| 11 | +import {asBaseComponent, Constants, forwardRef} from '../../commons/new'; |
12 | 12 | import View from '../../components/view';
|
| 13 | +import Text from '../../components/text'; |
13 | 14 | import {useMeasure} from '../../hooks';
|
14 | 15 | import {
|
15 | 16 | TextFieldProps,
|
@@ -72,6 +73,7 @@ const TextField = (props: InternalTextFieldProps) => {
|
72 | 73 | placeholder,
|
73 | 74 | children,
|
74 | 75 | centered = false,
|
| 76 | + inline = false, |
75 | 77 | ...others
|
76 | 78 | } = usePreset(props);
|
77 | 79 | const {ref: leadingAccessoryRef, measurements: leadingAccessoryMeasurements} = useMeasure();
|
@@ -130,30 +132,39 @@ const TextField = (props: InternalTextFieldProps) => {
|
130 | 132 | <View style={[paddings, fieldStyle]} row centerV centerH={centered}>
|
131 | 133 | {/* <View row centerV> */}
|
132 | 134 | {leadingAccessoryClone}
|
133 |
| - {children || <View flex={!centered} flexG={centered} /* flex row */> |
134 |
| - {floatingPlaceholder && ( |
135 |
| - <FloatingPlaceholder |
136 |
| - defaultValue={others.defaultValue} |
| 135 | + {/* Note: We should avoid flexing this when the input is inlined or centered*/} |
| 136 | + {children || ( |
| 137 | + <View flex={!centered && !inline}> |
| 138 | + {/* Note: Render dummy placeholder for Android center issues */} |
| 139 | + {Constants.isAndroid && (centered || inline) && ( |
| 140 | + <Text marginR-s1 style={styles.dummyPlaceholder}> |
| 141 | + {placeholder} |
| 142 | + </Text> |
| 143 | + )} |
| 144 | + {floatingPlaceholder && ( |
| 145 | + <FloatingPlaceholder |
| 146 | + defaultValue={others.defaultValue} |
| 147 | + placeholder={placeholder} |
| 148 | + floatingPlaceholderStyle={_floatingPlaceholderStyle} |
| 149 | + floatingPlaceholderColor={floatingPlaceholderColor} |
| 150 | + floatOnFocus={floatOnFocus} |
| 151 | + validationMessagePosition={validationMessagePosition} |
| 152 | + extraOffset={leadingAccessoryMeasurements?.width} |
| 153 | + testID={`${props.testID}.floatingPlaceholder`} |
| 154 | + /> |
| 155 | + )} |
| 156 | + <Input |
| 157 | + placeholderTextColor={hidePlaceholder ? 'transparent' : placeholderTextColor} |
| 158 | + {...others} |
| 159 | + style={[typographyStyle, colorStyle, others.style]} |
| 160 | + onFocus={onFocus} |
| 161 | + onBlur={onBlur} |
| 162 | + onChangeText={onChangeText} |
137 | 163 | placeholder={placeholder}
|
138 |
| - floatingPlaceholderStyle={_floatingPlaceholderStyle} |
139 |
| - floatingPlaceholderColor={floatingPlaceholderColor} |
140 |
| - floatOnFocus={floatOnFocus} |
141 |
| - validationMessagePosition={validationMessagePosition} |
142 |
| - extraOffset={leadingAccessoryMeasurements?.width} |
143 |
| - testID={`${props.testID}.floatingPlaceholder`} |
| 164 | + hint={hint} |
144 | 165 | />
|
145 |
| - )} |
146 |
| - <Input |
147 |
| - placeholderTextColor={hidePlaceholder ? 'transparent' : placeholderTextColor} |
148 |
| - {...others} |
149 |
| - style={[typographyStyle, colorStyle, others.style]} |
150 |
| - onFocus={onFocus} |
151 |
| - onBlur={onBlur} |
152 |
| - onChangeText={onChangeText} |
153 |
| - placeholder={placeholder} |
154 |
| - hint={hint} |
155 |
| - /> |
156 |
| - </View>} |
| 166 | + </View> |
| 167 | + )} |
157 | 168 | {trailingAccessory}
|
158 | 169 | {/* </View> */}
|
159 | 170 | </View>
|
@@ -206,5 +217,8 @@ const styles = StyleSheet.create({
|
206 | 217 | centeredValidationMessage: {
|
207 | 218 | flexGrow: 1,
|
208 | 219 | textAlign: 'center'
|
| 220 | + }, |
| 221 | + dummyPlaceholder: { |
| 222 | + height: 0 |
209 | 223 | }
|
210 | 224 | });
|
0 commit comments