Fix capitalize Text style on IOS#32774
Conversation
Base commit: 3bd1159 |
Base commit: 3bd1159 |
|
Thanks for the contribution! It is interesting that web preserves pre-existing capitalized letters. I agree that we do not need to consider that as part of this PR, but it is interesting to consider which behavior is desirable longer term. |
|
@yungsters has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
Hi there! For testing it with RN-tester, can you please try removing Pods folder, Podfile.lock, and build folder before running pod install with fabric_enabled off? |
118e09e to
2a7e0ef
Compare
|
Thanks for your quick answers! I managed to launch rn-tester without fabric thanks to you @sota000! I'll edit my first comment to add screenshots. |
There was a problem hiding this comment.
we prefer to use new if there's no initializer params
There was a problem hiding this comment.
Oh I didn't know this syntax. Done!
There was a problem hiding this comment.
let's add one for 2 digit dates as well
There was a problem hiding this comment.
why aren't we just joining on newWords? NSString's description is just the string itself
There was a problem hiding this comment.
Yes you're right. Fixed!
There was a problem hiding this comment.
can you make this a C function? i.e.
static NSString *CapitalizeText(NSString *text) {
...
}
this is more lightweight and the function does not require any state from this class.
There was a problem hiding this comment.
I think this is good. Tell me if it isn't!
As you can see with the code I wrote, I'm not familiar with Objective-C. I learned while I was making this PR 😁 So, thanks a lot for taking the time to review this PR, I learned a lot!
It would crash the app if there were several spaces in a row
Also rename the function to be clearer
2a7e0ef to
3fb165a
Compare
|
@yungsters has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
This pull request was successfully merged by @MaeIg in 8b5a5d4. When will my fix make it into a release? | Upcoming Releases |
Summary: <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> Few month ago, I created a [pull request](#32774) to unify the behavior of capitalize style between Android and IOS. But, I found out that it doesn't work when fabric is enabled. We have the old behavior : | Android | IOS | | ------------- | ------------- | | <img width="458" alt="capitalize_android_fabric" src="https://user-images.githubusercontent.com/40902940/163182082-4061003c-230b-46f7-9e93-c34b66dbf3d2.png"> | <img width="476" alt="capitalize_ios_fabric" src="https://user-images.githubusercontent.com/40902940/163182124-b6dee450-46e3-41a3-b5bb-553d7c2662e6.png"> | (source: rn-tester, last commit: dac56ce) As fabric is now live since v0.68, we should fix this behavior for fabric aswell. I don't know why there is so much duplicated code between `ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm` and `Libraries/Text/RCTTextAttributes.m` because I don't know the architecture of the project very well. But if you see missing tests or some refacto to do I'm open to suggestions! ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Fixed] - Don't capitalize the first letter of a word that is starting by a number (Fabric renderer) Pull Request resolved: #33629 Test Plan: I manually tested these changes on rn-tester (react-native `main` branch): | Fabric ? | Android | IOS | | ------------- | ------------- | ------------- | | YES | <img width="458" alt="capitalize_android_fabric" src="https://user-images.githubusercontent.com/40902940/163182082-4061003c-230b-46f7-9e93-c34b66dbf3d2.png"> | <img width="476" alt="capitalize_ios_fabric_after" src="https://user-images.githubusercontent.com/40902940/163184277-6c58c117-7144-4f6b-98ea-0c1db654f27b.png"> | | NO | <img width="458" alt="android_nf_after" src="https://user-images.githubusercontent.com/40902940/163190263-9d801f6a-09c2-4ec6-a841-3dca115a5ef7.png"> | <img width="476" alt="ios_nf_after" src="https://user-images.githubusercontent.com/40902940/163190333-7e9eac6a-3f28-4826-8ef9-bcf45bf870a9.png"> | Reviewed By: cortinico Differential Revision: D35611086 Pulled By: GijsWeterings fbshipit-source-id: 0c43807dcddb30e65921eb1525c0fe440162ec32
…33629) Summary: <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> Few month ago, I created a [pull request](react#32774) to unify the behavior of capitalize style between Android and IOS. But, I found out that it doesn't work when fabric is enabled. We have the old behavior : | Android | IOS | | ------------- | ------------- | | <img width="458" alt="capitalize_android_fabric" src="https://user-images.githubusercontent.com/40902940/163182082-4061003c-230b-46f7-9e93-c34b66dbf3d2.png"> | <img width="476" alt="capitalize_ios_fabric" src="https://user-images.githubusercontent.com/40902940/163182124-b6dee450-46e3-41a3-b5bb-553d7c2662e6.png"> | (source: rn-tester, last commit: dac56ce) As fabric is now live since v0.68, we should fix this behavior for fabric aswell. I don't know why there is so much duplicated code between `ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm` and `Libraries/Text/RCTTextAttributes.m` because I don't know the architecture of the project very well. But if you see missing tests or some refacto to do I'm open to suggestions! ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Fixed] - Don't capitalize the first letter of a word that is starting by a number (Fabric renderer) Pull Request resolved: react#33629 Test Plan: I manually tested these changes on rn-tester (react-native `main` branch): | Fabric ? | Android | IOS | | ------------- | ------------- | ------------- | | YES | <img width="458" alt="capitalize_android_fabric" src="https://user-images.githubusercontent.com/40902940/163182082-4061003c-230b-46f7-9e93-c34b66dbf3d2.png"> | <img width="476" alt="capitalize_ios_fabric_after" src="https://user-images.githubusercontent.com/40902940/163184277-6c58c117-7144-4f6b-98ea-0c1db654f27b.png"> | | NO | <img width="458" alt="android_nf_after" src="https://user-images.githubusercontent.com/40902940/163190263-9d801f6a-09c2-4ec6-a841-3dca115a5ef7.png"> | <img width="476" alt="ios_nf_after" src="https://user-images.githubusercontent.com/40902940/163190333-7e9eac6a-3f28-4826-8ef9-bcf45bf870a9.png"> | Reviewed By: cortinico Differential Revision: D35611086 Pulled By: GijsWeterings fbshipit-source-id: 0c43807dcddb30e65921eb1525c0fe440162ec32

Summary
On my project, I realized that capitalize style doesn't work with dates on IOS. I found this issue and tried to solve it.
(code example: https://snack.expo.dev/@maelg/capitalize-demo)
As we can see, the behavior is different on IOS, Android and web:
unless it begins with a number. And put the rest in lowercase.And put the rest in lowercase.This PR aims to unify behavior on Android and Ios. I am not changing the behavior which differs from the web because I don't know if it is desirable to align with the web.
Changelog
[IOS] [Changed] - Don't capitalize the first letter of a word that is starting by a number
Test Plan
I manually tested my changes on a POC app (same code: https://snack.expo.dev/@maelg/capitalize-demo) on react-native v0.66.4 and react-native main branch.
You can see the result here:
I tried to use rn-tester but it was not taking my code. I think it is because fabric was enabled so it was using other code.I tried to disable fabric but I was not able to build the app on my IOS simulator anymore:
On rn-tester:
