Commit 111d22ec authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Implement custom presentation for infobar modals.

This CL updates InfobarModalOverlayCoordinator to use an
InfobarModalTransitionDriver to present infobar modal UI.

It also updates the save password infobar delegate so that
calls to InfobarPresenting() and InfobarDismissed() are
idempotent.  This is necessary because with the second
phase of the infobar UI reboot, the modal is presented
while the banner is still visible if the banner's show
modal button is tapped.  This should only count as a single
infobar presentation event.

Bug: 1030357
Change-Id: I3266395c25215163d32bf4d669e906804df172e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2041031
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750378}
parent 230f4fb5
......@@ -239,7 +239,8 @@ void IOSChromeSavePasswordInfoBarDelegate::UpdateCredentials(
void IOSChromeSavePasswordInfoBarDelegate::InfobarPresenting(bool automatic) {
DCHECK(IsInfobarUIRebootEnabled());
DCHECK(!infobar_presenting_);
if (infobar_presenting_)
return;
RecordPresentationMetrics(form_to_save(), current_password_saved_,
IsUpdateInfobar(infobar_type_), automatic);
......@@ -248,7 +249,8 @@ void IOSChromeSavePasswordInfoBarDelegate::InfobarPresenting(bool automatic) {
void IOSChromeSavePasswordInfoBarDelegate::InfobarDismissed() {
DCHECK(IsInfobarUIRebootEnabled());
DCHECK(infobar_presenting_);
if (!infobar_presenting_)
return;
RecordDismissalMetrics(form_to_save(), infobar_response(),
IsUpdateInfobar(infobar_type_));
......
......@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/infobars/presentation/infobar_modal_presentation_controller.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#import "ios/chrome/browser/ui/infobars/presentation/infobar_modal_positioner.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
......@@ -42,6 +43,14 @@ const CGFloat kContainerCornerRadius = 13.0;
return self;
}
- (BOOL)shouldPresentInFullscreen {
// Don't present in fullscreen when modals are shown using OverlayPresenter
// so that banners presented are inserted into the correct place in the view
// hierarchy. Returning NO adds the container view as a sibling view in front
// of the presenting view controller's view.
return !base::FeatureList::IsEnabled(kInfobarOverlayUI);
}
- (void)presentationTransitionWillBegin {
// Add a gesture recognizer to endEditing (thus hiding the keyboard) if a user
// taps outside the keyboard while one its being presented. Set
......
......@@ -26,6 +26,7 @@ source_set("coordinators") {
"//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/common/infobars",
"//ios/chrome/browser/ui/infobars/modals",
"//ios/chrome/browser/ui/infobars/presentation",
"//ios/chrome/browser/ui/overlays:coordinators",
]
}
......
......@@ -6,6 +6,9 @@
#import "ios/chrome/browser/ui/overlays/infobar_modal/infobar_modal_overlay_coordinator+modal_configuration.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/infobars/presentation/infobar_modal_positioner.h"
#import "ios/chrome/browser/ui/infobars/presentation/infobar_modal_transition_driver.h"
#import "ios/chrome/browser/ui/overlays/infobar_modal/infobar_modal_overlay_mediator.h"
#import "ios/chrome/browser/ui/overlays/overlay_request_coordinator+subclassing.h"
#import "ios/chrome/browser/ui/overlays/overlay_request_coordinator_delegate.h"
......@@ -14,9 +17,12 @@
#error "This file requires ARC support."
#endif
@interface InfobarModalOverlayCoordinator ()
@interface InfobarModalOverlayCoordinator () <InfobarModalPositioner>
// The navigation controller used to display the modal view.
@property(nonatomic) UINavigationController* modalNavController;
// The transition delegate used by the coordinator to present the modal UI.
@property(nonatomic, strong)
InfobarModalTransitionDriver* modalTransitionDriver;
@end
@implementation InfobarModalOverlayCoordinator
......@@ -28,13 +34,13 @@
return;
[self configureModal];
self.mediator = self.modalMediator;
self.modalTransitionDriver = [[InfobarModalTransitionDriver alloc]
initWithTransitionMode:InfobarModalTransitionBase];
self.modalTransitionDriver.modalPositioner = self;
self.modalNavController = [[UINavigationController alloc]
initWithRootViewController:self.modalViewController];
// TODO(crbug.com/1030357): Use custom presentation.
self.modalNavController.modalPresentationStyle =
UIModalPresentationOverCurrentContext;
self.modalNavController.modalTransitionStyle =
UIModalTransitionStyleCrossDissolve;
self.modalNavController.modalPresentationStyle = UIModalPresentationCustom;
self.modalNavController.transitioningDelegate = self.modalTransitionDriver;
[self.baseViewController presentViewController:self.viewController
animated:animated
completion:^{
......@@ -57,6 +63,14 @@
return self.modalNavController;
}
#pragma mark - InfobarModalPositioner
- (CGFloat)modalHeightForWidth:(CGFloat)width {
CGSize layoutBoundsSize = CGSizeMake(width, CGFLOAT_MAX);
return [self.modalViewController.view sizeThatFits:layoutBoundsSize].height +
CGRectGetHeight(self.modalNavController.navigationBar.bounds);
}
#pragma mark - Private
// Called when the presentation of the modal UI is completed.
......
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