Commit c5a66ec7 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Adds confirmation of InfobarModal being configured successfully.

- configureModalViewController now returns true or false depending on the
modal being configured successfully.
- Adds a completion parameter that only gets executed if the Modal is
presented successfully.
- Reduces the tap animation time.

Bug: 981822
Change-Id: I89058d2342aee0190f7796e9e3b8576d7936b392
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1692756Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676022}
parent 7b213d69
...@@ -28,7 +28,7 @@ const CGFloat kBannerViewShadowOpacity = 0.23; ...@@ -28,7 +28,7 @@ const CGFloat kBannerViewShadowOpacity = 0.23;
const CGFloat kTappedBannerViewScale = 0.98; const CGFloat kTappedBannerViewScale = 0.98;
const CGFloat kSelectedBannerViewScale = 1.02; const CGFloat kSelectedBannerViewScale = 1.02;
const CGFloat kSelectBannerAnimationDurationInSeconds = 0.2; const CGFloat kSelectBannerAnimationDurationInSeconds = 0.2;
const CGFloat kTappedBannerAnimationDurationInSeconds = 0.1; const CGFloat kTappedBannerAnimationDurationInSeconds = 0.05;
const CGFloat kSelectedBannerViewYShadowOffset = 8.0; const CGFloat kSelectedBannerViewYShadowOffset = 8.0;
// Bottom Grip constants. // Bottom Grip constants.
...@@ -390,6 +390,9 @@ const CGFloat kLongPressTimeDurationInSeconds = 0.4; ...@@ -390,6 +390,9 @@ const CGFloat kLongPressTimeDurationInSeconds = 0.4;
// state. After the animation it presentd the Infobar Modal. // state. After the animation it presentd the Infobar Modal.
- (void)animateBannerTappedAndPresentModal { - (void)animateBannerTappedAndPresentModal {
[self.interactionDelegate infobarBannerStartedInteraction]; [self.interactionDelegate infobarBannerStartedInteraction];
// TODO(crbug.com/961343): Interrupt this animation in case the Banner needs
// to be dismissed mid tap (Currently it will be dismmissed after the
// animation).
[UIView animateWithDuration:kTappedBannerAnimationDurationInSeconds [UIView animateWithDuration:kTappedBannerAnimationDurationInSeconds
animations:^{ animations:^{
self.view.superview.transform = CGAffineTransformMakeScale( self.view.superview.transform = CGAffineTransformMakeScale(
......
...@@ -73,11 +73,12 @@ ...@@ -73,11 +73,12 @@
#pragma mark - InfobarCoordinatorImplementation #pragma mark - InfobarCoordinatorImplementation
- (void)configureModalViewController { - (BOOL)configureModalViewController {
self.modalViewController = self.modalViewController =
[[InfobarModalViewController alloc] initWithModalDelegate:self]; [[InfobarModalViewController alloc] initWithModalDelegate:self];
self.modalViewController.title = self.modalViewController.title =
base::SysUTF16ToNSString(self.confirmInfobarDelegate->GetMessageText()); base::SysUTF16ToNSString(self.confirmInfobarDelegate->GetMessageText());
return YES;
} }
- (void)infobarBannerWasPresented { - (void)infobarBannerWasPresented {
......
...@@ -140,9 +140,12 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -140,9 +140,12 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
self.modalTransitionDriver = [[InfobarModalTransitionDriver alloc] self.modalTransitionDriver = [[InfobarModalTransitionDriver alloc]
initWithTransitionMode:InfobarModalTransitionBase]; initWithTransitionMode:InfobarModalTransitionBase];
self.modalTransitionDriver.modalPositioner = self; self.modalTransitionDriver.modalPositioner = self;
__weak __typeof(self) weakSelf = self;
[self presentInfobarModalFrom:self.baseViewController [self presentInfobarModalFrom:self.baseViewController
driver:self.modalTransitionDriver]; driver:self.modalTransitionDriver
[self infobarModalPresentedFromBanner:NO]; completion:^{
[weakSelf infobarModalPresentedFromBanner:NO];
}];
}; };
// Dismiss InfobarBanner first if being presented. // Dismiss InfobarBanner first if being presented.
...@@ -193,9 +196,12 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -193,9 +196,12 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
self.modalTransitionDriver = [[InfobarModalTransitionDriver alloc] self.modalTransitionDriver = [[InfobarModalTransitionDriver alloc]
initWithTransitionMode:InfobarModalTransitionBanner]; initWithTransitionMode:InfobarModalTransitionBanner];
self.modalTransitionDriver.modalPositioner = self; self.modalTransitionDriver.modalPositioner = self;
__weak __typeof(self) weakSelf = self;
[self presentInfobarModalFrom:self.bannerViewController [self presentInfobarModalFrom:self.bannerViewController
driver:self.modalTransitionDriver]; driver:self.modalTransitionDriver
[self infobarModalPresentedFromBanner:YES]; completion:^{
[weakSelf infobarModalPresentedFromBanner:YES];
}];
} }
- (void)dismissInfobarBanner:(id)sender - (void)dismissInfobarBanner:(id)sender
...@@ -327,8 +333,9 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -327,8 +333,9 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
#pragma mark InfobarCoordinatorImplementation #pragma mark InfobarCoordinatorImplementation
- (void)configureModalViewController { - (BOOL)configureModalViewController {
NOTREACHED() << "Subclass must implement."; NOTREACHED() << "Subclass must implement.";
return NO;
} }
- (void)infobarBannerWasPresented { - (void)infobarBannerWasPresented {
...@@ -358,9 +365,19 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -358,9 +365,19 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
#pragma mark - Private #pragma mark - Private
// |presentingViewController| presents the InfobarModal using |driver|. If
// Modal is presented successfully |completion| will be executed.
- (void)presentInfobarModalFrom:(UIViewController*)presentingViewController - (void)presentInfobarModalFrom:(UIViewController*)presentingViewController
driver:(InfobarModalTransitionDriver*)driver { driver:(InfobarModalTransitionDriver*)driver
[self configureModalViewController]; completion:(ProceduralBlock)completion {
BOOL infobarWasConfigured = [self configureModalViewController];
if (!infobarWasConfigured) {
if (driver.transitionMode == InfobarModalTransitionBanner) {
[self dismissInfobarBannerAnimated:NO completion:nil];
}
return;
}
DCHECK(self.modalViewController); DCHECK(self.modalViewController);
UINavigationController* navController = [[UINavigationController alloc] UINavigationController* navController = [[UINavigationController alloc]
initWithRootViewController:self.modalViewController]; initWithRootViewController:self.modalViewController];
...@@ -369,7 +386,7 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -369,7 +386,7 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
self.modalNavigationController = navController; self.modalNavigationController = navController;
[presentingViewController presentViewController:navController [presentingViewController presentViewController:navController
animated:YES animated:YES
completion:nil]; completion:completion];
[self.badgeDelegate infobarModalWasPresented:self.infobarType]; [self.badgeDelegate infobarModalWasPresented:self.infobarType];
} }
......
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
@protocol InfobarCoordinatorImplementation @protocol InfobarCoordinatorImplementation
// Initializes and configures the ModalViewController that will be presented by // Initializes and configures the ModalViewController that will be presented by
// the InfobarCoordinator. // the InfobarCoordinator. Returns YES if the modalViewController was configured
- (void)configureModalViewController; // successfully. If it returns NO no Modal should be presented.
- (BOOL)configureModalViewController;
// Performs any actions related to an Infobar Banner presentation. // Performs any actions related to an Infobar Banner presentation.
- (void)infobarBannerWasPresented; - (void)infobarBannerWasPresented;
......
...@@ -102,7 +102,13 @@ ...@@ -102,7 +102,13 @@
#pragma mark - InfobarCoordinatorImplementation #pragma mark - InfobarCoordinatorImplementation
- (void)configureModalViewController { - (BOOL)configureModalViewController {
// Return early if there's no delegate. e.g. A Modal presentation has been
// triggered after the Infobar was destroyed, but before the badge/banner
// were dismissed.
if (!self.passwordInfoBarDelegate)
return NO;
// Do not use |self.infobarBannerType| since the modal type might change each // Do not use |self.infobarBannerType| since the modal type might change each
// time is presented. e.g. We present a Modal of type Save and tap on "Save". // time is presented. e.g. We present a Modal of type Save and tap on "Save".
// The next time the Modal is presented we'll present a Modal of Type "Update" // The next time the Modal is presented we'll present a Modal of Type "Update"
...@@ -137,6 +143,7 @@ ...@@ -137,6 +143,7 @@
self.passwordInfoBarDelegate->IsCurrentPasswordSaved(); self.passwordInfoBarDelegate->IsCurrentPasswordSaved();
[self recordModalPresentationMetricsUsingModalType:infobarModalType]; [self recordModalPresentationMetricsUsingModalType:infobarModalType];
return YES;
} }
- (void)infobarBannerWasPresented { - (void)infobarBannerWasPresented {
......
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