Skip to content

Commit 2cc8641

Browse files
fix: Fix initial label position when value is set on React Native >= 0.61
1 parent a069062 commit 2cc8641

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/components/TextInput/TextInput.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,20 @@ class TextInput extends React.Component<TextInputProps, State> {
184184
}
185185

186186
state = {
187-
labeled: new Animated.Value(this.props.value ? 0 : 1),
187+
labeled: new Animated.Value(
188+
(this.props.value !== undefined
189+
? this.props.value
190+
: this.props.defaultValue)
191+
? 0
192+
: 1
193+
),
188194
error: new Animated.Value(this.props.error ? 1 : 0),
189195
focused: false,
190196
placeholder: '',
191-
value: this.props.value || this.props.defaultValue,
197+
value:
198+
this.props.value !== undefined
199+
? this.props.value
200+
: this.props.defaultValue,
192201
labelLayout: {
193202
measured: false,
194203
width: 0,
@@ -202,7 +211,9 @@ class TextInput extends React.Component<TextInputProps, State> {
202211
if (
203212
prevState.focused !== this.state.focused ||
204213
prevState.value !== this.state.value ||
205-
this.props.defaultValue
214+
// workaround for animated regression for react native > 0.61
215+
// https://github.com/callstack/react-native-paper/pull/1440
216+
prevState.labelLayout !== this.state.labelLayout
206217
) {
207218
// The label should be minimized if the text input is focused, or has text
208219
// In minimized mode, the label moves up and becomes small

0 commit comments

Comments
 (0)