Skip to content

Commit

Permalink
Revert "[FeatureHighlight] FeatureHighlightViewController should expo…
Browse files Browse the repository at this point in the history
…se FeatureHighlightView as a property. (#3145)"

This reverts commit 24be789.
  • Loading branch information
randallli committed Mar 30, 2018
1 parent d9becb0 commit 19de254
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 78 deletions.
Expand Up @@ -30,8 +30,7 @@ - (void)collectionView:(UICollectionView *)collectionView
completion:nil];
highlightController.titleText = @"So pretty!";
highlightController.bodyText = @"What a nice color you've chosen.";
MDCFeatureHighlightView *featureHighlightView = highlightController.featureHighlightView;
featureHighlightView.outerHighlightColor = cell.accessoryView.backgroundColor;
highlightController.outerHighlightColor = cell.accessoryView.backgroundColor;
[MDCFeatureHighlightAccessibilityMutator mutate:highlightController];
[self presentViewController:highlightController animated:YES completion:nil];
}
Expand Down
Expand Up @@ -25,7 +25,7 @@ - (void)didTapButton:(id)sender {
[[MDCFeatureHighlightViewController alloc] initWithHighlightedView:_button completion:nil];
[MDCFeatureHighlightAccessibilityMutator mutate:vc];

vc.featureHighlightView.mdc_adjustsFontForContentSizeCategory = YES;
vc.mdc_adjustsFontForContentSizeCategory = YES;

vc.titleText = @"Hey this is a multi-line title for the Feature Highlight";
vc.bodyText = @"This is the description of the feature highlight view controller.";
Expand Down
Expand Up @@ -29,7 +29,7 @@ + (void)mutate:(MDCFeatureHighlightViewController *)featureHighlightViewControll

+ (void)mutateTitleColor:(MDCFeatureHighlightViewController *)featureHighlightViewController{
MDCFeatureHighlightView *featureHighlightView =
featureHighlightViewController.featureHighlightView;
(MDCFeatureHighlightView *)featureHighlightViewController.view;
if (![featureHighlightView isKindOfClass:[MDCFeatureHighlightView class]]) {
NSAssert(NO, @"FeatureHighlightViewController should have FeatureHighlightView");
return;
Expand All @@ -39,9 +39,9 @@ + (void)mutateTitleColor:(MDCFeatureHighlightViewController *)featureHighlightVi
options |= MDFTextAccessibilityOptionsLargeFont;
}

UIColor *textColor = featureHighlightView.titleColor;
UIColor *textColor = featureHighlightViewController.titleColor;
UIColor *backgroundColor =
[featureHighlightView.outerHighlightColor colorWithAlphaComponent:1.0f];
[featureHighlightViewController.outerHighlightColor colorWithAlphaComponent:1.0f];
UIColor *titleColor =
[MDCFeatureHighlightAccessibilityMutator accessibleColorForTextColor:textColor
withBackgroundColor:backgroundColor
Expand All @@ -57,12 +57,12 @@ + (void)mutateTitleColor:(MDCFeatureHighlightViewController *)featureHighlightVi
onBackgroundColor:backgroundColor
options:options];
titleAlpha = MAX([MDCTypography titleFontOpacity], titleAlpha);
featureHighlightView.titleColor = [titleColor colorWithAlphaComponent:titleAlpha];
featureHighlightViewController.titleColor = [titleColor colorWithAlphaComponent:titleAlpha];
}

+ (void)mutateBodyColor:(MDCFeatureHighlightViewController *)featureHighlightViewController {
MDCFeatureHighlightView *featureHighlightView =
featureHighlightViewController.featureHighlightView;
(MDCFeatureHighlightView *)featureHighlightViewController.view;
if (![featureHighlightView isKindOfClass:[MDCFeatureHighlightView class]]) {
NSAssert(NO, @"FeatureHighlightViewController should have FeatureHighlightView");
return;
Expand All @@ -72,10 +72,10 @@ + (void)mutateBodyColor:(MDCFeatureHighlightViewController *)featureHighlightVie
options |= MDFTextAccessibilityOptionsLargeFont;
}

UIColor *textColor = featureHighlightView.bodyColor;
UIColor *textColor = featureHighlightViewController.bodyColor;
UIColor *backgroundColor =
[featureHighlightView.outerHighlightColor colorWithAlphaComponent:1.0f];
featureHighlightView.bodyColor =
[featureHighlightViewController.outerHighlightColor colorWithAlphaComponent:1.0f];
featureHighlightViewController.bodyColor =
[MDCFeatureHighlightAccessibilityMutator accessibleColorForTextColor:textColor
withBackgroundColor:backgroundColor
options:options];
Expand Down
Expand Up @@ -16,8 +16,6 @@

#import <UIKit/UIKit.h>

@class MDCFeatureHighlightView;

/** The default alpha for the outer highlight circle. */
extern const CGFloat kMDCFeatureHighlightOuterHighlightAlpha;

Expand Down Expand Up @@ -94,9 +92,47 @@ typedef void (^MDCFeatureHighlightCompletion)(BOOL accepted);
@property(nonatomic, copy, nullable) NSString *bodyText;

/**
The MDCFeatureHighlightView instance that is being presented by this view controller.
Sets the color to be used for the outer highlight. Defaults to blue with an alpha of
kMDCFeatureHighlightOuterHighlightAlpha.
Alpha should be set to kMDCFeatureHighlightOuterHighlightAlpha.
*/
@property(nonatomic, strong, null_resettable) UIColor *outerHighlightColor;

/**
Sets the color to be used for the inner highlight. Defaults to white.
Should be opaque.
*/
@property(nonatomic, strong, null_resettable) UIColor *innerHighlightColor;

/**
Sets the color to be used for the title text. If nil upon presentation, a color of sufficient
contrast to the |outerHighlightColor| will be automatically chosen.
Defaults to nil.
*/
@property(nonatomic, strong, nullable) UIColor *titleColor;

/**
Sets the color to be used for the body text. If nil upon presentation, a color of sufficient
contrast to the |outerHighlightColor| will be automatically chosen upon presentation.
Defaults to nil.
*/
@property(nonatomic, strong, nullable) UIColor *bodyColor;

/**
Indicates whether the feature highlight contents should automatically update their font when the
device’s UIContentSizeCategory changes.
This property is modeled after the adjustsFontForContentSizeCategory property in the
UIContentSizeCategoryAdjusting protocol added by Apple in iOS 10.0.
Default value is NO.
*/
@property(nonatomic, readonly, nullable) MDCFeatureHighlightView *featureHighlightView;
@property(nonatomic, readwrite, setter=mdc_setAdjustsFontForContentSizeCategory:)
BOOL mdc_adjustsFontForContentSizeCategory UI_APPEARANCE_SELECTOR;

/**
Dismisses the feature highlight using the 'accept' style dismissal animation and triggers the
Expand Down
Expand Up @@ -94,6 +94,8 @@ - (void)loadView {
_featureHighlightView.displayedView = _displayedView;
_featureHighlightView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_featureHighlightView.mdc_adjustsFontForContentSizeCategory =
_mdc_adjustsFontForContentSizeCategory;

__weak MDCFeatureHighlightViewController *weakSelf = self;
_featureHighlightView.interactionBlock = ^(BOOL accepted) {
Expand Down Expand Up @@ -158,6 +160,38 @@ - (void)viewWillTransitionToSize:(CGSize)size
completion:nil];
}

- (UIColor *)outerHighlightColor {
return self.view.outerHighlightColor;
}

- (void)setOuterHighlightColor:(UIColor *)outerHighlightColor {
self.view.outerHighlightColor = outerHighlightColor;
}

- (UIColor *)innerHighlightColor {
return self.view.innerHighlightColor;
}

- (void)setInnerHighlightColor:(UIColor *)innerHighlightColor {
self.view.innerHighlightColor = innerHighlightColor;
}

- (UIColor *)titleColor {
return self.view.titleColor;
}

- (void)setTitleColor:(UIColor *)titleColor {
self.view.titleColor = titleColor;
}

- (UIColor *)bodyColor {
return self.view.bodyColor;
}

- (void)setBodyColor:(UIColor *)bodyColor {
self.view.bodyColor = bodyColor;
}

- (void)acceptFeature {
[self dismiss:YES];
}
Expand All @@ -181,8 +215,32 @@ - (void)dismiss:(BOOL)accepted {
}];
}

- (MDCFeatureHighlightView *)featureHighlightView {
return self.view;
#pragma mark - Dynamic Type

- (void)mdc_setAdjustsFontForContentSizeCategory:(BOOL)adjusts {
_mdc_adjustsFontForContentSizeCategory = adjusts;

if (_mdc_adjustsFontForContentSizeCategory) {
[self updateFontsForDynamicType];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contentSizeCategoryDidChange:)
name:UIContentSizeCategoryDidChangeNotification
object:nil];
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIContentSizeCategoryDidChangeNotification
object:nil];
}
}

- (void)contentSizeCategoryDidChange:(__unused NSNotification *)notification {
[self updateFontsForDynamicType];
}

- (void)updateFontsForDynamicType {
[_featureHighlightView updateTitleFont];
[_featureHighlightView updateBodyFont];
[_featureHighlightView layoutIfNeeded];
}

#pragma mark - Accessibility
Expand Down
Expand Up @@ -67,13 +67,6 @@ static inline CGPoint CGPointAddedToPoint(CGPoint a, CGPoint b) {
return CGPointMake(a.x + b.x, a.y + b.y);
}

@interface MDCFeatureHighlightView ()

@property (class, nonatomic, readonly) UIFont *titleFontDefault;
@property (class, nonatomic, readonly) UIFont *bodyFontDefault;

@end

@implementation MDCFeatureHighlightView {
BOOL _forceConcentricLayout;
UIView *_highlightView;
Expand Down Expand Up @@ -205,18 +198,49 @@ - (void)setOuterHighlightColor:(UIColor *)outerHighlightColor {

- (void)setTitleFont:(UIFont *)titleFont {
_titleFont = titleFont;
[self updateTitleFont];

[self updateTitleFont];
}

- (void)updateTitleFont {
UIFont *titleFont = _titleFont ?: [[self class] titleFontDefault];
if (_mdc_adjustsFontForContentSizeCategory) {
_titleLabel.font =
[titleFont mdc_fontSizedForMaterialTextStyle:kTitleTextStyle
scaledForDynamicType:_mdc_adjustsFontForContentSizeCategory];
// If we have a custom font apply it to the label.
// If not, fall back to the Material specified font.
if (_titleFont) {
// If we are automatically adjusting for Dynamic Type resize the font based on the text style
if (_mdc_adjustsFontForContentSizeCategory) {
_titleLabel.font =
[_titleFont mdc_fontSizedForMaterialTextStyle:kTitleTextStyle
scaledForDynamicType:_mdc_adjustsFontForContentSizeCategory];
} else {
_titleLabel.font = _titleFont;
}
} else {
_titleLabel.font = titleFont;
// TODO(#2709): Migrate to a single source of truth for fonts
// There is no custom font, so use the default font.
if (_mdc_adjustsFontForContentSizeCategory) {
// If we are using the default (system) font loader, retrieve the
// font from the UIFont preferredFont API.
if ([MDCTypography.fontLoader isKindOfClass:[MDCSystemFontLoader class]]) {
_titleLabel.font = [UIFont mdc_preferredFontForMaterialTextStyle:kTitleTextStyle];
} else {
// There is a custom font loader, retrieve the font and scale it.
UIFont *customTypographyFont = [MDCTypography titleFont];
_titleLabel.font =
[customTypographyFont mdc_fontSizedForMaterialTextStyle:kTitleTextStyle
scaledForDynamicType:_mdc_adjustsFontForContentSizeCategory];
}
} else {
// If we are using the default (system) font loader, retrieve the
// font from the UIFont standardFont API.
if ([MDCTypography.fontLoader isKindOfClass:[MDCSystemFontLoader class]]) {
_titleLabel.font = [UIFont mdc_standardFontForMaterialTextStyle:kTitleTextStyle];
} else {
// There is a custom font loader, retrieve the font from it.
_titleLabel.font = [MDCTypography titleFont];
}
}
}

[self setNeedsLayout];
}

Expand All @@ -226,35 +250,51 @@ - (void)setTitleColor:(UIColor *)titleColor {
_titleLabel.textColor = titleColor;
}

+ (UIFont *)titleFontDefault {
if ([MDCTypography.fontLoader isKindOfClass:[MDCSystemFontLoader class]]) {
return [UIFont mdc_standardFontForMaterialTextStyle:kTitleTextStyle];
}
return [MDCTypography titleFont];
}

- (void)setBodyFont:(UIFont *)bodyFont {
_bodyFont = bodyFont;
[self updateBodyFont];
}

+ (UIFont *)bodyFontDefault {
if ([MDCTypography.fontLoader isKindOfClass:[MDCSystemFontLoader class]]) {
return [UIFont mdc_standardFontForMaterialTextStyle:kBodyTextStyle];
}
return [MDCTypography body1Font];
[self updateBodyFont];
}

- (void)updateBodyFont {
UIFont *bodyFont = _bodyFont ?: [[self class] bodyFontDefault];
if (_mdc_adjustsFontForContentSizeCategory) {
// If we are automatically adjusting for Dynamic Type resize the font based on the text style
_bodyLabel.font =
[bodyFont mdc_fontSizedForMaterialTextStyle:kBodyTextStyle
scaledForDynamicType:_mdc_adjustsFontForContentSizeCategory];
// If we have a custom font apply it to the label.
// If not, fall back to the Material specified font.
if (_bodyFont) {
if (_mdc_adjustsFontForContentSizeCategory) {
// If we are automatically adjusting for Dynamic Type resize the font based on the text style
_bodyLabel.font =
[_bodyFont mdc_fontSizedForMaterialTextStyle:kBodyTextStyle
scaledForDynamicType:_mdc_adjustsFontForContentSizeCategory];
} else {
_bodyLabel.font = _bodyFont;
}
} else {
_bodyLabel.font = bodyFont;
// TODO(#2709): Migrate to a single source of truth for fonts
// There is no custom font, so use the default font.
if (_mdc_adjustsFontForContentSizeCategory) {
// If we are using the default (system) font loader, retrieve the
// font from the UIFont preferredFont API.
if ([MDCTypography.fontLoader isKindOfClass:[MDCSystemFontLoader class]]) {
_bodyLabel.font = [UIFont mdc_preferredFontForMaterialTextStyle:kBodyTextStyle];
} else {
// There is a custom font loader, retrieve the font and scale it.
UIFont *customTypographyFont = [MDCTypography body1Font];
_bodyLabel.font =
[customTypographyFont mdc_fontSizedForMaterialTextStyle:kBodyTextStyle
scaledForDynamicType:_mdc_adjustsFontForContentSizeCategory];
}
} else {
// If we are using the default (system) font loader, retrieve the
// font from the UIFont standardFont API.
if ([MDCTypography.fontLoader isKindOfClass:[MDCSystemFontLoader class]]) {
_bodyLabel.font = [UIFont mdc_standardFontForMaterialTextStyle:kBodyTextStyle];
} else {
// There is a custom font loader, retrieve the font from it.
_bodyLabel.font = [MDCTypography body1Font];
}
}
}

[self setNeedsLayout];
}

Expand Down Expand Up @@ -640,14 +680,12 @@ - (void)mdc_setAdjustsFontForContentSizeCategory:(BOOL)adjusts {

[self updateTitleFont];
[self updateBodyFont];
[self layoutIfNeeded];
}

// Handles UIContentSizeCategoryDidChangeNotifications
- (void)contentSizeCategoryDidChange:(__unused NSNotification *)notification {
[self updateTitleFont];
[self updateBodyFont];
[self layoutIfNeeded];
}

#pragma mark - UIGestureRecognizerDelegate (Tap)
Expand Down

0 comments on commit 19de254

Please sign in to comment.