Closed CostachescuCristinel closed 7 months ago
A bunch of these bugs seem to be related. https://github.com/facebook/react-native/issues/31573, also points to some weird state when multiline is enabled.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.
Description
It seems that
TextInput
s withmultiline={true}
, but which do not specify eithervalue
ordefaultValue
, behave somewhat unexpectedly on both iOS and Sndroid.On both iOS and Android, the text
color
does not update even if thestyle
prop changes and specifies a different value. This does not happen if theTextInput
hasmultiline={false}
(or nomultiline
prop specified). For sure, thecolor
styling prop is affected, but I haven't tested other props.On Android, if there is no
value
ordefaultValue
specified, theTextInput
will completely loose any typed text on each re-render. If there isdefaultValue
specified, theTextInput
will reset to the values specified by it (again, any changes immediately lost on the next re-render). This happens for bothmultiline={true}
andmultiline={false}
.Admittedly, this may not be a huge issue, there's no reason to have a
TextInput
with novalue
prop. However, in early development stages where developers only get the UI done with mostly no logic or actual data, this can be a source of issues. I have personally lost 2 hours trying to figure out why the styles did not update correctly in a custom component with complicated styling logic.React Native version:
Steps To Reproduce
Please see the snack below for a complete test. TLDR, render multiple
TextInput
s with differentmultiline
,value
anddefaultValue
props (unspecified/undefined, and true/false), save style in state, use state as style for the inputs. update state and compare render output.Expected Results
The
TextInput
s should respect thecolor
prop in the style for bothmultiline={true}
andmultiline={false}
, but only themultiline={false}
will actually do. On Android, theTextInput
s should keep any typed text even if novalue
ordefaultValue
is specified, but neither will.Snack, code example, screenshot, or link to a repository:
https://snack.expo.io/@cristian-nxtl/uncontrolled-textinput---style-not-updating-with-multiline-true-ios-android---text-lost-android