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

feat(ios): support font scaling for custom fonts #11364

Merged
merged 3 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions apidoc/Titanium/UI/Font.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ properties:
description: |
Use one of the TEXT_STYLE constants from <Titanium.UI> to set the font to a predefined system font.
When this property is set to a valid value, all other font properties are ignored.

Notes:
Since SDK 9.0.0 property <Font.fontFamily> will not be ignored for iOS 11+.
Custom fonts can be used with this property for dynamic font management.
Copy link
Contributor

Choose a reason for hiding this comment

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

This reads like a bug fix release note so i don't think it should be part of the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to tell developer that this behavior is available to use for iOS 11+. So I think there should be something in doc to tell this otherwise how developer will know. That's why I put in Notes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, i agree that we have to make this changes public somewhere. And for that i think the release notes are a better place. So users now right away, ok that was fixed in 9.0.0.

A note in the docs saying that the property works as expected with the current SDK seems unnecessary. There should have been a note in the docs for previous SDK versions saying that the property does not work as expected, which we would have removed now.

Copy link
Contributor

Choose a reason for hiding this comment

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

After reading this in context again i'm fine with the message how it is. IMHO still not ideal though, but that's an issue of our docs not being versioned.

type: String
constants: Titanium.UI.TEXT_STYLE_*
platforms: [iphone, ipad]
Expand Down
15 changes: 10 additions & 5 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/WebFont.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ - (BOOL)isSizeNotSet

- (UIFont *)font
{
// TO DO: Refactor this function
if (font == nil) {
if (textStyle != nil && [textStyle isKindOfClass:[NSString class]]) {
if (textStyle != nil && [textStyle isKindOfClass:[NSString class]] && family != nil && [TiUtils isIOSVersionOrGreater:@"11.0"]) {
UIFont *tempFont = [UIFont fontWithName:family size:self.size];
if (tempFont) {
UIFontMetrics *fontMetrics = [UIFontMetrics metricsForTextStyle:textStyle];
font = [[fontMetrics scaledFontForFont:tempFont] retain];
}
} else if (textStyle != nil && [textStyle isKindOfClass:[NSString class]]) {
font = [[UIFont preferredFontForTextStyle:textStyle] retain];
} else {
if (family != nil) {
Expand Down Expand Up @@ -126,7 +133,7 @@ - (UIFont *)font
if (font == nil) {
//NO valid family specified. Just check for characteristics. Semi bold is ignored here.
if (self.isBoldWeight) {
UIFont *theFont = ([TiUtils isIOSVersionOrGreater:@"8.2"]) ? [UIFont systemFontOfSize:self.size weight:UIFontWeightBold] : [UIFont boldSystemFontOfSize:self.size];
UIFont *theFont = [UIFont systemFontOfSize:self.size weight:UIFontWeightBold];
if (self.isItalicStyle) {
NSString *fontFamily = [theFont familyName];
NSArray *fontNames = [UIFont fontNamesForFamilyName:fontFamily];
Expand All @@ -153,7 +160,7 @@ - (UIFont *)font
}
} else if (self.isItalicStyle) {
font = [[UIFont italicSystemFontOfSize:self.size] retain];
} else if ([TiUtils isIOSVersionOrGreater:@"8.2"]) {
} else {
if (self.isSemiboldWeight) {
font = [[UIFont systemFontOfSize:self.size weight:UIFontWeightSemibold] retain];
} else if (self.isThinWeight) {
Expand All @@ -165,8 +172,6 @@ - (UIFont *)font
} else {
font = [[UIFont systemFontOfSize:self.size] retain];
}
} else {
font = [[UIFont systemFontOfSize:self.size] retain];
}
}
}
Expand Down