Commit 44abf4c7 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Create the ConsentBump skeleton

This CL creates the architecture of the ConsentBump for the new sign in.

Bug: 866506
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I02fd7b3f2612f9c9510f111199100ca3e88b85fb
Reviewed-on: https://chromium-review.googlesource.com/1148320Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577513}
parent 7b1b1ba4
...@@ -52,6 +52,7 @@ source_set("authentication") { ...@@ -52,6 +52,7 @@ source_set("authentication") {
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/alert_coordinator", "//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/authentication/consent_bump",
"//ios/chrome/browser/ui/collection_view/cells", "//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/colors", "//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
......
# 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("//build/config/chrome_build.gni")
source_set("consent_bump") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"consent_bump_coordinator.h",
"consent_bump_coordinator.mm",
"consent_bump_personalization_coordinator.h",
"consent_bump_personalization_coordinator.mm",
"consent_bump_personalization_view_controller.h",
"consent_bump_personalization_view_controller.mm",
"consent_bump_view_controller.h",
"consent_bump_view_controller.mm",
"consent_bump_view_controller_delegate.h",
]
deps = [
"//base",
"//ios/chrome/browser/ui/authentication/unified_consent",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/common/ui_util",
]
}
// 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_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_COORDINATOR_H_
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
// Coordinator handling the consent bump.
@interface ConsentBumpCoordinator : ChromeCoordinator
// ViewController associated with this coordinator.
@property(nonatomic, strong, readonly) UIViewController* viewController;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_COORDINATOR_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_coordinator.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"
#import "ios/chrome/browser/ui/authentication/unified_consent/unified_consent_coordinator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#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;
// The ViewController of this coordinator, redefined as a
// ConsentBumpViewController.
@property(nonatomic, strong)
ConsentBumpViewController* consentBumpViewController;
// The child coordinator presenting the unified consent.
@property(nonatomic, strong)
UnifiedConsentCoordinator* unifiedConsentCoordinator;
// The child coordinator presenting the presonalization content.
@property(nonatomic, strong)
ConsentBumpPersonalizationCoordinator* personalizationCoordinator;
@end
@implementation ConsentBumpCoordinator
@synthesize presentedCoordinator = _presentedCoordinator;
@synthesize consentBumpViewController = _consentBumpViewController;
@synthesize unifiedConsentCoordinator = _unifiedConsentCoordinator;
@synthesize personalizationCoordinator = _personalizationCoordinator;
#pragma mark - Properties
- (UIViewController*)viewController {
return self.consentBumpViewController;
}
#pragma mark - ChromeCoordinator
- (void)start {
self.consentBumpViewController = [[ConsentBumpViewController alloc] init];
self.consentBumpViewController.delegate = self;
self.unifiedConsentCoordinator = [[UnifiedConsentCoordinator alloc] init];
[self.unifiedConsentCoordinator start];
self.presentedCoordinator = PresentedCoordinatorUnifiedConsent;
self.consentBumpViewController.contentViewController =
self.unifiedConsentCoordinator.viewController;
}
- (void)stop {
self.consentBumpViewController = nil;
self.unifiedConsentCoordinator = nil;
self.personalizationCoordinator = nil;
}
#pragma mark - ConsentBumpViewControllerDelegate
- (void)consentBumpViewControllerDidTapPrimaryButton:
(ConsentBumpViewController*)consentBumpViewController {
switch (self.presentedCoordinator) {
case PresentedCoordinatorUnifiedConsent:
// TODO(crbug.com/866506): Consent bump accepted.
break;
case PresentedCoordinatorPersonalization:
// TODO(crbug.com/866506): Clarify what should be the behavior at this
// point.
break;
}
}
- (void)consentBumpViewControllerDidTapSecondaryButton:
(ConsentBumpViewController*)consentBumpViewController {
switch (self.presentedCoordinator) {
case PresentedCoordinatorUnifiedConsent:
// Present the personlization.
if (!self.personalizationCoordinator) {
self.personalizationCoordinator =
[[ConsentBumpPersonalizationCoordinator alloc]
initWithBaseViewController:nil];
[self.personalizationCoordinator start];
}
self.consentBumpViewController.contentViewController =
self.personalizationCoordinator.viewController;
self.presentedCoordinator = PresentedCoordinatorPersonalization;
break;
case PresentedCoordinatorPersonalization:
// Go back to the unified consent.
self.consentBumpViewController.contentViewController =
self.unifiedConsentCoordinator.viewController;
self.presentedCoordinator = PresentedCoordinatorUnifiedConsent;
break;
}
}
@end
// 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_PERSONALIZATION_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_PERSONALIZATION_COORDINATOR_H_
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
// Coordinator for handling the ConsentBump Personalization screen.
@interface ConsentBumpPersonalizationCoordinator : ChromeCoordinator
// The view Controller for this coordinator.
@property(nonatomic, strong, readonly) UIViewController* viewController;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_PERSONALIZATION_COORDINATOR_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_personalization_coordinator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_personalization_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface ConsentBumpPersonalizationCoordinator ()
// The view controller, redefined as ConsentBumpPersonalizationViewController.
@property(nonatomic, strong)
ConsentBumpPersonalizationViewController* personalizationViewController;
@end
@implementation ConsentBumpPersonalizationCoordinator
@synthesize personalizationViewController = _personalizationViewController;
#pragma mark - Properties
- (UIViewController*)viewController {
return self.personalizationViewController;
}
#pragma mark - ChromeCoordinator
- (void)start {
self.personalizationViewController =
[[ConsentBumpPersonalizationViewController alloc] init];
}
- (void)stop {
self.personalizationViewController = nil;
}
@end
// 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_PERSONALIZATION_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_PERSONALIZATION_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
// View controller displaying the Personalization screen.
@interface ConsentBumpPersonalizationViewController : UIViewController
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_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.
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_personalization_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ConsentBumpPersonalizationViewController
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor blueColor];
}
@end
// 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_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
@protocol ConsentBumpViewControllerDelegate;
// View Controller handling the ConsentBump screen.
@interface ConsentBumpViewController : UIViewController
// Delegate for the view controller.
@property(nonatomic, weak) id<ConsentBumpViewControllerDelegate> delegate;
// View controller displayed as child view controller for this ViewController.
@property(nonatomic, strong) UIViewController* contentViewController;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_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.
#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"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kMargin = 16;
const CGFloat kGradientHeight = 40;
} // namespace
@interface ConsentBumpViewController ()
@property(nonatomic, strong) UIView* buttonContainer;
@property(nonatomic, strong) UIButton* primaryButton;
@property(nonatomic, strong) UIButton* secondaryButton;
@property(nonatomic, strong) UIView* gradientView;
@property(nonatomic, strong) CAGradientLayer* gradientLayer;
@end
@implementation ConsentBumpViewController
@synthesize delegate = _delegate;
@synthesize contentViewController = _contentViewController;
@synthesize buttonContainer = _buttonContainer;
@synthesize primaryButton = _primaryButton;
@synthesize secondaryButton = _secondaryButton;
@synthesize gradientView = _gradientView;
@synthesize gradientLayer = _gradientLayer;
#pragma mark - Public
- (void)setContentViewController:(UIViewController*)contentViewController {
if (_contentViewController == contentViewController)
return;
// Remove previous VC.
[_contentViewController willMoveToParentViewController:nil];
[_contentViewController.view removeFromSuperview];
[_contentViewController removeFromParentViewController];
_contentViewController = contentViewController;
if (!contentViewController)
return;
[self addChildViewController:contentViewController];
contentViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view insertSubview:contentViewController.view
belowSubview:self.gradientView];
AddSameConstraintsToSides(
self.view, contentViewController.view,
LayoutSides::kTop | LayoutSides::kLeading | LayoutSides::kTrailing);
[contentViewController.view.bottomAnchor
constraintEqualToAnchor:self.buttonContainer.topAnchor]
.active = YES;
[contentViewController didMoveToParentViewController:self];
}
#pragma mark - Property
- (UIButton*)primaryButton {
if (!_primaryButton) {
_primaryButton = [UIButton buttonWithType:UIButtonTypeSystem];
_primaryButton.translatesAutoresizingMaskIntoConstraints = NO;
[_primaryButton setTitle:@"Primary Button" forState:UIControlStateNormal];
_primaryButton.backgroundColor = [UIColor blueColor];
[_primaryButton setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisVertical];
[_primaryButton addTarget:self
action:@selector(primaryButtonCallback)
forControlEvents:UIControlEventTouchUpInside];
}
return _primaryButton;
}
- (UIButton*)secondaryButton {
if (!_secondaryButton) {
_secondaryButton = [UIButton buttonWithType:UIButtonTypeSystem];
_secondaryButton.translatesAutoresizingMaskIntoConstraints = NO;
[_secondaryButton setTitle:@"Secondary Button"
forState:UIControlStateNormal];
[_secondaryButton setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisVertical];
[_secondaryButton addTarget:self
action:@selector(secondaryButtonCallback)
forControlEvents:UIControlEventTouchUpInside];
}
return _secondaryButton;
}
- (UIView*)buttonContainer {
if (!_buttonContainer) {
_buttonContainer = [[UIView alloc] init];
_buttonContainer.translatesAutoresizingMaskIntoConstraints = NO;
}
return _buttonContainer;
}
- (UIView*)gradientView {
if (!_gradientView) {
_gradientView = [[UIView alloc] initWithFrame:CGRectZero];
_gradientView.userInteractionEnabled = NO;
_gradientView.translatesAutoresizingMaskIntoConstraints = NO;
[_gradientView.layer insertSublayer:self.gradientLayer atIndex:0];
}
return _gradientView;
}
- (CAGradientLayer*)gradientLayer {
if (!_gradientLayer) {
_gradientLayer = [CAGradientLayer layer];
_gradientLayer.colors = @[
(id)[[UIColor colorWithWhite:1 alpha:0] CGColor],
(id)[self.view.backgroundColor CGColor]
];
}
return _gradientLayer;
}
#pragma mark - UIViewController
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.gradientLayer.frame = self.gradientView.bounds;
}
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor whiteColor];
// Add subviews.
[self.buttonContainer addSubview:self.primaryButton];
[self.buttonContainer addSubview:self.secondaryButton];
[self.view addSubview:self.buttonContainer];
[self.view addSubview:self.gradientView];
// Constraints.
id<LayoutGuideProvider> safeArea = SafeAreaLayoutGuideForView(self.view);
AddSameConstraintsToSides(self.view, self.gradientView,
LayoutSides::kLeading | LayoutSides::kTrailing);
AddSameConstraintsToSides(
safeArea, self.buttonContainer,
LayoutSides::kBottom | LayoutSides::kLeading | LayoutSides::kTrailing);
AddSameConstraintsToSidesWithInsets(
self.secondaryButton, self.buttonContainer,
LayoutSides::kLeading | LayoutSides::kTop | LayoutSides::kBottom,
ChromeDirectionalEdgeInsetsMake(kMargin, kMargin, kMargin, 0));
AddSameConstraintsToSidesWithInsets(
self.primaryButton, self.buttonContainer,
LayoutSides::kTrailing | LayoutSides::kTop | LayoutSides::kBottom,
ChromeDirectionalEdgeInsetsMake(kMargin, 0, kMargin, kMargin));
[NSLayoutConstraint activateConstraints:@[
[self.gradientView.heightAnchor constraintEqualToConstant:kGradientHeight],
[self.gradientView.bottomAnchor
constraintEqualToAnchor:self.buttonContainer.topAnchor],
[self.primaryButton.leadingAnchor
constraintGreaterThanOrEqualToAnchor:self.secondaryButton
.trailingAnchor],
]];
}
#pragma mark - Private
- (void)primaryButtonCallback {
[self.delegate consentBumpViewControllerDidTapPrimaryButton:self];
}
- (void)secondaryButtonCallback {
[self.delegate consentBumpViewControllerDidTapSecondaryButton:self];
}
@end
// 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_VIEW_CONTROLLER_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_VIEW_CONTROLLER_DELEGATE_H_
#import <UIKit/UIKit.h>
@class ConsentBumpViewController;
// Protocol for the delegate of the ConsentBumpViewController.
@protocol ConsentBumpViewControllerDelegate<NSObject>
// Notifies the delegate that the primary button of the view controller has been
// pressed.
- (void)consentBumpViewControllerDidTapPrimaryButton:
(ConsentBumpViewController*)consentBumpViewController;
// Notifies the delegate that the secondary button of the view controller has
// been pressed.
- (void)consentBumpViewControllerDidTapSecondaryButton:
(ConsentBumpViewController*)consentBumpViewController;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_VIEW_CONTROLLER_DELEGATE_H_
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