[PR] Updates the edit flow in PaymentRequest UI
1. Exits 'edit' mode after saving or canceling changes to an address,
credit card, or contact info.
2. Changes the label of the edit screen's 'Done' button to 'Save'.
TBR=sdefresne@
Bug: 814856
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ie69697299e92d7f8a922104f84c002c37b5a442b
Reviewed-on: https://chromium-review.googlesource.com/1007865
Commit-Queue: Moe Ahmadi <[email protected]>
Reviewed-by: Eugene But <[email protected]>
Cr-Commit-Position: refs/heads/master@{#550388}
diff --git a/components/components_strings.grd b/components/components_strings.grd
index 9134fb8..3b1c6bfa 100644
--- a/components/components_strings.grd
+++ b/components/components_strings.grd
@@ -298,6 +298,9 @@
<message name="IDS_ACCNAME_DONE" desc="The accessible name for the DONE button.">
Done
</message>
+ <message name="IDS_ACCNAME_SAVE" desc="The accessible name for the SAVE button.">
+ Save
+ </message>
<message name="IDS_ACCNAME_CLOSE" desc="The accessible name for the Close button.">
Close
</message>
diff --git a/ios/chrome/browser/ui/payments/contact_info_selection_coordinator.mm b/ios/chrome/browser/ui/payments/contact_info_selection_coordinator.mm
index f80cc9e..8d831ea7 100644
--- a/ios/chrome/browser/ui/payments/contact_info_selection_coordinator.mm
+++ b/ios/chrome/browser/ui/payments/contact_info_selection_coordinator.mm
@@ -134,6 +134,8 @@
- (void)contactInfoEditCoordinator:(ContactInfoEditCoordinator*)coordinator
didFinishEditingProfile:(autofill::AutofillProfile*)profile {
+ BOOL isEditing = [self.viewController isEditing];
+
// Update the data source with the new data.
[self.mediator loadItems];
@@ -151,18 +153,21 @@
self.mediator.selectableItems[index];
editedItem.complete = YES;
- if (![self.viewController isEditing]) {
+ if (!isEditing) {
// Update the data source with the selection.
self.mediator.selectedItemIndex = index;
}
+ // Exit 'edit' mode, if applicable.
+ [self.viewController setEditing:NO];
+
[self.viewController loadModel];
[self.viewController.collectionView reloadData];
[self.contactInfoEditCoordinator stop];
self.contactInfoEditCoordinator = nil;
- if (![self.viewController isEditing]) {
+ if (!isEditing) {
// Inform |self.delegate| that |profile| has been selected.
[self.delegate contactInfoSelectionCoordinator:self
didSelectContactProfile:profile];
@@ -171,6 +176,13 @@
- (void)contactInfoEditCoordinatorDidCancel:
(ContactInfoEditCoordinator*)coordinator {
+ // Exit 'edit' mode, if applicable.
+ if ([self.viewController isEditing]) {
+ [self.viewController setEditing:NO];
+ [self.viewController loadModel];
+ [self.viewController.collectionView reloadData];
+ }
+
[self.contactInfoEditCoordinator stop];
self.contactInfoEditCoordinator = nil;
}
diff --git a/ios/chrome/browser/ui/payments/payment_method_selection_coordinator.mm b/ios/chrome/browser/ui/payments/payment_method_selection_coordinator.mm
index 8e6f02b..b624de4 100644
--- a/ios/chrome/browser/ui/payments/payment_method_selection_coordinator.mm
+++ b/ios/chrome/browser/ui/payments/payment_method_selection_coordinator.mm
@@ -143,6 +143,8 @@
- (void)creditCardEditCoordinator:(CreditCardEditCoordinator*)coordinator
didFinishEditingPaymentMethod:
(payments::AutofillPaymentInstrument*)creditCard {
+ BOOL isEditing = [self.viewController isEditing];
+
// Update the data source with the new data.
[self.mediator loadItems];
@@ -158,18 +160,21 @@
self.mediator.selectableItems[position - paymentMethods.begin()];
editedItem.complete = YES;
- if (![self.viewController isEditing]) {
+ if (!isEditing) {
// Update the data source with the selection.
self.mediator.selectedItemIndex = position - paymentMethods.begin();
}
+ // Exit 'edit' mode, if applicable.
+ [self.viewController setEditing:NO];
+
[self.viewController loadModel];
[self.viewController.collectionView reloadData];
[self.creditCardEditCoordinator stop];
self.creditCardEditCoordinator = nil;
- if (![self.viewController isEditing]) {
+ if (!isEditing) {
// Inform |self.delegate| that this card has been selected.
[self.delegate paymentMethodSelectionCoordinator:self
didSelectPaymentMethod:creditCard];
@@ -178,6 +183,13 @@
- (void)creditCardEditCoordinatorDidCancel:
(CreditCardEditCoordinator*)coordinator {
+ // Exit 'edit' mode, if applicable.
+ if ([self.viewController isEditing]) {
+ [self.viewController setEditing:NO];
+ [self.viewController loadModel];
+ [self.viewController.collectionView reloadData];
+ }
+
[self.creditCardEditCoordinator stop];
self.creditCardEditCoordinator = nil;
}
diff --git a/ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h b/ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h
index f763ec0b..b04dbf7 100644
--- a/ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h
+++ b/ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h
@@ -63,7 +63,7 @@
// Convenience initializer. Initializes this view controller with the
// CollectionViewControllerStyleAppBar style and sets up the leading (cancel)
-// and the trailing (done) buttons.
+// and the trailing (save) buttons.
- (instancetype)init;
@end
diff --git a/ios/chrome/browser/ui/payments/payment_request_edit_view_controller.mm b/ios/chrome/browser/ui/payments/payment_request_edit_view_controller.mm
index 50ee8bb..a9d778a 100644
--- a/ios/chrome/browser/ui/payments/payment_request_edit_view_controller.mm
+++ b/ios/chrome/browser/ui/payments/payment_request_edit_view_controller.mm
@@ -194,7 +194,7 @@
initWithTitle:l10n_util::GetNSString(IDS_CANCEL)
style:UIBarButtonItemStylePlain
target:self
- action:@selector(onCancel)];
+ action:@selector(didCancel)];
[cancelButton setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor lightGrayColor]
}
@@ -203,19 +203,19 @@
setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)];
[self navigationItem].leftBarButtonItem = cancelButton;
- // Set up trailing (done) button.
- UIBarButtonItem* doneButton =
- [[UIBarButtonItem alloc] initWithTitle:l10n_util::GetNSString(IDS_DONE)
+ // Set up trailing (save) button.
+ UIBarButtonItem* saveButton =
+ [[UIBarButtonItem alloc] initWithTitle:l10n_util::GetNSString(IDS_SAVE)
style:UIBarButtonItemStylePlain
target:nil
- action:@selector(onDone)];
- [doneButton setTitleTextAttributes:@{
+ action:@selector(didSave)];
+ [saveButton setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor lightGrayColor]
}
forState:UIControlStateDisabled];
- [doneButton setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_DONE)];
- doneButton.enabled = NO; // Disabled until form has been validated.
- [self navigationItem].rightBarButtonItem = doneButton;
+ [saveButton setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_SAVE)];
+ saveButton.enabled = NO; // Disabled until form has been validated.
+ [self navigationItem].rightBarButtonItem = saveButton;
}
return self;
@@ -892,11 +892,11 @@
#pragma mark - PaymentRequestEditViewControllerActions methods
-- (void)onCancel {
+- (void)didCancel {
[self.delegate paymentRequestEditViewControllerDidCancel:self];
}
-- (void)onDone {
+- (void)didSave {
[_currentEditingCell.textField resignFirstResponder];
[self.delegate paymentRequestEditViewController:self
@@ -906,7 +906,7 @@
#pragma mark - UIAccessibilityAction
- (BOOL)accessibilityPerformEscape {
- [self onCancel];
+ [self didCancel];
return YES;
}
diff --git a/ios/chrome/browser/ui/payments/payment_request_edit_view_controller_actions.h b/ios/chrome/browser/ui/payments/payment_request_edit_view_controller_actions.h
index c8d24a6..1553e75b 100644
--- a/ios/chrome/browser/ui/payments/payment_request_edit_view_controller_actions.h
+++ b/ios/chrome/browser/ui/payments/payment_request_edit_view_controller_actions.h
@@ -9,10 +9,10 @@
@protocol PaymentRequestEditViewControllerActions
// Called when the user presses the cancel button.
-- (void)onCancel;
+- (void)didCancel;
-// Called when the user presses the done button.
-- (void)onDone;
+// Called when the user presses the save button.
+- (void)didSave;
@end
diff --git a/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm b/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm
index 001a03e..321a5ecd 100644
--- a/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm
+++ b/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm
@@ -143,6 +143,8 @@
- (void)addressEditCoordinator:(AddressEditCoordinator*)coordinator
didFinishEditingAddress:(autofill::AutofillProfile*)address {
+ BOOL isEditing = [self.viewController isEditing];
+
// Update the data source with the new data.
[self.mediator loadItems];
@@ -158,18 +160,21 @@
self.mediator.selectableItems[position - shippingProfiles.begin()];
editedItem.complete = YES;
- if (![self.viewController isEditing]) {
+ if (!isEditing) {
// Update the data source with the selection.
self.mediator.selectedItemIndex = position - shippingProfiles.begin();
}
+ // Exit 'edit' mode, if applicable.
+ [self.viewController setEditing:NO];
+
[self.viewController loadModel];
[self.viewController.collectionView reloadData];
[self.addressEditCoordinator stop];
self.addressEditCoordinator = nil;
- if (![self.viewController isEditing]) {
+ if (!isEditing) {
// Inform |self.delegate| that |address| has been selected.
[self.delegate shippingAddressSelectionCoordinator:self
didSelectShippingAddress:address];
@@ -177,6 +182,13 @@
}
- (void)addressEditCoordinatorDidCancel:(AddressEditCoordinator*)coordinator {
+ // Exit 'edit' mode, if applicable.
+ if ([self.viewController isEditing]) {
+ [self.viewController setEditing:NO];
+ [self.viewController loadModel];
+ [self.viewController.collectionView reloadData];
+ }
+
[self.addressEditCoordinator stop];
self.addressEditCoordinator = nil;
}