Commit 2185701b authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Update ConsentBump's buttons

This CL makes sure the ConsentBump buttons are correctly updated based
on the screen currently displayed.

Bug: 866506
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Id40cee04d6b07f4556b54867344f23d88324c0e3
Reviewed-on: https://chromium-review.googlesource.com/1161864
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580528}
parent 64b266a1
......@@ -528,12 +528,18 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_CLEAR_SAVED_PASSWORDS" desc="Label for the option in settings to clear saved passwords. In titlecase. [Length: 20em] [iOS only]">
Saved Passwords
</message>
<message name="IDS_IOS_CONSENT_BUMP_IM_IN" desc="Title for the Consent Bump 'accept' button. If the user press this button, then the users agrees to the consent bump prompt.">
Yes, I'm in
</message>
<message name="IDS_IOS_CONSENT_BUMP_NO_CHANGE_TEXT" desc="Text for the Consent Bump personalization option to not make any change to the existing sync options. [iOS only]">
The data sync to Google and the features you use will not change
</message>
<message name="IDS_IOS_CONSENT_BUMP_NO_CHANGE_TITLE" desc="Title for the Consent Bump personalization option to not make any change to the existing sync options. [iOS only]">
Make no changes
</message>
<message name="IDS_IOS_CONSENT_BUMP_MORE" desc="Title for the button in the ConsentBump to display more options for personalizing the sync settings. [iOS only]">
More Options
</message>
<message name="IDS_IOS_CONSENT_BUMP_PERSONALIZATION_TITLE" desc="Title for the Consent Bump personalization menu, presented when the user wants more informations and control over the sync personalization. [iOS only]">
Control Sync, Personalization, and More
</message>
......
......@@ -9,20 +9,26 @@ source_set("consent_bump") {
sources = [
"consent_bump_coordinator.h",
"consent_bump_coordinator.mm",
"consent_bump_mediator.h",
"consent_bump_mediator.mm",
"consent_bump_personalization_coordinator.h",
"consent_bump_personalization_coordinator.mm",
]
deps = [
":consent_bump_ui",
"//base",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/authentication/unified_consent",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ui/base",
]
}
source_set("consent_bump_ui") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"consent_bump_consumer.h",
"consent_bump_option_button.h",
"consent_bump_option_button.mm",
"consent_bump_personalization_view_controller.h",
......
// Copyright 2018 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_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_CONSUMER_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_CONSUMER_H_
#import <Foundation/Foundation.h>
// Consumer protocol for the ConsentBump
@protocol ConsentBumpConsumer
// Sets the title of the primary button of the ConsentBump.
- (void)setPrimaryButtonTitle:(NSString*)primaryButtonTitle;
// Sets the title of the secondary button of the ConsentBump.
- (void)setSecondaryButtonTitle:(NSString*)secondaryButtonTitle;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_CONSUMER_H_
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_mediator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_personalization_coordinator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_view_controller.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_view_controller_delegate.h"
......@@ -13,18 +14,10 @@
#error "This file requires ARC support."
#endif
namespace {
// Type of child coordinator presented by this coordinator.
typedef NS_ENUM(NSInteger, PresentedCoordinator) {
PresentedCoordinatorUnifiedConsent,
PresentedCoordinatorPersonalization,
};
} // namespace
@interface ConsentBumpCoordinator ()<ConsentBumpViewControllerDelegate>
// Which child coordinator is currently presented.
@property(nonatomic, assign) PresentedCoordinator presentedCoordinator;
@property(nonatomic, assign) ConsentBumpScreen presentedCoordinatorType;
// The ViewController of this coordinator, redefined as a
// ConsentBumpViewController.
......@@ -36,15 +29,18 @@ typedef NS_ENUM(NSInteger, PresentedCoordinator) {
// The child coordinator presenting the presonalization content.
@property(nonatomic, strong)
ConsentBumpPersonalizationCoordinator* personalizationCoordinator;
// Mediator for this coordinator.
@property(nonatomic, strong) ConsentBumpMediator* mediator;
@end
@implementation ConsentBumpCoordinator
@synthesize presentedCoordinator = _presentedCoordinator;
@synthesize presentedCoordinatorType = _presentedCoordinatorType;
@synthesize consentBumpViewController = _consentBumpViewController;
@synthesize unifiedConsentCoordinator = _unifiedConsentCoordinator;
@synthesize personalizationCoordinator = _personalizationCoordinator;
@synthesize mediator = _mediator;
#pragma mark - Properties
......@@ -52,21 +48,31 @@ typedef NS_ENUM(NSInteger, PresentedCoordinator) {
return self.consentBumpViewController;
}
- (void)setPresentedCoordinatorType:
(ConsentBumpScreen)presentedCoordinatorType {
_presentedCoordinatorType = presentedCoordinatorType;
[self.mediator updateConsumerForConsentBumpScreen:presentedCoordinatorType];
}
#pragma mark - ChromeCoordinator
- (void)start {
self.consentBumpViewController = [[ConsentBumpViewController alloc] init];
self.consentBumpViewController.delegate = self;
self.mediator = [[ConsentBumpMediator alloc] init];
self.mediator.consumer = self.consentBumpViewController;
self.unifiedConsentCoordinator = [[UnifiedConsentCoordinator alloc] init];
[self.unifiedConsentCoordinator start];
self.presentedCoordinator = PresentedCoordinatorUnifiedConsent;
self.presentedCoordinatorType = ConsentBumpScreenUnifiedConsent;
self.consentBumpViewController.contentViewController =
self.unifiedConsentCoordinator.viewController;
}
- (void)stop {
self.mediator = nil;
self.consentBumpViewController = nil;
self.unifiedConsentCoordinator = nil;
self.personalizationCoordinator = nil;
......@@ -76,11 +82,11 @@ typedef NS_ENUM(NSInteger, PresentedCoordinator) {
- (void)consentBumpViewControllerDidTapPrimaryButton:
(ConsentBumpViewController*)consentBumpViewController {
switch (self.presentedCoordinator) {
case PresentedCoordinatorUnifiedConsent:
switch (self.presentedCoordinatorType) {
case ConsentBumpScreenUnifiedConsent:
// TODO(crbug.com/866506): Consent bump accepted.
break;
case PresentedCoordinatorPersonalization:
case ConsentBumpScreenPersonalization:
// TODO(crbug.com/866506): Clarify what should be the behavior at this
// point.
break;
......@@ -89,8 +95,8 @@ typedef NS_ENUM(NSInteger, PresentedCoordinator) {
- (void)consentBumpViewControllerDidTapSecondaryButton:
(ConsentBumpViewController*)consentBumpViewController {
switch (self.presentedCoordinator) {
case PresentedCoordinatorUnifiedConsent:
switch (self.presentedCoordinatorType) {
case ConsentBumpScreenUnifiedConsent:
// Present the personlization.
if (!self.personalizationCoordinator) {
self.personalizationCoordinator =
......@@ -100,14 +106,14 @@ typedef NS_ENUM(NSInteger, PresentedCoordinator) {
}
self.consentBumpViewController.contentViewController =
self.personalizationCoordinator.viewController;
self.presentedCoordinator = PresentedCoordinatorPersonalization;
self.presentedCoordinatorType = ConsentBumpScreenPersonalization;
break;
case PresentedCoordinatorPersonalization:
case ConsentBumpScreenPersonalization:
// Go back to the unified consent.
self.consentBumpViewController.contentViewController =
self.unifiedConsentCoordinator.viewController;
self.presentedCoordinator = PresentedCoordinatorUnifiedConsent;
self.presentedCoordinatorType = ConsentBumpScreenUnifiedConsent;
break;
}
}
......
// Copyright 2018 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_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_MEDIATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_MEDIATOR_H_
#import <Foundation/Foundation.h>
@protocol ConsentBumpConsumer;
// Type of consent bump sub-screen.
typedef NS_ENUM(NSInteger, ConsentBumpScreen) {
ConsentBumpScreenUnifiedConsent,
ConsentBumpScreenPersonalization,
};
// Mediator for the consent bump, updating the consumer as needed.
@interface ConsentBumpMediator : NSObject
// Consumer for this mediator.
@property(nonatomic, weak) id<ConsentBumpConsumer> consumer;
// Updates the consumer such as it is displaying information relative to the
// |consentBumpScreen|.
- (void)updateConsumerForConsentBumpScreen:(ConsentBumpScreen)consentBumpScreen;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_MEDIATOR_H_
// Copyright 2018 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/authentication/consent_bump/consent_bump_mediator.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_consumer.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ConsentBumpMediator
@synthesize consumer = _consumer;
- (void)updateConsumerForConsentBumpScreen:
(ConsentBumpScreen)consentBumpScreen {
switch (consentBumpScreen) {
case ConsentBumpScreenUnifiedConsent:
[self.consumer setPrimaryButtonTitle:l10n_util::GetNSString(
IDS_IOS_CONSENT_BUMP_IM_IN)];
[self.consumer setSecondaryButtonTitle:l10n_util::GetNSString(
IDS_IOS_CONSENT_BUMP_MORE)];
break;
case ConsentBumpScreenPersonalization:
[self.consumer
setPrimaryButtonTitle:l10n_util::GetNSString(IDS_ACCNAME_OK)];
[self.consumer
setSecondaryButtonTitle:l10n_util::GetNSString(IDS_ACCNAME_BACK)];
break;
}
}
@end
......@@ -7,10 +7,12 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_consumer.h"
@protocol ConsentBumpViewControllerDelegate;
// View Controller handling the ConsentBump screen.
@interface ConsentBumpViewController : UIViewController
@interface ConsentBumpViewController : UIViewController<ConsentBumpConsumer>
// Delegate for the view controller.
@property(nonatomic, weak) id<ConsentBumpViewControllerDelegate> delegate;
......
......@@ -5,7 +5,10 @@
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_view_controller.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_view_controller_delegate.h"
#include "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -14,6 +17,12 @@
namespace {
const CGFloat kMargin = 16;
const CGFloat kGradientHeight = 40;
const int kButtonBackgroundColor = 0x1A73E8;
const CGFloat kButtonTitleGreyShade = 0.98;
const CGFloat kButtonCornerRadius = 8;
const CGFloat kButtonPadding = 16;
const CGFloat kButtonMinimalWidth = 80;
const CGFloat kButtonTitleChangeAnimationDuration = 0.15;
} // namespace
@interface ConsentBumpViewController ()
......@@ -73,8 +82,13 @@ const CGFloat kGradientHeight = 40;
if (!_primaryButton) {
_primaryButton = [UIButton buttonWithType:UIButtonTypeSystem];
_primaryButton.translatesAutoresizingMaskIntoConstraints = NO;
[_primaryButton setTitle:@"Primary Button" forState:UIControlStateNormal];
_primaryButton.backgroundColor = [UIColor blueColor];
_primaryButton.backgroundColor = UIColorFromRGB(kButtonBackgroundColor);
[_primaryButton
setTitleColor:[UIColor colorWithWhite:kButtonTitleGreyShade alpha:1]
forState:UIControlStateNormal];
_primaryButton.layer.cornerRadius = kButtonCornerRadius;
_primaryButton.contentEdgeInsets =
UIEdgeInsetsMake(0, kButtonPadding, 0, kButtonPadding);
[_primaryButton setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisVertical];
[_primaryButton addTarget:self
......@@ -88,8 +102,6 @@ const CGFloat kGradientHeight = 40;
if (!_secondaryButton) {
_secondaryButton = [UIButton buttonWithType:UIButtonTypeSystem];
_secondaryButton.translatesAutoresizingMaskIntoConstraints = NO;
[_secondaryButton setTitle:@"Secondary Button"
forState:UIControlStateNormal];
[_secondaryButton setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisVertical];
[_secondaryButton addTarget:self
......@@ -166,9 +178,44 @@ const CGFloat kGradientHeight = 40;
[self.primaryButton.leadingAnchor
constraintGreaterThanOrEqualToAnchor:self.secondaryButton
.trailingAnchor],
// Add minimum width to the buttons to have a better looking animation when
// changing the label.
[self.primaryButton.widthAnchor
constraintGreaterThanOrEqualToConstant:kButtonMinimalWidth],
[self.secondaryButton.widthAnchor
constraintGreaterThanOrEqualToConstant:kButtonMinimalWidth],
]];
}
#pragma mark - ConsentBumpConsumer
- (void)setPrimaryButtonTitle:(NSString*)secondaryButtonTitle {
// Use CrossDisolve to avoid issue where the button is changing size before
// changing its label, leading to an inconsistent animation.
[UIView transitionWithView:self.primaryButton
duration:kButtonTitleChangeAnimationDuration
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.primaryButton setTitle:secondaryButtonTitle
forState:UIControlStateNormal];
}
completion:nil];
}
- (void)setSecondaryButtonTitle:(NSString*)secondaryButtonTitle {
// Use CrossDisolve to avoid issue where the button is changing size before
// changing its label, leading to an inconsistent animation.
[UIView transitionWithView:self.primaryButton
duration:kButtonTitleChangeAnimationDuration
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.secondaryButton setTitle:secondaryButtonTitle
forState:UIControlStateNormal];
}
completion:nil];
}
#pragma mark - Private
- (void)primaryButtonCallback {
......
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