-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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 textTransform style support #20572
Android textTransform style support #20572
Conversation
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 working on this!
Looks good, we just need to improve the capitalize implementation to be more robust and consistent with iOS.
return transformed; | ||
} | ||
|
||
private String capitalize(String rawString) { |
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.
This will need to be a bit more robust to match iOS's [NSString capitalizedString]
. I did some testing and something like this seems to work well and produce the same result as iOS.
import java.text.BreakIterator;
...
String text = ".aa\nbb\tcc dd EE \r\nZZ I like to eat apples. 中文éé 我喜欢吃苹果。awdawd ";
BreakIterator wordIterator = BreakIterator.getWordInstance();
wordIterator.setText(text);
StringBuilder res = new StringBuilder(text.length());
int start = wordIterator.first();
for (int end = wordIterator.next(); end != BreakIterator.DONE; end = wordIterator.next()) {
String word = text.substring(start, end);
if (Character.isLetterOrDigit(word.charAt(0))) {
res.append(Character.toUpperCase(word.charAt(0)));
res.append(word.substring(1).toLowerCase());
} else {
res.append(word);
}
start = end;
}
Log.d("test", res.toString());
(based on https://stackoverflow.com/a/42219474)
Might be nice to also add some more complex test cases like this. Could be a good candidate for some unit tests too.
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.
Nice, thanks for this! I've used your suggestion in c580a50 and included your test string in the test view, as well as writing some UTs.
Although, I'm struggling to run them and I've noticed this in the UTs BUCK file:
rn_robolectric_test(
name = "views",
# TODO Disabled temporarily until Yoga linking is fixed t14964130
# srcs = glob(['**/*.java']),
srcs = glob(["image/*.java"]),
I can't see that issue, or run the Text UTs without hitting the linking issue mentioned 🤔 (so my UTs... probably work? 😅)
Not sure if anyone knows a way around this?
@facebook-github-bot shipit |
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.
janicduplessis is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
This pull request was closed by Stephen Cook in 22cf5dc. Once this commit is added to a release, you will see the corresponding version tag below the description at 22cf5dc. If the commit has a single |
Summary: Issue #2088 (closed, but a bit pre-emptively imo, since Android support was skipped) Related (merged) iOS PR #18387 Related documentation PR facebook/react-native-website#500 The basic desire is to have a declarative mechanism to transform text content to uppercase or lowercase or titlecase ("capitalized"). Pull Request resolved: #20572 Differential Revision: D9311716 Pulled By: hramos fbshipit-source-id: dfbb855117196958e7ae5e980700d31be07a448d
Summary: Issue facebook/react-native#2088 (closed, but a bit pre-emptively imo, since Android support was skipped) Related (merged) iOS PR facebook/react-native#18387 Related documentation PR facebook/react-native-website#500 The basic desire is to have a declarative mechanism to transform text content to uppercase or lowercase or titlecase ("capitalized"). Pull Request resolved: facebook/react-native#20572 Differential Revision: D9311716 Pulled By: hramos fbshipit-source-id: dfbb855117196958e7ae5e980700d31be07a448d
Issue #2088 (closed, but a bit pre-emptively imo, since Android support was skipped)
Related (merged) iOS PR #18387
Related documentation PR facebook/react-native-website#500
The basic desire is to have a declarative mechanism to transform text content to uppercase or lowercase or titlecase ("capitalized").
Test Plan:
My test plan involves having copied exactly the iOS test-case, i.e. adding a test-case to the RNTester app within the component area. I then manually verified that the rendered content met my expectation.
The test itself is:
And here is what that looks like:
Release Notes:
[ANDROID] [ENHANCEMENT] [Text] - added textTransform style property enabling declarative casing transformations