Skip to content

Commit 924c49e

Browse files
afweissmaterial-automation
authored andcommitted
Remove all iOS 10 availability checks from material_components_ios now that only iOS 10+ is supported.
PiperOrigin-RevId: 366437050
1 parent 9a49fd9 commit 924c49e

File tree

24 files changed

+339
-455
lines changed

24 files changed

+339
-455
lines changed

components/Banner/tests/snapshot/MDCBannerSnapshotTests.m

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
#import "MaterialSnapshot.h"
1616

17-
#import "MaterialBanner+Theming.h"
1817
#import "MaterialBanner.h"
18+
#import "MaterialBanner+Theming.h"
1919
#import "MaterialButtons.h"
2020
#import "MaterialTypographyScheme.h"
2121

@@ -63,12 +63,9 @@ - (instancetype)initWithContentSizeCategoryOverride:
6363
}
6464

6565
- (UITraitCollection *)traitCollection {
66-
if (@available(iOS 10.0, *)) {
67-
UITraitCollection *traitCollection = [UITraitCollection
68-
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
69-
return traitCollection;
70-
}
71-
return [super traitCollection];
66+
UITraitCollection *traitCollection = [UITraitCollection
67+
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
68+
return traitCollection;
7269
}
7370

7471
@end
@@ -452,66 +449,62 @@ - (void)testLongTextWithTwoActionsAndIconRTLInArabic {
452449
}
453450

454451
- (void)testDynamicTypeForContentSizeCategoryExtraExtraLarge {
455-
if (@available(iOS 10.0, *)) {
456-
// Given
457-
self.bannerView = [[MDCBannerView alloc] init];
458-
self.typographyScheme =
459-
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
452+
// Given
453+
self.bannerView = [[MDCBannerView alloc] init];
454+
self.typographyScheme =
455+
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
460456

461-
// When
462-
self.bannerView.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 8);
463-
self.bannerView.textView.text = kBannerShortText;
464-
self.bannerView.textView.font = self.typographyScheme.body2;
465-
MDCButton *button = self.bannerView.leadingButton;
466-
[button setTitle:@"Action" forState:UIControlStateNormal];
467-
[button setTitleFont:self.typographyScheme.button forState:UIControlStateNormal];
468-
button.uppercaseTitle = YES;
469-
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
470-
self.bannerView.trailingButton.hidden = YES;
471-
self.bannerView.mdc_adjustsFontForContentSizeCategory = YES;
457+
// When
458+
self.bannerView.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 8);
459+
self.bannerView.textView.text = kBannerShortText;
460+
self.bannerView.textView.font = self.typographyScheme.body2;
461+
MDCButton *button = self.bannerView.leadingButton;
462+
[button setTitle:@"Action" forState:UIControlStateNormal];
463+
[button setTitleFont:self.typographyScheme.button forState:UIControlStateNormal];
464+
button.uppercaseTitle = YES;
465+
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
466+
self.bannerView.trailingButton.hidden = YES;
467+
self.bannerView.mdc_adjustsFontForContentSizeCategory = YES;
472468

473-
// Then
474-
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
475-
UIContentSizeCategoryExtraExtraLarge
476-
andVerifyForView:self.bannerView];
477-
}
469+
// Then
470+
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
471+
UIContentSizeCategoryExtraExtraLarge
472+
andVerifyForView:self.bannerView];
478473
}
479474

480475
- (void)testDynamicTypeForAttributedTextStringWhenContentSizeCategoryIsExtraExtraLarge {
481-
if (@available(iOS 10.0, *)) {
482-
// Given
483-
self.bannerView = [[MDCBannerView alloc] init];
484-
self.typographyScheme =
485-
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
486-
MDCButton *button = self.bannerView.leadingButton;
487-
self.bannerView.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 8);
488-
[button setTitle:@"Action" forState:UIControlStateNormal];
489-
[button setTitleFont:self.typographyScheme.button forState:UIControlStateNormal];
490-
button.uppercaseTitle = YES;
491-
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
492-
self.bannerView.trailingButton.hidden = YES;
476+
// Given
477+
self.bannerView = [[MDCBannerView alloc] init];
478+
self.typographyScheme =
479+
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
480+
MDCButton *button = self.bannerView.leadingButton;
481+
self.bannerView.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 8);
482+
[button setTitle:@"Action" forState:UIControlStateNormal];
483+
[button setTitleFont:self.typographyScheme.button forState:UIControlStateNormal];
484+
button.uppercaseTitle = YES;
485+
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
486+
self.bannerView.trailingButton.hidden = YES;
493487

494-
// When
495-
NSMutableAttributedString *bannerString =
496-
[[NSMutableAttributedString alloc] initWithString:kBannerShortText];
497-
[bannerString addAttribute:NSFontAttributeName
498-
value:self.typographyScheme.body1
499-
range:NSMakeRange(10, 8)];
500-
[bannerString addAttribute:NSForegroundColorAttributeName
501-
value:UIColor.redColor
502-
range:NSMakeRange(0, 9)];
503-
[bannerString addAttribute:NSLinkAttributeName
504-
value:@"http://www.google.com"
505-
range:NSMakeRange([kBannerShortText length] - 2, 2)];
506-
self.bannerView.textView.attributedText = bannerString;
507-
self.bannerView.textView.font = self.typographyScheme.body2;
508-
self.bannerView.mdc_adjustsFontForContentSizeCategory = YES;
488+
// When
489+
NSMutableAttributedString *bannerString =
490+
[[NSMutableAttributedString alloc] initWithString:kBannerShortText];
491+
[bannerString addAttribute:NSFontAttributeName
492+
value:self.typographyScheme.body1
493+
range:NSMakeRange(10, 8)];
494+
[bannerString addAttribute:NSForegroundColorAttributeName
495+
value:UIColor.redColor
496+
range:NSMakeRange(0, 9)];
497+
[bannerString addAttribute:NSLinkAttributeName
498+
value:@"http://www.google.com"
499+
range:NSMakeRange([kBannerShortText length] - 2, 2)];
500+
self.bannerView.textView.attributedText = bannerString;
501+
self.bannerView.textView.font = self.typographyScheme.body2;
502+
self.bannerView.mdc_adjustsFontForContentSizeCategory = YES;
509503

510-
// Then
511-
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
512-
UIContentSizeCategoryExtraExtraLarge
513-
andVerifyForView:self.bannerView];
514-
}
504+
// Then
505+
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
506+
UIContentSizeCategoryExtraExtraLarge
507+
andVerifyForView:self.bannerView];
515508
}
516509

517510
- (void)testPreferredFontForAXXLContentSizeCategory {

components/Banner/tests/unit/BannerViewTests.m

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ - (instancetype)initWithContentSizeCategoryOverride:
4545
}
4646

4747
- (UITraitCollection *)traitCollection {
48-
if (@available(iOS 10.0, *)) {
49-
UITraitCollection *traitCollection = [UITraitCollection
50-
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
51-
return traitCollection;
52-
}
53-
return [super traitCollection];
48+
UITraitCollection *traitCollection = [UITraitCollection
49+
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
50+
return traitCollection;
5451
}
5552

5653
@end
@@ -74,38 +71,36 @@ - (void)tearDown {
7471
}
7572

7673
- (void)testBannerViewDynamicTypeBehavior {
77-
if (@available(iOS 10.0, *)) {
78-
// Given
79-
self.banner.trailingButton.hidden = YES;
80-
self.banner.mdc_adjustsFontForContentSizeCategory = YES;
81-
UIFont *font = [UIFont systemFontOfSize:10.0 weight:UIFontWeightRegular];
82-
MDCFontScaler *fontScaler = [[MDCFontScaler alloc] initForMaterialTextStyle:MDCTextStyleBody2];
83-
UIFont *scalableFont = [fontScaler scaledFontWithFont:font];
84-
scalableFont = [scalableFont mdc_scaledFontAtDefaultSize];
85-
self.banner.textView.font = scalableFont;
86-
self.banner.textView.text = @"Banner Text";
87-
CGFloat originalTextFontSize = self.banner.textView.font.pointSize;
88-
MDCButton *leadingButton = self.banner.leadingButton;
89-
[leadingButton setTitleFont:scalableFont forState:UIControlStateNormal];
90-
CGFloat originalButtonFontSize =
91-
[self.banner.leadingButton titleFontForState:UIControlStateNormal].pointSize;
92-
93-
// When
94-
MDCBannerViewTestsDynamicTypeContentSizeCategoryOverrideWindow *extraExtraLargeContainer =
95-
[[MDCBannerViewTestsDynamicTypeContentSizeCategoryOverrideWindow alloc]
96-
initWithContentSizeCategoryOverride:UIContentSizeCategoryExtraExtraLarge];
97-
[extraExtraLargeContainer addSubview:self.banner];
98-
[NSNotificationCenter.defaultCenter
99-
postNotificationName:UIContentSizeCategoryDidChangeNotification
100-
object:nil];
101-
102-
// Then
103-
CGFloat actualTextFontSize = self.banner.textView.font.pointSize;
104-
XCTAssertGreaterThan(actualTextFontSize, originalTextFontSize);
105-
CGFloat actualButtonFontSize =
106-
[self.banner.leadingButton titleFontForState:UIControlStateNormal].pointSize;
107-
XCTAssertGreaterThan(actualButtonFontSize, originalButtonFontSize);
108-
}
74+
// Given
75+
self.banner.trailingButton.hidden = YES;
76+
self.banner.mdc_adjustsFontForContentSizeCategory = YES;
77+
UIFont *font = [UIFont systemFontOfSize:10.0 weight:UIFontWeightRegular];
78+
MDCFontScaler *fontScaler = [[MDCFontScaler alloc] initForMaterialTextStyle:MDCTextStyleBody2];
79+
UIFont *scalableFont = [fontScaler scaledFontWithFont:font];
80+
scalableFont = [scalableFont mdc_scaledFontAtDefaultSize];
81+
self.banner.textView.font = scalableFont;
82+
self.banner.textView.text = @"Banner Text";
83+
CGFloat originalTextFontSize = self.banner.textView.font.pointSize;
84+
MDCButton *leadingButton = self.banner.leadingButton;
85+
[leadingButton setTitleFont:scalableFont forState:UIControlStateNormal];
86+
CGFloat originalButtonFontSize =
87+
[self.banner.leadingButton titleFontForState:UIControlStateNormal].pointSize;
88+
89+
// When
90+
MDCBannerViewTestsDynamicTypeContentSizeCategoryOverrideWindow *extraExtraLargeContainer =
91+
[[MDCBannerViewTestsDynamicTypeContentSizeCategoryOverrideWindow alloc]
92+
initWithContentSizeCategoryOverride:UIContentSizeCategoryExtraExtraLarge];
93+
[extraExtraLargeContainer addSubview:self.banner];
94+
[NSNotificationCenter.defaultCenter
95+
postNotificationName:UIContentSizeCategoryDidChangeNotification
96+
object:nil];
97+
98+
// Then
99+
CGFloat actualTextFontSize = self.banner.textView.font.pointSize;
100+
XCTAssertGreaterThan(actualTextFontSize, originalTextFontSize);
101+
CGFloat actualButtonFontSize =
102+
[self.banner.leadingButton titleFontForState:UIControlStateNormal].pointSize;
103+
XCTAssertGreaterThan(actualButtonFontSize, originalButtonFontSize);
109104
}
110105

111106
- (void)testTraitCollectionDidChangeBlockCalledWithExpectedParameters {

components/Banner/tests/unit/Theming/MDCBannerViewThemingTests.m

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
#import <XCTest/XCTest.h>
1616

1717
#import "MaterialAvailability.h"
18-
#import "MaterialBanner+Theming.h"
1918
#import "MaterialBanner.h"
20-
#import "MaterialContainerScheme.h"
21-
#import "MaterialMath.h"
19+
#import "MaterialBanner+Theming.h"
2220
#import "UIColor+MaterialDynamic.h"
21+
#import "MaterialMath.h"
22+
#import "MaterialContainerScheme.h"
2323

2424
// The opacity value applied to text view.
2525
static CGFloat const kTextViewOpacity = (CGFloat)0.87;
@@ -56,12 +56,9 @@ - (instancetype)initWithContentSizeCategoryOverride:
5656
}
5757

5858
- (UITraitCollection *)traitCollection {
59-
if (@available(iOS 10.0, *)) {
60-
UITraitCollection *traitCollection = [UITraitCollection
61-
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
62-
return traitCollection;
63-
}
64-
return [super traitCollection];
59+
UITraitCollection *traitCollection = [UITraitCollection
60+
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
61+
return traitCollection;
6562
}
6663

6764
@end
@@ -190,27 +187,24 @@ - (void)testThemingWithCustomValues {
190187
}
191188

192189
- (void)testFontsAreScaledWhenTypographySchemeRequestsPrescaling {
193-
if (@available(iOS 10.0, *)) {
194-
// Given
195-
self.containerScheme.typographyScheme =
196-
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
197-
self.containerScheme.typographyScheme.useCurrentContentSizeCategoryWhenApplied = YES;
190+
// Given
191+
self.containerScheme.typographyScheme =
192+
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
193+
self.containerScheme.typographyScheme.useCurrentContentSizeCategoryWhenApplied = YES;
198194

199-
// When
200-
MDCBannerViewThemingTestsDynamicTypeContentSizeCategoryOverrideWindow
201-
*extraExtraLargeContainer =
202-
[[MDCBannerViewThemingTestsDynamicTypeContentSizeCategoryOverrideWindow alloc]
203-
initWithContentSizeCategoryOverride:UIContentSizeCategoryExtraExtraLarge];
204-
[extraExtraLargeContainer addSubview:self.bannerView];
205-
[NSNotificationCenter.defaultCenter
206-
postNotificationName:UIContentSizeCategoryDidChangeNotification
207-
object:nil];
208-
[self.bannerView applyThemeWithScheme:self.containerScheme];
195+
// When
196+
MDCBannerViewThemingTestsDynamicTypeContentSizeCategoryOverrideWindow *extraExtraLargeContainer =
197+
[[MDCBannerViewThemingTestsDynamicTypeContentSizeCategoryOverrideWindow alloc]
198+
initWithContentSizeCategoryOverride:UIContentSizeCategoryExtraExtraLarge];
199+
[extraExtraLargeContainer addSubview:self.bannerView];
200+
[NSNotificationCenter.defaultCenter
201+
postNotificationName:UIContentSizeCategoryDidChangeNotification
202+
object:nil];
203+
[self.bannerView applyThemeWithScheme:self.containerScheme];
209204

210-
// Then
211-
XCTAssertGreaterThan(self.bannerView.textView.font.pointSize,
212-
self.containerScheme.typographyScheme.body2.pointSize);
213-
}
205+
// Then
206+
XCTAssertGreaterThan(self.bannerView.textView.font.pointSize,
207+
self.containerScheme.typographyScheme.body2.pointSize);
214208
}
215209

216210
- (void)testBannerViewBackgroundColorChangeWhenUIUserInterfaceStyleChangesOnIOS13 {

components/Buttons/tests/snapshot/ButtonCustomTraitCollectionSnapshotTests.m

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
#import "MaterialAvailability.h"
2121
#import "MaterialButtons.h"
22-
#import "MaterialColor.h"
2322
#import "MaterialTypography.h"
23+
#import "MaterialColor.h"
2424

2525
/** A @c MDCButton test fake to override the @c traitCollection to test for dynamic type. */
2626
@interface ButtonDynamicTypeSnapshotTestFakeButton : MDCButton
@@ -77,15 +77,10 @@ - (void)generateSnapshotAndVerifyForView:(UIView *)view {
7777

7878
/**
7979
Used to set the @c UIContentSizeCategory on an @c MDCButton.
80-
81-
@note On iOS 9 or below this method has no impact.
8280
*/
8381
- (void)setButtonTraitCollectionSizeToSize:(UIContentSizeCategory)sizeCategory {
84-
UITraitCollection *traitCollection = [[UITraitCollection alloc] init];
85-
if (@available(iOS 10.0, *)) {
86-
traitCollection =
87-
[UITraitCollection traitCollectionWithPreferredContentSizeCategory:sizeCategory];
88-
}
82+
UITraitCollection *traitCollection =
83+
[UITraitCollection traitCollectionWithPreferredContentSizeCategory:sizeCategory];
8984

9085
self.button.traitCollectionOverride = traitCollection;
9186
}

components/Buttons/tests/snapshot/ButtonsFlippedImageRenderingSnapshotTests.m

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,11 @@ - (void)generateSnapshotAndVerifyForView:(UIView *)view {
4646
// before a horizontally flipped UIImage causes the image to render outside of the UIImageView's
4747
// frame.
4848
- (void)testHorizontallyFlippedImageWithContentInsets {
49-
// Given
50-
if (@available(iOS 10.0, *)) {
51-
// When
52-
self.button.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20);
53-
UIImage *testImage =
54-
[[UIImage mdc_testImageOfSize:CGSizeMake(24, 24)] imageWithHorizontallyFlippedOrientation];
55-
[self.button setImage:testImage forState:UIControlStateNormal];
56-
} else {
57-
// Fallback on earlier versions
58-
}
49+
// When
50+
self.button.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20);
51+
UIImage *testImage =
52+
[[UIImage mdc_testImageOfSize:CGSizeMake(24, 24)] imageWithHorizontallyFlippedOrientation];
53+
[self.button setImage:testImage forState:UIControlStateNormal];
5954

6055
// Then
6156
[self.button sizeToFit];

components/Chips/tests/snapshot/MDCChipViewLayoutSnapshotTests.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ - (void)testChipWithAllZeroPadding {
9090
}
9191

9292
- (void)changeToRTL:(MDCChipViewLayoutCustomTraitCollectionFake *)chip {
93-
if (@available(iOS 10.0, *)) {
94-
chip.traitCollectionOverride = [UITraitCollection
95-
traitCollectionWithLayoutDirection:UITraitEnvironmentLayoutDirectionRightToLeft];
96-
}
93+
chip.traitCollectionOverride = [UITraitCollection
94+
traitCollectionWithLayoutDirection:UITraitEnvironmentLayoutDirectionRightToLeft];
9795
}
9896

9997
#pragma mark - ContentPadding

0 commit comments

Comments
 (0)