Commit 452cd830 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Configures Save CreditCard InfobarBanner.

- Configures the CreditCard Banner for presentation.
- Implements Banner related methods like performInfobarAction
and dismissBannerWhenInteractionIsFinished.
- On InfobarCoordinator detachView (which is called when the Infobar
view needs to be removed) we only dismiss the VC if they have been
created. This is needed since now a CreditCard InfobarBanner can be created
while other one is being presented, since replace is not supported
it will discard the new Infobar, thus calling detachView in an Infobar
that was never presented.

Screenshot:
https://drive.google.com/open?id=1bmPWLDNIEsJYORx8YfOs82wsYUKdoXcN

Bug: 1014652
Change-Id: Icd50ed542743054b38924fba668c42f38dbcc7f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865445Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707129}
parent c4735a6b
......@@ -190,8 +190,10 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
}
- (void)detachView {
[self dismissInfobarBanner:self animated:NO completion:nil];
[self dismissInfobarModal:self animated:NO completion:nil];
if (self.bannerViewController)
[self dismissInfobarBanner:self animated:NO completion:nil];
if (self.modalViewController)
[self dismissInfobarModal:self animated:NO completion:nil];
[self stop];
}
......
......@@ -4,12 +4,14 @@
#import "ios/chrome/browser/ui/infobars/coordinators/infobar_save_card_coordinator.h"
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/payments/autofill_save_card_infobar_delegate_mobile.h"
#include "ios/chrome/browser/infobars/infobar_controller_delegate.h"
#import "ios/chrome/browser/infobars/infobar_type.h"
#import "ios/chrome/browser/ui/infobars/banners/infobar_banner_view_controller.h"
#import "ios/chrome/browser/ui/infobars/coordinators/infobar_coordinator_implementation.h"
#import "ios/chrome/browser/ui/infobars/infobar_container.h"
#include "ui/gfx/image/image.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -50,7 +52,20 @@
- (void)start {
if (!self.started) {
self.started = YES;
// TODO(crbug.com/1014652): Configure and present Banner.
self.bannerViewController = [[InfobarBannerViewController alloc]
initWithDelegate:self
presentsModal:self.hasBadge
type:InfobarType::kInfobarTypeSaveCard];
self.bannerViewController.buttonText =
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate->GetButtonLabel(
ConfirmInfoBarDelegate::BUTTON_OK));
self.bannerViewController.titleText = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->GetMessageText());
self.bannerViewController.subTitleText =
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate->card_label());
gfx::Image icon = self.saveCardInfoBarDelegate->GetIcon();
if (!icon.IsEmpty())
self.bannerViewController.iconImage = icon.ToUIImage();
}
}
......@@ -69,29 +84,50 @@
#pragma mark - InfobarCoordinatorImplementation
- (void)performInfobarAction {
// TODO(crbug.com/1014652): Continue implementation.
if (self.saveCardInfoBarDelegate->upload()) {
// TODO(crbug.com/1014652): Open Modal if CreditCard details will be
// uploaded. Meaning that the ToS needs to be displayed.
} else if (self.saveCardInfoBarDelegate->Accept()) {
// TODO(crbug.com/1014652): Until a post save editing functionality is
// implemented the Infobar will be completely removed after its been
// accepted.
if (self.modalViewController) {
[self dismissInfobarModal:self
animated:YES
completion:^{
// TODO(crbug.com/1014652): Once the badge is created
// confirm detachView completely removes it.
[self detachView];
}];
} else {
[self dismissInfobarBannerAnimated:YES
completion:^{
[self detachView];
}];
}
}
}
- (void)infobarWasDismissed {
// Release these strong ViewControllers at the time of infobar dismissal.
self.bannerViewController = nil;
self.modalViewController = nil;
if (self.saveCardInfoBarDelegate)
self.saveCardInfoBarDelegate->InfoBarDismissed();
}
#pragma mark Banner
- (void)infobarBannerWasPresented {
// TODO(crbug.com/1014652): Continue implementation.
// TODO(crbug.com/1014652): Record metrics here if there's a distinction
// between automatic and manual presentation.
}
- (void)dismissBannerWhenInteractionIsFinished {
// TODO(crbug.com/1014652): Continue implementation.
[self.bannerViewController dismissWhenInteractionIsFinished];
}
- (void)infobarBannerWillBeDismissed:(BOOL)userInitiated {
// TODO(crbug.com/1014652): Continue implementation.
// TODO(crbug.com/1014652): Record metrics here if there's a distinction
// between ignoring or dismissing the Infobar.
}
#pragma mark Modal
......
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