Skip to content

Commit

Permalink
[Typography] Remove checks for systemFontOfSize:weight:. (#8581)
Browse files Browse the repository at this point in the history
Removing conditional checks and guards for the API since we now support iOS 9
as the minimum iOS version and no longer support Xcode 9.

Part of #8580
  • Loading branch information
Robert Moore authored and featherless committed Oct 15, 2019
1 parent 10b2962 commit 2550aa0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 84 deletions.
38 changes: 4 additions & 34 deletions components/Typography/src/MDCTypography.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,7 @@ - (nullable UIFont *)lightFontOfSize:(CGFloat)fontSize {
return font;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
font = [UIFont systemFontOfSize:fontSize weight:UIFontWeightLight];
} else {
font = [UIFont fontWithName:@"HelveticaNeue-Light" size:fontSize];
}
#pragma clang diagnostic pop
font = [UIFont systemFontOfSize:fontSize weight:UIFontWeightLight];
if (font) {
[self.fontCache setObject:font forKey:cacheKey];
}
Expand All @@ -240,15 +233,7 @@ - (UIFont *)regularFontOfSize:(CGFloat)fontSize {
return font;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
font = [UIFont systemFontOfSize:fontSize weight:UIFontWeightRegular];
} else {
font = [UIFont systemFontOfSize:fontSize];
}
#pragma clang diagnostic pop

font = [UIFont systemFontOfSize:fontSize weight:UIFontWeightRegular];
[self.fontCache setObject:font forKey:cacheKey];

return (UIFont *)font;
Expand All @@ -261,15 +246,7 @@ - (nullable UIFont *)mediumFontOfSize:(CGFloat)fontSize {
return font;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
font = [UIFont systemFontOfSize:fontSize weight:UIFontWeightMedium];
} else {
font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:fontSize];
}
#pragma clang diagnostic pop

font = [UIFont systemFontOfSize:fontSize weight:UIFontWeightMedium];
if (font) {
[self.fontCache setObject:font forKey:cacheKey];
}
Expand All @@ -283,14 +260,7 @@ - (UIFont *)boldFontOfSize:(CGFloat)fontSize {
return font;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
font = [UIFont systemFontOfSize:fontSize weight:UIFontWeightSemibold];
} else {
font = [UIFont boldSystemFontOfSize:fontSize];
}
#pragma clang diagnostic pop
font = [UIFont systemFontOfSize:fontSize weight:UIFontWeightSemibold];

[self.fontCache setObject:font forKey:cacheKey];

Expand Down
13 changes: 2 additions & 11 deletions components/Typography/src/UIFontDescriptor+MaterialTypography.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,8 @@ + (nonnull UIFontDescriptor *)mdc_fontDescriptorForMaterialTextStyle:(MDCFontTex
dispatch_once(&onceToken, ^{
UIFont *smallSystemFont;
UIFont *largeSystemFont;
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
smallSystemFont = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
largeSystemFont = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
#pragma clang diagnostic pop
} else {
// TODO: Remove this fallback once we are 8.2+
smallSystemFont = [UIFont systemFontOfSize:12];
largeSystemFont = [UIFont systemFontOfSize:20];
}
smallSystemFont = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
largeSystemFont = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
smallSystemFontFamilyName = [smallSystemFont.familyName copy];
largeSystemFontFamilyName = [largeSystemFont.familyName copy];
});
Expand Down
29 changes: 8 additions & 21 deletions components/Typography/tests/unit/SystemFontLoaderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,14 @@ - (void)testWeights {
MDCSystemFontLoader *fontLoader = [[MDCSystemFontLoader alloc] init];

// Then
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
XCTAssertEqual([fontLoader lightFontOfSize:size], [UIFont systemFontOfSize:size
weight:UIFontWeightLight]);
XCTAssertEqual([fontLoader regularFontOfSize:size],
[UIFont systemFontOfSize:size weight:UIFontWeightRegular]);
XCTAssertEqual([fontLoader mediumFontOfSize:size],
[UIFont systemFontOfSize:size weight:UIFontWeightMedium]);
XCTAssertEqual([fontLoader boldFontOfSize:size],
[UIFont systemFontOfSize:size weight:UIFontWeightSemibold]);
#pragma clang diagnostic pop
} else {
// Fallback on earlier versions
XCTAssertEqual([fontLoader lightFontOfSize:size], [UIFont fontWithName:@"HelveticaNeue-Light"
size:size]);
XCTAssertEqual([fontLoader regularFontOfSize:size], [UIFont systemFontOfSize:size]);
XCTAssertEqual([fontLoader mediumFontOfSize:size], [UIFont fontWithName:@"HelveticaNeue-Medium"
size:size]);
XCTAssertEqual([fontLoader boldFontOfSize:size], [UIFont boldSystemFontOfSize:size]);
}
XCTAssertEqual([fontLoader lightFontOfSize:size], [UIFont systemFontOfSize:size
weight:UIFontWeightLight]);
XCTAssertEqual([fontLoader regularFontOfSize:size],
[UIFont systemFontOfSize:size weight:UIFontWeightRegular]);
XCTAssertEqual([fontLoader mediumFontOfSize:size], [UIFont systemFontOfSize:size
weight:UIFontWeightMedium]);
XCTAssertEqual([fontLoader boldFontOfSize:size], [UIFont systemFontOfSize:size
weight:UIFontWeightSemibold]);
UIFontDescriptor *fontDescriptorWithBoldItalic = [[UIFont systemFontOfSize:size].fontDescriptor
fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold | UIFontDescriptorTraitItalic];
XCTAssertEqual([fontLoader boldItalicFontOfSize:size],
Expand Down
20 changes: 2 additions & 18 deletions components/Typography/tests/unit/TypographyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,7 @@ - (void)testFontFamilyMatchesSystemFontFamily {
// When
MDCFontTextStyle style = styleObject.integerValue;
UIFont *mdcFont = [UIFont mdc_preferredFontForMaterialTextStyle:style];
UIFont *systemFont;
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
systemFont = [UIFont systemFontOfSize:mdcFont.pointSize weight:UIFontWeightRegular];
} else {
systemFont = [UIFont systemFontOfSize:mdcFont.pointSize];
}
#pragma clang diagnostic pop
UIFont *systemFont = [UIFont systemFontOfSize:mdcFont.pointSize weight:UIFontWeightRegular];

// Then
XCTAssertEqualObjects(systemFont.familyName, mdcFont.familyName);
Expand All @@ -367,15 +359,7 @@ - (void)testFontFamilyMatchesSystemFontFamily {

- (void)testExtendedDescription {
// Given
UIFont *systemFont;
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
systemFont = [UIFont systemFontOfSize:22.0 weight:UIFontWeightRegular];
} else {
systemFont = [UIFont systemFontOfSize:22.0];
}
#pragma clang diagnostic pop
UIFont *systemFont = [UIFont systemFontOfSize:22.0 weight:UIFontWeightRegular];
XCTAssertNotNil(systemFont);

// When
Expand Down

0 comments on commit 2550aa0

Please sign in to comment.