Commit d82ed312 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Support dark mode for widgets

With the new +widgetVibrancyEffectForStyle: visual effect views,
setting the alpha of the button in HighlightButton doesn't work.
(According to the docs, this never should have worked.) Now,
HighlightButton takes a list of views to highlight.

Bug: 976683
Change-Id: I44e6b10e58fad7acb25bb591f46ae31878ab0fdd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736673
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688052}
parent 09fc0bb9
...@@ -9,6 +9,13 @@ ...@@ -9,6 +9,13 @@
// A button that fades opacity on highlight. // A button that fades opacity on highlight.
@interface HighlightButton : UIButton @interface HighlightButton : UIButton
// If the button has subviews that are UIVisualEffectViews, fading the opacity
// breaks the visual effect. If this array is non-nil, only the views in this
// array will have their opacities faded. Otherwise, the entire view will fade
// opacity.
@property(nonatomic, strong) NSArray<UIView*>* highlightableViews;
@end @end
#endif // IOS_CHROME_COMMON_HIGHLIGHT_BUTTON_H_ #endif // IOS_CHROME_COMMON_HIGHLIGHT_BUTTON_H_
...@@ -15,11 +15,20 @@ ...@@ -15,11 +15,20 @@
- (void)setHighlighted:(BOOL)highlighted { - (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted]; [super setHighlighted:highlighted];
NSArray<UIView*>* highlightViews;
if (self.highlightableViews) {
highlightViews = self.highlightableViews;
} else {
highlightViews = @[ self ];
}
[UIView transitionWithView:self [UIView transitionWithView:self
duration:ios::material::kDuration8 duration:ios::material::kDuration8
options:UIViewAnimationOptionCurveEaseInOut options:UIViewAnimationOptionCurveEaseInOut
animations:^{ animations:^{
self.alpha = highlighted ? 0.5 : 1.0; for (UIView* view in highlightViews) {
view.alpha = highlighted ? 0.5 : 1.0;
}
} }
completion:nil]; completion:nil];
} }
......
...@@ -193,7 +193,7 @@ const int kRows = 2; ...@@ -193,7 +193,7 @@ const int kRows = 2;
// Something bad happened when saving the icon. Switch to best effort to // Something bad happened when saving the icon. Switch to best effort to
// show something to the user. // show something to the user.
// kDefaultTextColor = SK_ColorWHITE; // kDefaultTextColor = SK_ColorWHITE;
site.fallbackTextColor = [UIColor whiteColor]; site.fallbackTextColor = UIColor.whiteColor;
// kDefaultBackgroundColor = SkColorSetRGB(0x78, 0x78, 0x78); // kDefaultBackgroundColor = SkColorSetRGB(0x78, 0x78, 0x78);
site.fallbackBackgroundColor = [UIColor colorWithRed:0x78 / 255.0f site.fallbackBackgroundColor = [UIColor colorWithRed:0x78 / 255.0f
green:0x78 / 255.0f green:0x78 / 255.0f
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#endif #endif
namespace { namespace {
const CGFloat kLabelTextColor = 0.314;
const NSInteger kLabelNumLines = 2; const NSInteger kLabelNumLines = 2;
const CGFloat kFaviconSize = 48; const CGFloat kFaviconSize = 48;
const CGFloat kSpaceFaviconTitle = 8; const CGFloat kSpaceFaviconTitle = 8;
...@@ -25,9 +24,7 @@ const CGFloat kTileWidth = 73; ...@@ -25,9 +24,7 @@ const CGFloat kTileWidth = 73;
@implementation MostVisitedTileView @implementation MostVisitedTileView
@synthesize faviconView = _faviconView;
@synthesize titleLabel = _titleLabel; @synthesize titleLabel = _titleLabel;
@synthesize URL = _URL;
#pragma mark - Public #pragma mark - Public
...@@ -40,13 +37,16 @@ const CGFloat kTileWidth = 73; ...@@ -40,13 +37,16 @@ const CGFloat kTileWidth = 73;
if (self) { if (self) {
UIVibrancyEffect* labelEffect = UIVibrancyEffect* labelEffect =
[UIVibrancyEffect widgetSecondaryVibrancyEffect]; [UIVibrancyEffect widgetSecondaryVibrancyEffect];
if (@available(iOS 13, *)) {
labelEffect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleSecondaryLabel];
}
UIVisualEffectView* titleLabelEffectView = UIVisualEffectView* titleLabelEffectView =
[[UIVisualEffectView alloc] initWithEffect:labelEffect]; [[UIVisualEffectView alloc] initWithEffect:labelEffect];
titleLabelEffectView.translatesAutoresizingMaskIntoConstraints = NO; titleLabelEffectView.translatesAutoresizingMaskIntoConstraints = NO;
_titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_titleLabel.textColor = [UIColor colorWithWhite:kLabelTextColor alpha:1.0];
_titleLabel.font = _titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]; [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2];
_titleLabel.textAlignment = NSTextAlignmentCenter; _titleLabel.textAlignment = NSTextAlignmentCenter;
...@@ -80,6 +80,8 @@ const CGFloat kTileWidth = 73; ...@@ -80,6 +80,8 @@ const CGFloat kTileWidth = 73;
]]; ]];
self.translatesAutoresizingMaskIntoConstraints = NO; self.translatesAutoresizingMaskIntoConstraints = NO;
self.highlightableViews = @[ _faviconView, _titleLabel ];
} }
return self; return self;
} }
......
...@@ -35,6 +35,9 @@ const CGFloat kURLButtonMargin = 10; ...@@ -35,6 +35,9 @@ const CGFloat kURLButtonMargin = 10;
// The button-shaped background view shown when there is a copied URL to open. // The button-shaped background view shown when there is a copied URL to open.
@property(nonatomic, strong) UIView* copiedButtonView; @property(nonatomic, strong) UIView* copiedButtonView;
@property(nonatomic, strong) UIVisualEffectView* primaryEffectView;
@property(nonatomic, strong) UIVisualEffectView* secondaryEffectView;
// Updates the view to show the currently set |type| and |copiedText|. // Updates the view to show the currently set |type| and |copiedText|.
- (void)updateUI; - (void)updateUI;
...@@ -57,13 +60,33 @@ const CGFloat kURLButtonMargin = 10; ...@@ -57,13 +60,33 @@ const CGFloat kURLButtonMargin = 10;
[UIVibrancyEffect widgetPrimaryVibrancyEffect]; [UIVibrancyEffect widgetPrimaryVibrancyEffect];
UIVibrancyEffect* secondaryEffect = UIVibrancyEffect* secondaryEffect =
[UIVibrancyEffect widgetSecondaryVibrancyEffect]; [UIVibrancyEffect widgetSecondaryVibrancyEffect];
UIVibrancyEffect* backgroundEffect =
[UIVibrancyEffect widgetSecondaryVibrancyEffect];
UIVibrancyEffect* hairlineEffect =
[UIVibrancyEffect widgetSecondaryVibrancyEffect];
if (@available(iOS 13, *)) {
primaryEffect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleLabel];
secondaryEffect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleSecondaryLabel];
backgroundEffect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleTertiaryFill];
hairlineEffect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleSeparator];
}
UIVisualEffectView* primaryEffectView = _primaryEffectView =
[[UIVisualEffectView alloc] initWithEffect:primaryEffect]; [[UIVisualEffectView alloc] initWithEffect:primaryEffect];
UIVisualEffectView* secondaryEffectView = _secondaryEffectView =
[[UIVisualEffectView alloc] initWithEffect:secondaryEffect]; [[UIVisualEffectView alloc] initWithEffect:secondaryEffect];
for (UIVisualEffectView* effectView in UIVisualEffectView* backgroundEffectView =
@[ primaryEffectView, secondaryEffectView ]) { [[UIVisualEffectView alloc] initWithEffect:backgroundEffect];
UIVisualEffectView* hairlineEffectView =
[[UIVisualEffectView alloc] initWithEffect:hairlineEffect];
for (UIVisualEffectView* effectView in @[
_primaryEffectView, _secondaryEffectView, backgroundEffectView,
hairlineEffectView
]) {
[self addSubview:effectView]; [self addSubview:effectView];
effectView.translatesAutoresizingMaskIntoConstraints = NO; effectView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self, effectView); AddSameConstraints(self, effectView);
...@@ -71,29 +94,39 @@ const CGFloat kURLButtonMargin = 10; ...@@ -71,29 +94,39 @@ const CGFloat kURLButtonMargin = 10;
} }
_hairlineView = [[UIView alloc] initWithFrame:CGRectZero]; _hairlineView = [[UIView alloc] initWithFrame:CGRectZero];
_hairlineView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05]; // The new widget vibrancy style API requires new colors for the views.
if (@available(iOS 13, *)) {
_hairlineView.backgroundColor = UIColor.separatorColor;
} else {
_hairlineView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05];
}
_hairlineView.translatesAutoresizingMaskIntoConstraints = NO; _hairlineView.translatesAutoresizingMaskIntoConstraints = NO;
[secondaryEffectView.contentView addSubview:_hairlineView]; [hairlineEffectView.contentView addSubview:_hairlineView];
_copiedButtonView = [[UIView alloc] init]; _copiedButtonView = [[UIView alloc] init];
_copiedButtonView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05]; // The new widget vibrancy style API requires new colors for the views.
if (@available(iOS 13, *)) {
_copiedButtonView.backgroundColor = UIColor.whiteColor;
} else {
_copiedButtonView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05];
}
_copiedButtonView.layer.cornerRadius = 5; _copiedButtonView.layer.cornerRadius = 5;
_copiedButtonView.translatesAutoresizingMaskIntoConstraints = NO; _copiedButtonView.translatesAutoresizingMaskIntoConstraints = NO;
[secondaryEffectView.contentView addSubview:_copiedButtonView]; [backgroundEffectView.contentView addSubview:_copiedButtonView];
_openCopiedContentTitleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _openCopiedContentTitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_openCopiedContentTitleLabel.textAlignment = NSTextAlignmentCenter; _openCopiedContentTitleLabel.textAlignment = NSTextAlignmentCenter;
_openCopiedContentTitleLabel.translatesAutoresizingMaskIntoConstraints = NO; _openCopiedContentTitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_openCopiedContentTitleLabel.font = _openCopiedContentTitleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
[primaryEffectView.contentView addSubview:_openCopiedContentTitleLabel]; [_primaryEffectView.contentView addSubview:_openCopiedContentTitleLabel];
_copiedContentLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _copiedContentLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_copiedContentLabel.textAlignment = NSTextAlignmentCenter; _copiedContentLabel.textAlignment = NSTextAlignmentCenter;
_copiedContentLabel.font = _copiedContentLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]; [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
_copiedContentLabel.translatesAutoresizingMaskIntoConstraints = NO; _copiedContentLabel.translatesAutoresizingMaskIntoConstraints = NO;
[secondaryEffectView.contentView addSubview:_copiedContentLabel]; [_secondaryEffectView.contentView addSubview:_copiedContentLabel];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[_hairlineView.topAnchor constraintEqualToAnchor:self.topAnchor], [_hairlineView.topAnchor constraintEqualToAnchor:self.topAnchor],
...@@ -133,6 +166,10 @@ const CGFloat kURLButtonMargin = 10; ...@@ -133,6 +166,10 @@ const CGFloat kURLButtonMargin = 10;
constraintEqualToAnchor:_openCopiedContentTitleLabel.trailingAnchor], constraintEqualToAnchor:_openCopiedContentTitleLabel.trailingAnchor],
]]; ]];
[self setCopiedContentType:CopiedContentTypeNone copiedText:nil]; [self setCopiedContentType:CopiedContentTypeNone copiedText:nil];
self.highlightableViews = @[
_hairlineView, _copiedButtonView, _openCopiedContentTitleLabel,
_copiedContentLabel
];
} }
return self; return self;
} }
...@@ -151,8 +188,22 @@ const CGFloat kURLButtonMargin = 10; ...@@ -151,8 +188,22 @@ const CGFloat kURLButtonMargin = 10;
self.hairlineView.hidden = hasContent; self.hairlineView.hidden = hasContent;
self.accessibilityTraits = self.accessibilityTraits =
(hasContent) ? UIAccessibilityTraitLink : UIAccessibilityTraitNone; (hasContent) ? UIAccessibilityTraitLink : UIAccessibilityTraitNone;
self.copiedContentLabel.alpha = (hasContent) ? 1 : 0.5; if (@available(iOS 13, *)) {
self.openCopiedContentTitleLabel.alpha = (hasContent) ? 1 : 0.5; if (hasContent) {
self.primaryEffectView.effect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleLabel];
self.secondaryEffectView.effect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleSecondaryLabel];
} else {
self.primaryEffectView.effect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleSecondaryLabel];
self.secondaryEffectView.effect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleTertiaryLabel];
}
} else {
self.copiedContentLabel.alpha = (hasContent) ? 1 : 0.5;
self.openCopiedContentTitleLabel.alpha = (hasContent) ? 1 : 0.5;
}
NSString* titleText; NSString* titleText;
NSString* contentText; NSString* contentText;
......
...@@ -36,24 +36,43 @@ const CGFloat kIconSize = 35; ...@@ -36,24 +36,43 @@ const CGFloat kIconSize = 35;
[UIVibrancyEffect widgetPrimaryVibrancyEffect]; [UIVibrancyEffect widgetPrimaryVibrancyEffect];
UIVibrancyEffect* secondaryEffect = UIVibrancyEffect* secondaryEffect =
[UIVibrancyEffect widgetSecondaryVibrancyEffect]; [UIVibrancyEffect widgetSecondaryVibrancyEffect];
UIVibrancyEffect* iconBackgroundEffect =
[UIVibrancyEffect widgetSecondaryVibrancyEffect];
if (@available(iOS 13, *)) {
primaryEffect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleLabel];
secondaryEffect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleSecondaryLabel];
iconBackgroundEffect = [UIVibrancyEffect
widgetEffectForVibrancyStyle:UIVibrancyEffectStyleTertiaryFill];
}
UIVisualEffectView* primaryEffectView = UIVisualEffectView* primaryEffectView =
[[UIVisualEffectView alloc] initWithEffect:primaryEffect]; [[UIVisualEffectView alloc] initWithEffect:primaryEffect];
UIVisualEffectView* secondaryEffectView = UIVisualEffectView* secondaryEffectView =
[[UIVisualEffectView alloc] initWithEffect:secondaryEffect]; [[UIVisualEffectView alloc] initWithEffect:secondaryEffect];
for (UIVisualEffectView* effectView in UIVisualEffectView* iconBackgroundEffectView =
@[ primaryEffectView, secondaryEffectView ]) { [[UIVisualEffectView alloc] initWithEffect:iconBackgroundEffect];
[self addSubview:effectView]; for (UIVisualEffectView* effectView in @[
primaryEffectView, secondaryEffectView, iconBackgroundEffectView
]) {
effectView.translatesAutoresizingMaskIntoConstraints = NO; effectView.translatesAutoresizingMaskIntoConstraints = NO;
effectView.userInteractionEnabled = NO; effectView.userInteractionEnabled = NO;
AddSameConstraints(self, effectView);
} }
UIView* circleView = [[UIView alloc] initWithFrame:CGRectZero]; UIView* circleView = [[UIView alloc] initWithFrame:CGRectZero];
circleView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05]; circleView.translatesAutoresizingMaskIntoConstraints = NO;
if (@available(iOS 13, *)) {
circleView.backgroundColor = UIColor.whiteColor;
} else {
circleView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05];
}
circleView.layer.cornerRadius = kActionButtonSize / 2; circleView.layer.cornerRadius = kActionButtonSize / 2;
[iconBackgroundEffectView.contentView addSubview:circleView];
AddSameConstraints(iconBackgroundEffectView.contentView, circleView);
UILabel* labelView = [[UILabel alloc] initWithFrame:CGRectZero]; UILabel* labelView = [[UILabel alloc] initWithFrame:CGRectZero];
labelView.translatesAutoresizingMaskIntoConstraints = NO;
labelView.text = title; labelView.text = title;
labelView.numberOfLines = 0; labelView.numberOfLines = 0;
labelView.textAlignment = NSTextAlignmentCenter; labelView.textAlignment = NSTextAlignmentCenter;
...@@ -62,22 +81,28 @@ const CGFloat kIconSize = 35; ...@@ -62,22 +81,28 @@ const CGFloat kIconSize = 35;
[labelView [labelView
setContentCompressionResistancePriority:UILayoutPriorityRequired setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical]; forAxis:UILayoutConstraintAxisVertical];
[secondaryEffectView.contentView addSubview:labelView];
AddSameConstraints(secondaryEffectView.contentView, labelView);
UIStackView* stack = [[UIStackView alloc] UIStackView* stack = [[UIStackView alloc] initWithArrangedSubviews:@[
initWithArrangedSubviews:@[ circleView, labelView ]]; iconBackgroundEffectView, secondaryEffectView
]];
stack.axis = UILayoutConstraintAxisVertical; stack.axis = UILayoutConstraintAxisVertical;
stack.spacing = kIconSpacing; stack.spacing = kIconSpacing;
stack.alignment = UIStackViewAlignmentCenter; stack.alignment = UIStackViewAlignmentCenter;
stack.translatesAutoresizingMaskIntoConstraints = NO; stack.translatesAutoresizingMaskIntoConstraints = NO;
[secondaryEffectView.contentView addSubview:stack]; stack.userInteractionEnabled = NO;
AddSameConstraints(secondaryEffectView, stack); [self addSubview:stack];
AddSameConstraints(self, stack);
UIImage* iconImage = [UIImage imageNamed:imageName]; UIImage* iconImage = [UIImage imageNamed:imageName];
iconImage = iconImage =
[iconImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [iconImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView* icon = [[UIImageView alloc] initWithImage:iconImage]; UIImageView* icon = [[UIImageView alloc] initWithImage:iconImage];
icon.translatesAutoresizingMaskIntoConstraints = NO; icon.translatesAutoresizingMaskIntoConstraints = NO;
[primaryEffectView.contentView addSubview:icon]; [primaryEffectView.contentView addSubview:icon];
AddSameConstraints(primaryEffectView.contentView, icon);
[self addSubview:primaryEffectView];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[circleView.widthAnchor constraintEqualToConstant:kActionButtonSize], [circleView.widthAnchor constraintEqualToConstant:kActionButtonSize],
...@@ -93,6 +118,8 @@ const CGFloat kIconSize = 35; ...@@ -93,6 +118,8 @@ const CGFloat kIconSize = 35;
action:actionSelector action:actionSelector
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
self.accessibilityLabel = title; self.accessibilityLabel = title;
self.highlightableViews = @[ circleView, labelView, icon ];
} }
return self; return self;
} }
......
...@@ -53,13 +53,6 @@ const CGFloat kMaxContentSize = 421; ...@@ -53,13 +53,6 @@ const CGFloat kMaxContentSize = 421;
@implementation SearchWidgetView @implementation SearchWidgetView
@synthesize target = _target;
@synthesize copiedURLSection = _copiedURLSection;
@synthesize actionsSection = _actionsSection;
@synthesize actionsContent = _actionsContent;
@synthesize compactHeight = _compactHeight;
@synthesize actionsSectionHeightConstraint = _actionsSectionHeightConstraint;
- (instancetype)initWithActionTarget:(id<SearchWidgetViewActionTarget>)target - (instancetype)initWithActionTarget:(id<SearchWidgetViewActionTarget>)target
compactHeight:(CGFloat)compactHeight { compactHeight:(CGFloat)compactHeight {
self = [super initWithFrame:CGRectZero]; self = [super initWithFrame:CGRectZero];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment