-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android TextInput: Improve application of styles for value
prop
#22461
Conversation
Generated by 🚫 dangerJS |
…lue` or `defaultValue` props, React Native didn't apply any of the styles in `buildSpannedFromShadowNode` to the text. This is because `spannedFromShadowNode` appends `value` after calling `buildSpannedFromShadowNode`. Many styles worked because their logic is included in both `buildSpannedFromShadowNode` and `ReactTextInputManager`. However, some only appear in `buildSpannedFromShadowNode` such as `textDecorationLine` (it would be good to understand why we need to duplicate styling logic in `buildSpannedFromShadowNode` & `ReactTextInputManager` and to know whether `ReactTextInputManager` should be handling `textDecorationLine`). Also, this commit improves consistency between iOS and Android if you specify both `value` and children on a `TextInput`. Prior to this, iOS concatenated the strings such that the `value` prop came before the children whereas Android put the children before the `value` prop. Now Android matches iOS's behavior and puts the `value` prop before the children. These appear to be regressions. The `value` prop used to be appended before calling `buildSpannedFromShadowNode` (this behavior appears to have been changed by accident in facebook@80027ce#diff-4f5947f2fe0381c4a6373a30e596b8c3). The fix is to append the `value` prop before calling `buildSpannedFromShadowNode`. Additionally, we have to expose a new `start` parameter on `buildSpannedFromShadowNode` so that we can tell it to include the text from the `value` prop in the range that it styles. Without this, the start of the styled text would be immediately after `value` because `value` is appended before calling `buildSpannedFromShadowNode`. Test Plan: ---------- Used a variety of props to style some `TextInputs` (e.g. `textDecorationLine`, `fontSize`, `letterSpacing`). Verified that the `TextInputs` looked the same regardless of whether the text was provided via the `value` prop, children, or both. Changelog: ---------- [Android] [Fixed] - TextInput: Improve application of styles for `value` prop Adam Comella Microsoft Corp.
141bba9
to
df28436
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Heads up this will probably conflict with #22670, whichever lands first. |
if (text != null) { | ||
// Handle text that is provided via a prop (e.g. the `value` and `defaultValue` props on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this, took me a while to figure out what this was for when working on fixing textTransform.
Prior to this change, when you passed text to
TextInput
via thevalue
ordefaultValue
props, React Native didn't apply any of the styles inbuildSpannedFromShadowNode
to the text. This is becausespannedFromShadowNode
appendsvalue
after callingbuildSpannedFromShadowNode
. Many styles worked because their logic is included in bothbuildSpannedFromShadowNode
andReactTextInputManager
. However, some only appear inbuildSpannedFromShadowNode
such astextDecorationLine
(it would be good to understand why we need to duplicate styling logic inbuildSpannedFromShadowNode
&ReactTextInputManager
and to know whetherReactTextInputManager
should be handlingtextDecorationLine
).Also, this commit improves consistency between iOS and Android if you specify both
value
and children on aTextInput
. Prior to this, iOS concatenated the strings such that thevalue
prop came before the children whereas Android put the children before thevalue
prop. Now Android matches iOS's behavior and puts thevalue
prop before the children.These appear to be regressions. The
value
prop used to be appended before callingbuildSpannedFromShadowNode
(this behavior appears to have been changed by accident in 80027ce#diff-4f5947f2fe0381c4a6373a30e596b8c3).The fix is to append the
value
prop before callingbuildSpannedFromShadowNode
. Additionally, we have to expose a newstart
parameter onbuildSpannedFromShadowNode
so that we can tell it to include the text from thevalue
prop in the range that it styles. Without this, the start of the styled text would be immediately aftervalue
becausevalue
is appended before callingbuildSpannedFromShadowNode
Test Plan:
Used a variety of props to style some
TextInputs
(e.g.textDecorationLine
,fontSize
,letterSpacing
). Verified that theTextInputs
looked the same regardless of whether the text was provided via thevalue
prop, children, or both.Changelog:
[Android] [Fixed] - TextInput: Improve application of styles for
value
propAdam Comella
Microsoft Corp.