-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[Text] Get the system font instead of Helvetica programmatically and add a virtual fontName called "System" #1635
Conversation
I have to modify |
This looks good for now but we'll later want to go further and use the system UIFont object instead of reconstructing it by hand because there are special flags set on it (getting the system font != creating a UIFont object with the same font name and size). |
dbc940c
to
8c2c142
Compare
@ide How can it go futher? Do you have any idea? |
re: going further -- in |
8c2c142
to
fcbb97b
Compare
I reduce my aim. I don't know how can I get I agree your idea. But it looks to me like It's beyond my limit now. |
When I used |
yeah, I think it's fine if this commit focuses just on getting iOS 9 on SF instead of Helvetica Neue. |
@dalinaum This is nice and solves one part of the problem which is using In addition to this, in P.S. All the places where Helvetica is mentioned in code. |
I think we need to solve this universally, not just in TextView, as per discussion in #1611 |
b0ae49a
to
98fa688
Compare
Because 98fa688 generates different snapshot images, it breaks all snapshot tests. How can I pass thoses tests? (I added @ide @nicklockwood @paramaggarwal on my fork. If you want to modify my fork, you can modify my fork.) |
98fa688
to
28c5939
Compare
Summary: Get the system font instead of Helvetica programmatically.
28c5939
to
dff466e
Compare
I modified snapshot images. |
This is only a partial solution, as generating the system font from the family name won't include the other attributes @ide mentioned. For the tests, we'll need to have different snapshots per OS version (which was already the case, as Apple always tend to make minor changes to font and UI rendering between OS versions). For now we can probably just mandate that the tests should be run on 8.x. For apps, the expectation is that anything using system font will look different on new iOS releases, so I think that's OK. If people really want to keep using Helvetica (and make their app look dated on iOS9), they can specify the font explicitly. |
Add a virtual fontName called "System" that defaults to whatever the current system font is. (@nicklockwood facebook#1611) It may break UI of existing apps.
dff466e
to
96e4f04
Compare
It generates the |
@dalinaum starting to take shape. :) |
53bcc3d
to
7b9f440
Compare
https://travis-ci.org/facebook/react-native/jobs/67305503
|
Travis works well now. @nicklockwood I pushed another commit that uses fontDescriptor. Unfortunately, it looks like dynamic weight change is not supported in iOS. |
fontWeight = [self RCTFontWeight:weight] ?: fontWeight; | ||
|
||
if (weight) { | ||
font = [UIFont systemFontOfSize:fontSize weight:fontWeight]; |
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 method was only added in iOS 8.2, it will crash on iOS 8.1 and earlier (we need to support 7+)
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.
Oh. I see. I have to modify that line.
7b9f440
to
901fe6c
Compare
Pushed a modified commit again :) |
The lack of dynamic weight change support was why I used the (rather hacky) solution of enumerating fonts to find the closest match with the requires attributes. But we can't really ship an update that breaks fontWeight support for the system font. There must be a better solution. |
How about introducing Some codes use PS: The last commit(3ca2f73) is not relevant to this comment. I have had a mistake. I fixed it. That's it. |
* All font + weight/fontName -> It uses familyName to generate font. * System font -> It uses fontDescriptor to generate font. * Other font -> uses fontDescriptor to getnere font. It looks like iOS doesn't support changing weight dynamically. System font with weight is supported iOS 8.2 and later.
901fe6c
to
3ca2f73
Compare
You'll probably notice I made a few changes to this before landing it, but I managed to keep support for bold/italic on system fonts and retain backwards compatibility with 8.2 |
@nicklockwood I learnt something from your reviews and changes. I should learn more about React Native. Thanks so much. |
Get the system font instead of Helvetica programmatically and add a virtual fontName called "System" that defaults to whatever the current system font is.
#1611