Commit bc190334 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Create CustomPresentation for the IdentityChooser

The Identity Chooser popup was using the MDC presentation style. It
is not in line with the current style applied with UI Refresh.

This CL creates the classes to be user to present the popup according
to the new styling. For now, no animation or styling is done.

Bug: 873065
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I73b93e0d47c7ebe2e2b5756faaf6fea32be63b3e
Reviewed-on: https://chromium-review.googlesource.com/1169815Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582530}
parent 77121bde
......@@ -28,12 +28,18 @@ source_set("identity_chooser_ui") {
sources = [
"identity_chooser_add_account_item.h",
"identity_chooser_add_account_item.mm",
"identity_chooser_animator.h",
"identity_chooser_animator.mm",
"identity_chooser_cell.h",
"identity_chooser_cell.mm",
"identity_chooser_header_item.h",
"identity_chooser_header_item.mm",
"identity_chooser_item.h",
"identity_chooser_item.mm",
"identity_chooser_presentation_controller.h",
"identity_chooser_presentation_controller.mm",
"identity_chooser_transition_delegate.h",
"identity_chooser_transition_delegate.mm",
"identity_chooser_view_controller.h",
"identity_chooser_view_controller.mm",
"identity_chooser_view_controller_presentation_delegate.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_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_ANIMATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_ANIMATOR_H_
#import <UIKit/UIKit.h>
// Animator, taking care of the animation of the IdentityChooser.
@interface IdentityChooserAnimator
: NSObject<UIViewControllerAnimatedTransitioning>
@property(nonatomic, assign) BOOL appearing;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_ANIMATOR_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/unified_consent/identity_chooser/identity_chooser_animator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation IdentityChooserAnimator
@synthesize appearing = _appearing;
#pragma mark - UIViewControllerAnimatedTransitioning
- (void)animateTransition:
(id<UIViewControllerContextTransitioning>)transitionContext {
// Get views and view controllers for this transition.
// The baseView is the view on top of which the VC is presented.
UIView* baseView = [transitionContext
viewForKey:self.appearing ? UITransitionContextFromViewKey
: UITransitionContextToViewKey];
// The VC being presented/dismissed and its view.
UIViewController* presentedViewController = [transitionContext
viewControllerForKey:self.appearing
? UITransitionContextToViewControllerKey
: UITransitionContextFromViewControllerKey];
UIView* presentedView = [transitionContext
viewForKey:self.appearing ? UITransitionContextToViewKey
: UITransitionContextFromViewKey];
// Always add the destination view to the container.
UIView* containerView = [transitionContext containerView];
if (self.appearing) {
[containerView addSubview:presentedView];
} else {
[containerView addSubview:baseView];
}
presentedView.frame =
[transitionContext finalFrameForViewController:presentedViewController];
[transitionContext completeTransition:YES];
}
- (NSTimeInterval)transitionDuration:
(id<UIViewControllerContextTransitioning>)transitionContext {
return 0;
}
@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_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_PRESENTATION_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_PRESENTATION_CONTROLLER_H_
#import <UIKit/UIKit.h>
// Presentation controller for presenting the IdentityChooser. It is presenting
// it as a Modal.
@interface IdentityChooserPresentationController : UIPresentationController
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_PRESENTATION_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/unified_consent/identity_chooser/identity_chooser_presentation_controller.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kMaxWidth = 350;
const CGFloat kMaxHeight = 350;
const CGFloat kMinimumMargin = 25;
} // namespace
@interface IdentityChooserPresentationController ()
@property(nonatomic, strong) UIView* shieldView;
@end
@implementation IdentityChooserPresentationController
@synthesize shieldView = _shieldView;
#pragma mark - UIPresentationController
- (CGRect)frameOfPresentedViewInContainerView {
CGRect safeAreaFrame = UIEdgeInsetsInsetRect(
self.containerView.bounds, SafeAreaInsetsForView(self.containerView));
CGFloat availableWidth = CGRectGetWidth(safeAreaFrame);
CGFloat availableHeight = CGRectGetHeight(safeAreaFrame);
CGFloat width = MIN(kMaxWidth, availableWidth - 2 * kMinimumMargin);
CGFloat height = MIN(kMaxHeight, availableHeight - 2 * kMinimumMargin);
CGRect presentedViewFrame = safeAreaFrame;
presentedViewFrame.origin.x += (availableWidth - width) / 2;
presentedViewFrame.origin.y += (availableHeight - height) / 2;
presentedViewFrame.size.width = width;
presentedViewFrame.size.height = height;
return presentedViewFrame;
}
- (void)presentationTransitionWillBegin {
self.shieldView = [[UIView alloc] init];
// TODO(crbug.com/873065): Change this for the real shadow.
self.shieldView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
self.shieldView.frame = self.containerView.bounds;
[self.containerView addSubview:self.shieldView];
[self.shieldView
addGestureRecognizer:[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleShieldTap)]];
[self.containerView addSubview:self.presentedViewController.view];
}
- (void)containerViewWillLayoutSubviews {
self.shieldView.frame = self.containerView.bounds;
self.presentedViewController.view.frame =
[self frameOfPresentedViewInContainerView];
}
#pragma mark - Private
- (void)handleShieldTap {
[self.presentedViewController dismissViewControllerAnimated:YES
completion: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_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_TRANSITION_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_TRANSITION_DELEGATE_H_
#import <UIKit/UIKit.h>
// Transition Delegate for the IdentityChooser. It is presenting it as a modal.
@interface IdentityChooserTransitionDelegate
: NSObject<UIViewControllerTransitioningDelegate>
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_UNIFIED_CONSENT_IDENTITY_CHOOSER_IDENTITY_CHOOSER_TRANSITION_DELEGATE_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/unified_consent/identity_chooser/identity_chooser_transition_delegate.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_animator.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_presentation_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation IdentityChooserTransitionDelegate
#pragma mark - UIViewControllerTransitioningDelegate
- (UIPresentationController*)
presentationControllerForPresentedViewController:(UIViewController*)presented
presentingViewController:(UIViewController*)presenting
sourceViewController:(UIViewController*)source {
return [[IdentityChooserPresentationController alloc]
initWithPresentedViewController:presented
presentingViewController:presenting];
}
- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForPresentedController:(UIViewController*)presented
presentingController:(UIViewController*)presenting
sourceController:(UIViewController*)source {
IdentityChooserAnimator* animator = [[IdentityChooserAnimator alloc] init];
animator.appearing = YES;
return animator;
}
- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForDismissedController:(UIViewController*)dismissed {
IdentityChooserAnimator* animator = [[IdentityChooserAnimator alloc] init];
animator.appearing = NO;
return animator;
}
@end
......@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_item.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_transition_delegate.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_view_controller_presentation_delegate.h"
#import "ios/third_party/material_components_ios/src/components/Dialogs/src/MaterialDialogs.h"
......@@ -28,7 +29,7 @@ const CGFloat kFooterHeight = 17.;
@interface IdentityChooserViewController ()
@property(nonatomic, strong)
MDCDialogTransitionController* transitionController;
IdentityChooserTransitionDelegate* transitionController;
@end
......@@ -42,7 +43,7 @@ const CGFloat kFooterHeight = 17.;
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) {
self.modalPresentationStyle = UIModalPresentationCustom;
_transitionController = [[MDCDialogTransitionController alloc] init];
_transitionController = [[IdentityChooserTransitionDelegate alloc] init];
self.transitioningDelegate = _transitionController;
self.modalPresentationStyle = UIModalPresentationCustom;
}
......
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