Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

rigdern
Copy link
Contributor

@rigdern rigdern commented Nov 30, 2018

Prior to this change, when you passed text to TextInput via the value 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 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.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 30, 2018
@pull-bot
Copy link

Warnings
⚠️

📋 Release Notes - This PR appears to be missing Release Notes.

Generated by 🚫 dangerJS

@react-native-bot react-native-bot added 🔶Components Component: Text Component: TextInput Related to the TextInput component. Platform: Android Android applications. labels Nov 30, 2018
…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.
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@janicduplessis
Copy link
Contributor

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
Copy link
Contributor

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.

@react-native-bot
Copy link
Collaborator

@rigdern merged commit f6f8b09 into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Jan 9, 2019
@react-native-bot react-native-bot added the Merged This PR has been merged. label Jan 9, 2019
@rigdern rigdern deleted the rigdern/text-attributes0 branch January 9, 2019 01:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Component: Text Component: TextInput Related to the TextInput component. Merged This PR has been merged. Platform: Android Android applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants