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

Fix textTransform when used with other text styles on Android #22670

Conversation

janicduplessis
Copy link
Contributor

@janicduplessis janicduplessis commented Dec 16, 2018

On Android textTransform breaks other styles applied to the text. It seems related to the usage of ReplacementSpan which allows drawing the text manually but seems to throw away some changes made by other span applied to the text.

To fix it I removed the usage of ReplacementSpan and simply transform the text before appending it to the Spannable string. To make sure textTransform is inherited correctly I added it to TextAttributes which handles this.

Test Plan:

I added a test case to RNTester. It should render turquoise text on a blue background. It also adds line height and letter spacing to make sure the text is properly measured and all styles are applied.

Before the fix:
screen shot 2018-12-15 at 8 16 30 pm

After the fix:
screen shot 2018-12-15 at 8 15 05 pm

Also made sure all existing text transform examples produce the expected result.

Changelog:

[Android] [Fixed] - Fix textTransform when used with other text styles on Android

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Tests This PR adds or edits a test case. labels Dec 16, 2018
Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

  • eslint found some issues.

RNTester/js/TextExample.android.js Show resolved Hide resolved
@kristerkari
Copy link

This will most likely fix #21966, right?

@janicduplessis
Copy link
Contributor Author

@kristerkari I think so, I can test with an example from the issue

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.

@rigdern
Copy link
Contributor

rigdern commented Dec 17, 2018

@janicduplessis I have a question about setTextTransform (I know you didn't change it in this PR).

The default for mTextTransform is UNSET but setTextTransform maps null to NONE. Is this a bug? Should setTextTransform be mapping null to UNSET instead?

@janicduplessis
Copy link
Contributor Author

@rigdern Quite possible, I just tested on snack but textTransform on android doesn't work on latest expo yet.

This should print aB

<Text style={{textTransform: 'uppercase'}}>
  <Text style={{textTransform: 'none'}}>a</Text>
  <Text style={{textTransform: null}}>b</Text>
</Text>

I can test it when I get on a computer.

@janicduplessis
Copy link
Contributor Author

@rigdern you were right #22694

@hramos
Copy link
Contributor

hramos commented Jan 11, 2019

@rigdern's changes landed in f6f8b09. @janicduplessis do you still want your changes to be incorporated? If so, let me know if you can resolve the conflicts.

Thanks to both of you for working on getting these issues addressed!

@janicduplessis
Copy link
Contributor Author

@hramos Looks like #22917 will also conflict with this. I think we should try to land #22917 first and then I can rebase this on top of the improvements to text inheritance that @rigdern implemented.

@rigdern
Copy link
Contributor

rigdern commented Jan 15, 2019

@janicduplessis #22917 has been merged.

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

  • eslint found some issues.

RNTester/js/TextExample.android.js Show resolved Hide resolved
@janicduplessis
Copy link
Contributor Author

@hramos @rigdern Rebased on top of #22917 and re-tested to make sure everything still works. I also included the little fix in #22694 since I ended up changing these lines.

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

  • eslint found some issues.

RNTester/js/TextExample.android.js Show resolved Hide resolved
Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

  • eslint found some issues.

@@ -600,6 +600,18 @@ class TextExample extends React.Component<{}> {
'.aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd '
}
</Text>
<Text
style={{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react-native/no-inline-styles: Inline style: { textTransform: 'uppercase',
fontSize: 16,
color: 'turquoise',
backgroundColor: 'blue',
lineHeight: 32,
letterSpacing: 2,
alignSelf: 'flex-start' }

@rigdern
Copy link
Contributor

rigdern commented Jan 24, 2019

@janicduplessis The PR description says:

To do that I can pass the parent's textTransform when recursing through text shadow nodes.

This sentence seems to need to be updated now that this information is passed around via TextAttributes.java

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jan 25, 2019
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.

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

@janicduplessis merged commit 3a33e75 into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Jan 25, 2019
@react-native-bot react-native-bot added the Merged This PR has been merged. label Jan 25, 2019
@hramos hramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 6, 2019
matt-oakes pushed a commit to matt-oakes/react-native that referenced this pull request Feb 7, 2019
…ok#22670)

Summary:
On Android `textTransform` breaks other styles applied to the text. It seems related to the usage of `ReplacementSpan` which allows drawing the text manually but seems to throw away some changes made by other span applied to the text.

To fix it I removed the usage of `ReplacementSpan` and simply transform the text before appending it to the `Spannable` string. To make sure textTransform is inherited correctly I added it to TextAttributes which handles this.
Pull Request resolved: facebook#22670

Differential Revision: D13494819

Pulled By: cpojer

fbshipit-source-id: 1c69591084aa906c2d3b10153b354d39c0936340
rozele pushed a commit to microsoft/react-native-windows that referenced this pull request Jul 18, 2019
Summary:
On Android `textTransform` breaks other styles applied to the text. It seems related to the usage of `ReplacementSpan` which allows drawing the text manually but seems to throw away some changes made by other span applied to the text.

To fix it I removed the usage of `ReplacementSpan` and simply transform the text before appending it to the `Spannable` string. To make sure textTransform is inherited correctly I added it to TextAttributes which handles this.
Pull Request resolved: facebook/react-native#22670

Differential Revision: D13494819

Pulled By: cpojer

fbshipit-source-id: 1c69591084aa906c2d3b10153b354d39c0936340
@facebook-github-bot facebook-github-bot added the Contributor A React Native contributor. label Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Component: Text Contributor A React Native contributor. Merged This PR has been merged. Platform: Android Android applications. Tests This PR adds or edits a test case.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants