Skip to content

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

Closed
janicduplessis wants to merge 4 commits into
react:masterfrom
janicduplessis:fix-android-text-transform
Closed

Fix textTransform when used with other text styles on Android#22670
janicduplessis wants to merge 4 commits into
react:masterfrom
janicduplessis:fix-android-text-transform

Conversation

@janicduplessis

@janicduplessisjanicduplessis commented Dec 16, 2018

Copy link
Copy Markdown
Contributor

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-botfacebook-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

@analysis-botanalysis-bot left a comment

Copy link
Copy Markdown

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.

Comment threadRNTester/js/TextExample.android.js Outdated
@kristerkari

Copy link
Copy Markdown

This will most likely fix #21966, right?

@janicduplessis

Copy link
Copy Markdown
ContributorAuthor

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

@facebook-github-botfacebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

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

@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
Copy Markdown
ContributorAuthor

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

This should print aB

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

I can test it when I get on a computer.

@janicduplessis

Copy link
Copy Markdown
ContributorAuthor

@rigdern you were right #22694

@hramos

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
ContributorAuthor

@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
Copy Markdown
Contributor

@janicduplessis#22917 has been merged.

@janicduplessis
janicduplessisforce-pushed the fix-android-text-transform branch from 15768b5 to ca640dbCompareJanuary 19, 2019 05:45

@analysis-botanalysis-bot left a comment

Copy link
Copy Markdown

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.

Comment threadRNTester/js/TextExample.android.js
@janicduplessis

Copy link
Copy Markdown
ContributorAuthor

@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.

@analysis-botanalysis-bot left a comment

Copy link
Copy Markdown

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.

Comment threadRNTester/js/TextExample.android.js

@analysis-botanalysis-bot left a comment

Copy link
Copy Markdown

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.

}
</Text>
<Text
style={{

Copy link
Copy Markdown

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

@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-botfacebook-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

@facebook-github-botfacebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

@janicduplessis merged commit 3a33e75 into facebook:master.

@reactreact locked as resolved and limited conversation to collaborators Jan 25, 2019
@react-native-botreact-native-bot added the Merged This PR has been merged. label Jan 25, 2019
@hramoshramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 6, 2019
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: react/react-native#22670
Differential Revision: D13494819
Pulled By: cpojer
fbshipit-source-id: 1c69591084aa906c2d3b10153b354d39c0936340
@facebook-github-botfacebook-github-bot added the Contributor A React Native contributor. label Apr 15, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

BugCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.Component: TextContributorA React Native contributor.MergedThis PR has been merged.Platform: AndroidAndroid applications.TestsThis PR adds or edits a test case.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@janicduplessis@kristerkari@rigdern@hramos@react-native-bot@cpojer@facebook-github-bot@analysis-bot