[iOS FRE] Change primary button style when being touched down
Adds styling to primary buttons in the new FRE when they're being touched down. This is done by deriving from the UIButton class and overriding setHighlighted:. Because this new button class is only intended for the FRE primary buttons, it assumes the alpha for the non- highlighted state will always be 1. Bug: 1189815 Change-Id: I569f6bf964621b4c9d1bade032cc9bba6f66052e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2944841 Reviewed-by: Gauthier Ambard <gambard@chromium.org> Commit-Queue: Guillaume Jenkins <gujen@google.com> Cr-Commit-Position: refs/heads/master@{#890874}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
585ae54fa2
commit
4381eb8046
ios/chrome/browser/ui/first_run
@ -142,6 +142,8 @@ source_set("first_run_ui") {
|
||||
"first_run_screen_view_controller.h",
|
||||
"first_run_screen_view_controller.mm",
|
||||
"first_run_screen_view_controller_delegate.h",
|
||||
"highlighted_button.h",
|
||||
"highlighted_button.mm",
|
||||
]
|
||||
deps = [
|
||||
"//base",
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/i18n/rtl.h"
|
||||
#import "ios/chrome/browser/ui/first_run/highlighted_button.h"
|
||||
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
|
||||
#import "ios/chrome/common/ui/util/button_util.h"
|
||||
#import "ios/chrome/common/ui/util/pointer_interaction_util.h"
|
||||
@ -49,7 +50,7 @@ constexpr CGFloat kVerticalButtonSpacing = 10;
|
||||
@property(nonatomic, strong) UIView* scrollContentView;
|
||||
@property(nonatomic, strong) UILabel* titleLabel;
|
||||
@property(nonatomic, strong) UILabel* subtitleLabel;
|
||||
@property(nonatomic, strong) UIButton* primaryActionButton;
|
||||
@property(nonatomic, strong) HighlightedButton* primaryActionButton;
|
||||
@property(nonatomic, strong) UIButton* secondaryActionButton;
|
||||
@property(nonatomic, strong) UIButton* tertiaryActionButton;
|
||||
|
||||
@ -383,7 +384,24 @@ constexpr CGFloat kVerticalButtonSpacing = 10;
|
||||
|
||||
- (UIButton*)primaryActionButton {
|
||||
if (!_primaryActionButton) {
|
||||
_primaryActionButton = PrimaryActionButton(YES);
|
||||
_primaryActionButton = [[HighlightedButton alloc] initWithFrame:CGRectZero];
|
||||
_primaryActionButton.contentEdgeInsets =
|
||||
UIEdgeInsetsMake(kButtonVerticalInsets, 0, kButtonVerticalInsets, 0);
|
||||
[_primaryActionButton setBackgroundColor:[UIColor colorNamed:kBlueColor]];
|
||||
UIColor* titleColor = [UIColor colorNamed:kSolidButtonTextColor];
|
||||
[_primaryActionButton setTitleColor:titleColor
|
||||
forState:UIControlStateNormal];
|
||||
_primaryActionButton.titleLabel.font =
|
||||
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
|
||||
_primaryActionButton.layer.cornerRadius = kPrimaryButtonCornerRadius;
|
||||
_primaryActionButton.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
||||
if (@available(iOS 13.4, *)) {
|
||||
_primaryActionButton.pointerInteractionEnabled = YES;
|
||||
_primaryActionButton.pointerStyleProvider =
|
||||
CreateOpaqueButtonPointerStyleProvider();
|
||||
}
|
||||
|
||||
// Use |primaryActionString| even if scrolling to the end is mandatory
|
||||
// because at the viewDidLoad stage, the scroll view hasn't computed its
|
||||
// content height, so there is no way to know if scrolling is needed. This
|
||||
|
16
ios/chrome/browser/ui/first_run/highlighted_button.h
Normal file
16
ios/chrome/browser/ui/first_run/highlighted_button.h
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef IOS_CHROME_BROWSER_UI_FIRST_RUN_HIGHLIGHTED_BUTTON_H_
|
||||
#define IOS_CHROME_BROWSER_UI_FIRST_RUN_HIGHLIGHTED_BUTTON_H_
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
// A UIButton subclass that applies a lower alpha when the button is
|
||||
// highlighted. When the button isn't highlighted, the alpha is set to 1.
|
||||
@interface HighlightedButton : UIButton
|
||||
|
||||
@end
|
||||
|
||||
#endif // IOS_CHROME_BROWSER_UI_FIRST_RUN_HIGHLIGHTED_BUTTON_H_
|
35
ios/chrome/browser/ui/first_run/highlighted_button.mm
Normal file
35
ios/chrome/browser/ui/first_run/highlighted_button.mm
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "ios/chrome/browser/ui/first_run/highlighted_button.h"
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
#error "This file requires ARC support."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
// Tha alpha to apply when the button is highlighted.
|
||||
const CGFloat kHighlightedAlpha = 0.5;
|
||||
|
||||
// The duration of the animation when adding / removing transparency.
|
||||
const CGFloat kAnimationDuration = 0.1;
|
||||
|
||||
} // namespace
|
||||
|
||||
@implementation HighlightedButton
|
||||
|
||||
#pragma mark - Accessors
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted {
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
CGFloat targetAlpha = highlighted ? kHighlightedAlpha : 1.0;
|
||||
[UIView animateWithDuration:kAnimationDuration
|
||||
animations:^{
|
||||
weakSelf.alpha = targetAlpha;
|
||||
}];
|
||||
[super setHighlighted:highlighted];
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user