Commit 510f1512 authored by Marc-Antoine Courteau's avatar Marc-Antoine Courteau Committed by Commit Bot

[Payment Request] Adds a navigation bar to the country picker.

Video of the fix in action:
https://drive.google.com/file/d/0B4g_WskzVRJdVUtMdjJqVlliQ0U/view?usp=sharing

This is a third attempt at fixing this issue. The first one was reverted due to failures in ios_showcase_egtests on smaller devices. Those failures were caused by the fact that some elements were off-screen, and EarlGrey was unable to select them. The second one was also reverted due to failures on iPhone 5s with iOS 9.0.

Bug: 767154
Change-Id: Ia5cb29dd719ab58311db9122ef7e41c0771200d2
Reviewed-on: https://chromium-review.googlesource.com/678020Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Marc-Antoine Courteau <macourteau@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#503771}
Reviewed-on: https://chromium-review.googlesource.com/682395
Cr-Commit-Position: refs/heads/master@{#504266}
parent fd4acd52
......@@ -140,8 +140,10 @@ source_set("payments_ui") {
"//ios/chrome/browser/ui/collection_view",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/icons",
"//ios/chrome/browser/ui/material_components",
"//ios/chrome/browser/ui/payments/cells",
"//ios/third_party/material_components_ios",
"//third_party/libaddressinput:strings_grit",
"//ui/base",
]
libs = [ "UIKit.framework" ]
......
......@@ -187,4 +187,10 @@ using ::AutofillTypeFromAutofillUIType;
self.countrySelectionCoordinator = nil;
}
- (void)countrySelectionCoordinatorDidReturn:
(CountrySelectionCoordinator*)coordinator {
[self.countrySelectionCoordinator stop];
self.countrySelectionCoordinator = nil;
}
@end
......@@ -20,6 +20,11 @@
- (void)countrySelectionCoordinator:(CountrySelectionCoordinator*)coordinator
didSelectCountryWithCode:(NSString*)countryCode;
// Notifies the delegate that the user has chosen to return to the previous
// screen without making a selection.
- (void)countrySelectionCoordinatorDidReturn:
(CountrySelectionCoordinator*)coordinator;
@end
// Coordinator responsible for creating and presenting the country selection
......
......@@ -7,8 +7,6 @@
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/payments/payment_request_picker_row.h"
#include "ios/chrome/browser/ui/payments/payment_request_picker_view_controller.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -55,7 +53,6 @@ const int64_t kDelegateNotificationDelayInNanoSeconds = 0.2 * NSEC_PER_SEC;
self.viewController =
[[PaymentRequestPickerViewController alloc] initWithRows:rows
selected:selectedRow];
self.viewController.title = l10n_util::GetNSString(IDS_IOS_AUTOFILL_COUNTRY);
self.viewController.delegate = self;
DCHECK(self.baseViewController.navigationController);
......@@ -77,6 +74,11 @@ const int64_t kDelegateNotificationDelayInNanoSeconds = 0.2 * NSEC_PER_SEC;
[self delayedNotifyDelegateOfSelection:row.value];
}
- (void)paymentRequestPickerViewControllerDidFinish:
(PaymentRequestPickerViewController*)controller {
[self.delegate countrySelectionCoordinatorDidReturn:self];
}
#pragma mark - Helper methods
- (void)delayedNotifyDelegateOfSelection:(NSString*)countryCode {
......
......@@ -7,7 +7,10 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/material_components/app_bar_presenting.h"
extern NSString* const kPaymentRequestPickerRowAccessibilityID;
extern NSString* const kPaymentRequestPickerViewControllerAccessibilityID;
extern NSString* const kPaymentRequestPickerSearchBarAccessibilityID;
@class PaymentRequestPickerViewController;
......@@ -21,11 +24,16 @@ extern NSString* const kPaymentRequestPickerSearchBarAccessibilityID;
(PaymentRequestPickerViewController*)controller
didSelectRow:(PickerRow*)row;
// Notifies the delegate that the user has chosen to return to the previous
// screen without making a selection.
- (void)paymentRequestPickerViewControllerDidFinish:
(PaymentRequestPickerViewController*)controller;
@end
// TableViewController that displays a searchable list of rows featuring a
// selected row as well as an index list.
@interface PaymentRequestPickerViewController : UITableViewController
@interface PaymentRequestPickerViewController
: UITableViewController<AppBarPresenting>
// The delegate to be notified when the user selects a row.
@property(nonatomic, weak) id<PaymentRequestPickerViewControllerDelegate>
......
......@@ -6,8 +6,14 @@
#import "base/logging.h"
#import "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/icons/chrome_icon.h"
#import "ios/chrome/browser/ui/material_components/utils.h"
#import "ios/chrome/browser/ui/payments/payment_request_picker_row.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/third_party/material_components_ios/src/components/AppBar/src/MaterialAppBar.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
#include "third_party/libaddressinput/messages.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -15,13 +21,10 @@
NSString* const kPaymentRequestPickerRowAccessibilityID =
@"kPaymentRequestPickerRowAccessibilityID";
NSString* const kPaymentRequestPickerSearchBarAccessibilityID =
@"kPaymentRequestPickerSearchBarAccessibilityID";
namespace {
NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
@"kPaymentRequestPickerViewControllerAccessibilityID";
} // namespace
NSString* const kPaymentRequestPickerSearchBarAccessibilityID =
@"kPaymentRequestPickerSearchBarAccessibilityID";
@interface PaymentRequestPickerViewController ()<UISearchResultsUpdating>
......@@ -43,6 +46,8 @@ NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
@end
@implementation PaymentRequestPickerViewController
@synthesize appBar = _appBar;
@synthesize searchController = _searchController;
@synthesize allRows = _allRows;
@synthesize displayedRows = _displayedRows;
......@@ -54,6 +59,8 @@ NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
selected:(PickerRow*)selectedRow {
self = [super initWithStyle:UITableViewStylePlain];
if (self) {
self.title =
l10n_util::GetNSString(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL);
self.allRows = [rows sortedArrayUsingComparator:^NSComparisonResult(
PickerRow* row1, PickerRow* row2) {
return [row1.label localizedCaseInsensitiveCompare:row2.label];
......@@ -61,6 +68,17 @@ NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
self.selectedRow = selectedRow;
// Default to displaying all the rows.
self.displayedRows = self.allRows;
_appBar = [[MDCAppBar alloc] init];
[self addChildViewController:_appBar.headerViewController];
ConfigureAppBarWithCardStyle(_appBar);
// Set up leading (back) button.
UIBarButtonItem* backButton =
[ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon]
target:nil
action:@selector(onBack)];
self.appBar.navigationBar.backItem = backButton;
}
return self;
}
......@@ -78,10 +96,32 @@ NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
const bool isFullScreen =
!IsIPadIdiom() || ([self navigationController].modalPresentationStyle !=
UIModalPresentationFormSheet);
if (isFullScreen && [self navigationController].navigationBarHidden) {
// TODO(crbug.com/767428): When shown full screen, the UITableViewController
// uses the full screen even when the status bar is present, but insets the
// section headers by the size of the status bar. This will inset the
// content by the same amount, to ensure they line up properly. Also insets
// by one more pixel to hide the one pixel gap left in between the
// navigation bar and the UITableView.
const UIEdgeInsets statusBarInset =
UIEdgeInsetsMake(-1 - StatusBarHeight(), 0, 0, 0);
self.tableView.contentInset = statusBarInset;
self.tableView.scrollIndicatorInsets = statusBarInset;
}
self.tableView.rowHeight = MDCCellDefaultOneLineHeight;
self.tableView.accessibilityIdentifier =
kPaymentRequestPickerViewControllerAccessibilityID;
self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
self.tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
self.searchController =
[[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
......@@ -96,6 +136,18 @@ NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
// context. Make this class the presentation context so that the search
// controller does not present on top of the navigation controller.
self.definesPresentationContext = YES;
self.appBar.headerViewController.headerView.trackingScrollView =
self.tableView;
[self.appBar addSubviewsToParent];
}
- (UIViewController*)childViewControllerForStatusBarHidden {
return self.appBar.headerViewController;
}
- (UIViewController*)childViewControllerForStatusBarStyle {
return self.appBar.headerViewController;
}
#pragma mark - UITableViewDataSource
......@@ -141,6 +193,45 @@ NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
return cell;
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
MDCFlexibleHeaderView* headerView =
self.appBar.headerViewController.headerView;
if (scrollView == headerView.trackingScrollView) {
[headerView trackingScrollViewDidScroll];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView {
MDCFlexibleHeaderView* headerView =
self.appBar.headerViewController.headerView;
if (scrollView == headerView.trackingScrollView) {
[headerView trackingScrollViewDidEndDecelerating];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView*)scrollView
willDecelerate:(BOOL)decelerate {
MDCFlexibleHeaderView* headerView =
self.appBar.headerViewController.headerView;
if (scrollView == headerView.trackingScrollView) {
[headerView trackingScrollViewDidEndDraggingWillDecelerate:decelerate];
}
}
- (void)scrollViewWillEndDragging:(UIScrollView*)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint*)targetContentOffset {
MDCFlexibleHeaderView* headerView =
self.appBar.headerViewController.headerView;
if (scrollView == headerView.trackingScrollView) {
[headerView
trackingScrollViewWillEndDraggingWithVelocity:velocity
targetContentOffset:targetContentOffset];
}
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView*)tableView
......@@ -148,18 +239,20 @@ NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
if (self.selectedRow) {
NSIndexPath* oldSelectedIndexPath = [self indexPathForRow:self.selectedRow];
self.selectedRow = nil;
// Reload the previously selected row if it is displaying.
// Update the previously selected row if it is displaying.
if (oldSelectedIndexPath) {
[self.tableView reloadRowsAtIndexPaths:@[ oldSelectedIndexPath ]
withRowAnimation:UITableViewRowAnimationFade];
UITableViewCell* cell =
[self.tableView cellForRowAtIndexPath:oldSelectedIndexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
self.selectedRow =
[[self rowsInSection:indexPath.section] objectAtIndex:indexPath.row];
// Reload the newly selected row.
[self.tableView reloadRowsAtIndexPaths:@[ indexPath ]
withRowAnimation:UITableViewRowAnimationFade];
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[_delegate paymentRequestPickerViewController:self
didSelectRow:self.selectedRow];
......@@ -187,6 +280,9 @@ NSString* const kPaymentRequestPickerViewControllerAccessibilityID =
#pragma mark - Private
- (void)onBack {
[self.delegate paymentRequestPickerViewControllerDidFinish:self];
}
// Creates a mapping from section titles to rows in that section, for currently
// displaying rows, and updates |sectionTitleToSectionRowsMap|.
- (void)updateSectionTitleToSectionRowsMap {
......
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