Skip to content

Commit

Permalink
Remove all iOS 10 availability checks from material_components_ios no…
Browse files Browse the repository at this point in the history
…w that only iOS 10+ is supported.

PiperOrigin-RevId: 366437050
  • Loading branch information
afweiss authored and material-automation committed Apr 2, 2021
1 parent 9a49fd9 commit 924c49e
Show file tree
Hide file tree
Showing 24 changed files with 339 additions and 455 deletions.
113 changes: 53 additions & 60 deletions components/Banner/tests/snapshot/MDCBannerSnapshotTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#import "MaterialSnapshot.h"

#import "MaterialBanner+Theming.h"
#import "MaterialBanner.h"
#import "MaterialBanner+Theming.h"
#import "MaterialButtons.h"
#import "MaterialTypographyScheme.h"

Expand Down Expand Up @@ -63,12 +63,9 @@ - (instancetype)initWithContentSizeCategoryOverride:
}

- (UITraitCollection *)traitCollection {
if (@available(iOS 10.0, *)) {
UITraitCollection *traitCollection = [UITraitCollection
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
return traitCollection;
}
return [super traitCollection];
UITraitCollection *traitCollection = [UITraitCollection
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
return traitCollection;
}

@end
Expand Down Expand Up @@ -452,66 +449,62 @@ - (void)testLongTextWithTwoActionsAndIconRTLInArabic {
}

- (void)testDynamicTypeForContentSizeCategoryExtraExtraLarge {
if (@available(iOS 10.0, *)) {
// Given
self.bannerView = [[MDCBannerView alloc] init];
self.typographyScheme =
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
// Given
self.bannerView = [[MDCBannerView alloc] init];
self.typographyScheme =
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];

// When
self.bannerView.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 8);
self.bannerView.textView.text = kBannerShortText;
self.bannerView.textView.font = self.typographyScheme.body2;
MDCButton *button = self.bannerView.leadingButton;
[button setTitle:@"Action" forState:UIControlStateNormal];
[button setTitleFont:self.typographyScheme.button forState:UIControlStateNormal];
button.uppercaseTitle = YES;
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
self.bannerView.trailingButton.hidden = YES;
self.bannerView.mdc_adjustsFontForContentSizeCategory = YES;
// When
self.bannerView.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 8);
self.bannerView.textView.text = kBannerShortText;
self.bannerView.textView.font = self.typographyScheme.body2;
MDCButton *button = self.bannerView.leadingButton;
[button setTitle:@"Action" forState:UIControlStateNormal];
[button setTitleFont:self.typographyScheme.button forState:UIControlStateNormal];
button.uppercaseTitle = YES;
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
self.bannerView.trailingButton.hidden = YES;
self.bannerView.mdc_adjustsFontForContentSizeCategory = YES;

// Then
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
UIContentSizeCategoryExtraExtraLarge
andVerifyForView:self.bannerView];
}
// Then
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
UIContentSizeCategoryExtraExtraLarge
andVerifyForView:self.bannerView];
}

- (void)testDynamicTypeForAttributedTextStringWhenContentSizeCategoryIsExtraExtraLarge {
if (@available(iOS 10.0, *)) {
// Given
self.bannerView = [[MDCBannerView alloc] init];
self.typographyScheme =
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
MDCButton *button = self.bannerView.leadingButton;
self.bannerView.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 8);
[button setTitle:@"Action" forState:UIControlStateNormal];
[button setTitleFont:self.typographyScheme.button forState:UIControlStateNormal];
button.uppercaseTitle = YES;
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
self.bannerView.trailingButton.hidden = YES;
// Given
self.bannerView = [[MDCBannerView alloc] init];
self.typographyScheme =
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
MDCButton *button = self.bannerView.leadingButton;
self.bannerView.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 8);
[button setTitle:@"Action" forState:UIControlStateNormal];
[button setTitleFont:self.typographyScheme.button forState:UIControlStateNormal];
button.uppercaseTitle = YES;
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
self.bannerView.trailingButton.hidden = YES;

// When
NSMutableAttributedString *bannerString =
[[NSMutableAttributedString alloc] initWithString:kBannerShortText];
[bannerString addAttribute:NSFontAttributeName
value:self.typographyScheme.body1
range:NSMakeRange(10, 8)];
[bannerString addAttribute:NSForegroundColorAttributeName
value:UIColor.redColor
range:NSMakeRange(0, 9)];
[bannerString addAttribute:NSLinkAttributeName
value:@"http://www.google.com"
range:NSMakeRange([kBannerShortText length] - 2, 2)];
self.bannerView.textView.attributedText = bannerString;
self.bannerView.textView.font = self.typographyScheme.body2;
self.bannerView.mdc_adjustsFontForContentSizeCategory = YES;
// When
NSMutableAttributedString *bannerString =
[[NSMutableAttributedString alloc] initWithString:kBannerShortText];
[bannerString addAttribute:NSFontAttributeName
value:self.typographyScheme.body1
range:NSMakeRange(10, 8)];
[bannerString addAttribute:NSForegroundColorAttributeName
value:UIColor.redColor
range:NSMakeRange(0, 9)];
[bannerString addAttribute:NSLinkAttributeName
value:@"http://www.google.com"
range:NSMakeRange([kBannerShortText length] - 2, 2)];
self.bannerView.textView.attributedText = bannerString;
self.bannerView.textView.font = self.typographyScheme.body2;
self.bannerView.mdc_adjustsFontForContentSizeCategory = YES;

// Then
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
UIContentSizeCategoryExtraExtraLarge
andVerifyForView:self.bannerView];
}
// Then
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
UIContentSizeCategoryExtraExtraLarge
andVerifyForView:self.bannerView];
}

- (void)testPreferredFontForAXXLContentSizeCategory {
Expand Down
71 changes: 33 additions & 38 deletions components/Banner/tests/unit/BannerViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ - (instancetype)initWithContentSizeCategoryOverride:
}

- (UITraitCollection *)traitCollection {
if (@available(iOS 10.0, *)) {
UITraitCollection *traitCollection = [UITraitCollection
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
return traitCollection;
}
return [super traitCollection];
UITraitCollection *traitCollection = [UITraitCollection
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
return traitCollection;
}

@end
Expand All @@ -74,38 +71,36 @@ - (void)tearDown {
}

- (void)testBannerViewDynamicTypeBehavior {
if (@available(iOS 10.0, *)) {
// Given
self.banner.trailingButton.hidden = YES;
self.banner.mdc_adjustsFontForContentSizeCategory = YES;
UIFont *font = [UIFont systemFontOfSize:10.0 weight:UIFontWeightRegular];
MDCFontScaler *fontScaler = [[MDCFontScaler alloc] initForMaterialTextStyle:MDCTextStyleBody2];
UIFont *scalableFont = [fontScaler scaledFontWithFont:font];
scalableFont = [scalableFont mdc_scaledFontAtDefaultSize];
self.banner.textView.font = scalableFont;
self.banner.textView.text = @"Banner Text";
CGFloat originalTextFontSize = self.banner.textView.font.pointSize;
MDCButton *leadingButton = self.banner.leadingButton;
[leadingButton setTitleFont:scalableFont forState:UIControlStateNormal];
CGFloat originalButtonFontSize =
[self.banner.leadingButton titleFontForState:UIControlStateNormal].pointSize;

// When
MDCBannerViewTestsDynamicTypeContentSizeCategoryOverrideWindow *extraExtraLargeContainer =
[[MDCBannerViewTestsDynamicTypeContentSizeCategoryOverrideWindow alloc]
initWithContentSizeCategoryOverride:UIContentSizeCategoryExtraExtraLarge];
[extraExtraLargeContainer addSubview:self.banner];
[NSNotificationCenter.defaultCenter
postNotificationName:UIContentSizeCategoryDidChangeNotification
object:nil];

// Then
CGFloat actualTextFontSize = self.banner.textView.font.pointSize;
XCTAssertGreaterThan(actualTextFontSize, originalTextFontSize);
CGFloat actualButtonFontSize =
[self.banner.leadingButton titleFontForState:UIControlStateNormal].pointSize;
XCTAssertGreaterThan(actualButtonFontSize, originalButtonFontSize);
}
// Given
self.banner.trailingButton.hidden = YES;
self.banner.mdc_adjustsFontForContentSizeCategory = YES;
UIFont *font = [UIFont systemFontOfSize:10.0 weight:UIFontWeightRegular];
MDCFontScaler *fontScaler = [[MDCFontScaler alloc] initForMaterialTextStyle:MDCTextStyleBody2];
UIFont *scalableFont = [fontScaler scaledFontWithFont:font];
scalableFont = [scalableFont mdc_scaledFontAtDefaultSize];
self.banner.textView.font = scalableFont;
self.banner.textView.text = @"Banner Text";
CGFloat originalTextFontSize = self.banner.textView.font.pointSize;
MDCButton *leadingButton = self.banner.leadingButton;
[leadingButton setTitleFont:scalableFont forState:UIControlStateNormal];
CGFloat originalButtonFontSize =
[self.banner.leadingButton titleFontForState:UIControlStateNormal].pointSize;

// When
MDCBannerViewTestsDynamicTypeContentSizeCategoryOverrideWindow *extraExtraLargeContainer =
[[MDCBannerViewTestsDynamicTypeContentSizeCategoryOverrideWindow alloc]
initWithContentSizeCategoryOverride:UIContentSizeCategoryExtraExtraLarge];
[extraExtraLargeContainer addSubview:self.banner];
[NSNotificationCenter.defaultCenter
postNotificationName:UIContentSizeCategoryDidChangeNotification
object:nil];

// Then
CGFloat actualTextFontSize = self.banner.textView.font.pointSize;
XCTAssertGreaterThan(actualTextFontSize, originalTextFontSize);
CGFloat actualButtonFontSize =
[self.banner.leadingButton titleFontForState:UIControlStateNormal].pointSize;
XCTAssertGreaterThan(actualButtonFontSize, originalButtonFontSize);
}

- (void)testTraitCollectionDidChangeBlockCalledWithExpectedParameters {
Expand Down
50 changes: 22 additions & 28 deletions components/Banner/tests/unit/Theming/MDCBannerViewThemingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#import <XCTest/XCTest.h>

#import "MaterialAvailability.h"
#import "MaterialBanner+Theming.h"
#import "MaterialBanner.h"
#import "MaterialContainerScheme.h"
#import "MaterialMath.h"
#import "MaterialBanner+Theming.h"
#import "UIColor+MaterialDynamic.h"
#import "MaterialMath.h"
#import "MaterialContainerScheme.h"

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

- (UITraitCollection *)traitCollection {
if (@available(iOS 10.0, *)) {
UITraitCollection *traitCollection = [UITraitCollection
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
return traitCollection;
}
return [super traitCollection];
UITraitCollection *traitCollection = [UITraitCollection
traitCollectionWithPreferredContentSizeCategory:self.contentSizeCategoryOverride];
return traitCollection;
}

@end
Expand Down Expand Up @@ -190,27 +187,24 @@ - (void)testThemingWithCustomValues {
}

- (void)testFontsAreScaledWhenTypographySchemeRequestsPrescaling {
if (@available(iOS 10.0, *)) {
// Given
self.containerScheme.typographyScheme =
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
self.containerScheme.typographyScheme.useCurrentContentSizeCategoryWhenApplied = YES;
// Given
self.containerScheme.typographyScheme =
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
self.containerScheme.typographyScheme.useCurrentContentSizeCategoryWhenApplied = YES;

// When
MDCBannerViewThemingTestsDynamicTypeContentSizeCategoryOverrideWindow
*extraExtraLargeContainer =
[[MDCBannerViewThemingTestsDynamicTypeContentSizeCategoryOverrideWindow alloc]
initWithContentSizeCategoryOverride:UIContentSizeCategoryExtraExtraLarge];
[extraExtraLargeContainer addSubview:self.bannerView];
[NSNotificationCenter.defaultCenter
postNotificationName:UIContentSizeCategoryDidChangeNotification
object:nil];
[self.bannerView applyThemeWithScheme:self.containerScheme];
// When
MDCBannerViewThemingTestsDynamicTypeContentSizeCategoryOverrideWindow *extraExtraLargeContainer =
[[MDCBannerViewThemingTestsDynamicTypeContentSizeCategoryOverrideWindow alloc]
initWithContentSizeCategoryOverride:UIContentSizeCategoryExtraExtraLarge];
[extraExtraLargeContainer addSubview:self.bannerView];
[NSNotificationCenter.defaultCenter
postNotificationName:UIContentSizeCategoryDidChangeNotification
object:nil];
[self.bannerView applyThemeWithScheme:self.containerScheme];

// Then
XCTAssertGreaterThan(self.bannerView.textView.font.pointSize,
self.containerScheme.typographyScheme.body2.pointSize);
}
// Then
XCTAssertGreaterThan(self.bannerView.textView.font.pointSize,
self.containerScheme.typographyScheme.body2.pointSize);
}

- (void)testBannerViewBackgroundColorChangeWhenUIUserInterfaceStyleChangesOnIOS13 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#import "MaterialAvailability.h"
#import "MaterialButtons.h"
#import "MaterialColor.h"
#import "MaterialTypography.h"
#import "MaterialColor.h"

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

/**
Used to set the @c UIContentSizeCategory on an @c MDCButton.
@note On iOS 9 or below this method has no impact.
*/
- (void)setButtonTraitCollectionSizeToSize:(UIContentSizeCategory)sizeCategory {
UITraitCollection *traitCollection = [[UITraitCollection alloc] init];
if (@available(iOS 10.0, *)) {
traitCollection =
[UITraitCollection traitCollectionWithPreferredContentSizeCategory:sizeCategory];
}
UITraitCollection *traitCollection =
[UITraitCollection traitCollectionWithPreferredContentSizeCategory:sizeCategory];

self.button.traitCollectionOverride = traitCollection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,11 @@ - (void)generateSnapshotAndVerifyForView:(UIView *)view {
// before a horizontally flipped UIImage causes the image to render outside of the UIImageView's
// frame.
- (void)testHorizontallyFlippedImageWithContentInsets {
// Given
if (@available(iOS 10.0, *)) {
// When
self.button.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20);
UIImage *testImage =
[[UIImage mdc_testImageOfSize:CGSizeMake(24, 24)] imageWithHorizontallyFlippedOrientation];
[self.button setImage:testImage forState:UIControlStateNormal];
} else {
// Fallback on earlier versions
}
// When
self.button.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20);
UIImage *testImage =
[[UIImage mdc_testImageOfSize:CGSizeMake(24, 24)] imageWithHorizontallyFlippedOrientation];
[self.button setImage:testImage forState:UIControlStateNormal];

// Then
[self.button sizeToFit];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ - (void)testChipWithAllZeroPadding {
}

- (void)changeToRTL:(MDCChipViewLayoutCustomTraitCollectionFake *)chip {
if (@available(iOS 10.0, *)) {
chip.traitCollectionOverride = [UITraitCollection
traitCollectionWithLayoutDirection:UITraitEnvironmentLayoutDirectionRightToLeft];
}
chip.traitCollectionOverride = [UITraitCollection
traitCollectionWithLayoutDirection:UITraitEnvironmentLayoutDirectionRightToLeft];
}

#pragma mark - ContentPadding
Expand Down
Loading

0 comments on commit 924c49e

Please sign in to comment.