Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Unified Diff: ios/chrome/browser/payments/cells/autofill_profile_item.mm

Issue 2712053003: [Payment Request] Displays Contact Info in the payment summary view (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/payments/cells/autofill_profile_item.mm
diff --git a/ios/chrome/browser/payments/cells/shipping_address_item.mm b/ios/chrome/browser/payments/cells/autofill_profile_item.mm
similarity index 61%
rename from ios/chrome/browser/payments/cells/shipping_address_item.mm
rename to ios/chrome/browser/payments/cells/autofill_profile_item.mm
index 0d756e1d028edda398134dae0ebf69c47d8e9389..4e82bfaa24359e8c6ac09c4eb4b73c495b98ed54 100644
--- a/ios/chrome/browser/payments/cells/shipping_address_item.mm
+++ b/ios/chrome/browser/payments/cells/autofill_profile_item.mm
@@ -1,10 +1,11 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import "ios/chrome/browser/payments/cells/shipping_address_item.h"
+#import "ios/chrome/browser/payments/cells/autofill_profile_item.h"
-#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
+#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
+#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
@@ -22,11 +23,13 @@ const CGFloat kVerticalPadding = 16;
const CGFloat kVerticalSpacingBetweenLabels = 8;
} // namespace
-@implementation ShippingAddressItem
+@implementation AutofillProfileItem
@synthesize name = _name;
@synthesize address = _address;
@synthesize phoneNumber = _phoneNumber;
+@synthesize email = _email;
+@synthesize notification = _notification;
@synthesize accessoryType = _accessoryType;
#pragma mark CollectionViewItem
@@ -34,26 +37,32 @@ const CGFloat kVerticalSpacingBetweenLabels = 8;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
- self.cellClass = [ShippingAddressCell class];
+ self.cellClass = [AutofillProfileCell class];
}
return self;
}
-- (void)configureCell:(ShippingAddressCell*)cell {
+- (void)configureCell:(AutofillProfileCell*)cell {
[super configureCell:cell];
cell.accessoryType = self.accessoryType;
cell.nameLabel.text = self.name;
cell.addressLabel.text = self.address;
cell.phoneNumberLabel.text = self.phoneNumber;
+ cell.emailLabel.text = self.email;
+ cell.notificationLabel.text = self.notification;
}
@end
-@implementation ShippingAddressCell
+@implementation AutofillProfileCell {
+ UIStackView* _stackView;
+}
@synthesize nameLabel = _nameLabel;
@synthesize addressLabel = _addressLabel;
@synthesize phoneNumberLabel = _phoneNumberLabel;
+@synthesize emailLabel = _emailLabel;
+@synthesize notificationLabel = _notificationLabel;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
@@ -71,17 +80,31 @@ const CGFloat kVerticalSpacingBetweenLabels = 8;
UIView* contentView = self.contentView;
contentView.clipsToBounds = YES;
+ _stackView = [[UIStackView alloc] initWithArrangedSubviews:@[]];
+ _stackView.axis = UILayoutConstraintAxisVertical;
+ _stackView.layoutMarginsRelativeArrangement = YES;
+ _stackView.layoutMargins =
+ UIEdgeInsetsMake(kVerticalPadding, kHorizontalPadding, kVerticalPadding,
+ kHorizontalPadding);
+ _stackView.alignment = UIStackViewAlignmentLeading;
+ _stackView.spacing = kVerticalSpacingBetweenLabels;
+ _stackView.translatesAutoresizingMaskIntoConstraints = NO;
+ [contentView addSubview:_stackView];
+
_nameLabel = [[UILabel alloc] init];
- _nameLabel.translatesAutoresizingMaskIntoConstraints = NO;
- [contentView addSubview:_nameLabel];
+ [_stackView addArrangedSubview:_nameLabel];
_addressLabel = [[UILabel alloc] init];
- _addressLabel.translatesAutoresizingMaskIntoConstraints = NO;
- [contentView addSubview:_addressLabel];
+ [_stackView addArrangedSubview:_addressLabel];
_phoneNumberLabel = [[UILabel alloc] init];
- _phoneNumberLabel.translatesAutoresizingMaskIntoConstraints = NO;
- [contentView addSubview:_phoneNumberLabel];
+ [_stackView addArrangedSubview:_phoneNumberLabel];
+
+ _emailLabel = [[UILabel alloc] init];
+ [_stackView addArrangedSubview:_emailLabel];
+
+ _notificationLabel = [[UILabel alloc] init];
+ [_stackView addArrangedSubview:_notificationLabel];
}
// Set default font and text colors for labels.
@@ -98,43 +121,17 @@ const CGFloat kVerticalSpacingBetweenLabels = 8;
_phoneNumberLabel.font = [MDCTypography body1Font];
_phoneNumberLabel.textColor = [[MDCPalette greyPalette] tint900];
+
+ _emailLabel.font = [MDCTypography body1Font];
+ _emailLabel.textColor = [[MDCPalette greyPalette] tint900];
+
+ _notificationLabel.font = [MDCTypography body1Font];
+ _notificationLabel.textColor = [[MDCPalette cr_bluePalette] tint500];
}
// Set constraints on subviews.
- (void)setViewConstraints {
- UIView* contentView = self.contentView;
-
- [NSLayoutConstraint activateConstraints:@[
- // Set leading anchors.
- [_nameLabel.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor
- constant:kHorizontalPadding],
- [_addressLabel.leadingAnchor
- constraintEqualToAnchor:_nameLabel.leadingAnchor],
- [_phoneNumberLabel.leadingAnchor
- constraintEqualToAnchor:_addressLabel.leadingAnchor],
-
- // Set vertical anchors.
- [_nameLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor
- constant:kVerticalPadding],
- [_addressLabel.topAnchor
- constraintEqualToAnchor:_nameLabel.bottomAnchor
- constant:kVerticalSpacingBetweenLabels],
- [_addressLabel.bottomAnchor
- constraintEqualToAnchor:_phoneNumberLabel.topAnchor
- constant:-kVerticalSpacingBetweenLabels],
- [_phoneNumberLabel.bottomAnchor
- constraintEqualToAnchor:contentView.bottomAnchor
- constant:-kVerticalPadding],
-
- // Set trailing anchors.
- [_nameLabel.trailingAnchor
- constraintLessThanOrEqualToAnchor:contentView.trailingAnchor
- constant:-kHorizontalPadding],
- [_addressLabel.trailingAnchor
- constraintLessThanOrEqualToAnchor:_nameLabel.trailingAnchor],
- [_phoneNumberLabel.trailingAnchor
- constraintLessThanOrEqualToAnchor:_addressLabel.trailingAnchor],
- ]];
+ AddSameSizeConstraint(self.contentView, _stackView);
}
#pragma mark - UIView
@@ -142,6 +139,12 @@ const CGFloat kVerticalSpacingBetweenLabels = 8;
// Implement -layoutSubviews as per instructions in documentation for
// +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
- (void)layoutSubviews {
+ _nameLabel.hidden = !_nameLabel.text;
+ _addressLabel.hidden = !_addressLabel.text;
+ _phoneNumberLabel.hidden = !_phoneNumberLabel.text;
+ _emailLabel.hidden = !_emailLabel.text;
+ _notificationLabel.hidden = !_notificationLabel.text;
+
// When the accessory type is None, the content view of the cell (and thus)
// the labels inside it span larger than when there is a Checkmark accessory
// type. That means that toggling the accessory type can induce a rewrapping
@@ -154,13 +157,12 @@ const CGFloat kVerticalSpacingBetweenLabels = 8;
[super layoutSubviews];
- // Adjust labels' preferredMaxLayoutWidth when the parent's width changes, for
- // instance on screen rotation.
+ // Adjust preferredMaxLayoutWidth of _nameLabel and _addressLabel when the
+ // parent's width changes, for instance on screen rotation.
CGFloat parentWidth = CGRectGetWidth(self.contentView.frame);
CGFloat preferredMaxLayoutWidth = parentWidth - (2 * kHorizontalPadding);
_nameLabel.preferredMaxLayoutWidth = preferredMaxLayoutWidth;
_addressLabel.preferredMaxLayoutWidth = preferredMaxLayoutWidth;
- _phoneNumberLabel.preferredMaxLayoutWidth = preferredMaxLayoutWidth;
// Re-layout with the new preferred width to allow the label to adjust its
// height.
@@ -177,15 +179,18 @@ const CGFloat kVerticalSpacingBetweenLabels = 8;
self.nameLabel.text = nil;
self.addressLabel.text = nil;
self.phoneNumberLabel.text = nil;
+ self.emailLabel.text = nil;
+ self.notificationLabel.text = nil;
self.accessoryType = MDCCollectionViewCellAccessoryNone;
}
#pragma mark - NSObject(Accessibility)
- (NSString*)accessibilityLabel {
- return [NSString stringWithFormat:@"%@, %@, %@", self.nameLabel.text,
- self.addressLabel.text,
- self.phoneNumberLabel.text];
+ return [NSString
+ stringWithFormat:@"%@, %@, %@, %@, %@", self.nameLabel.text,
+ self.addressLabel.text, self.phoneNumberLabel.text,
+ self.emailLabel.text, self.notificationLabel.text];
}
@end

Powered by Google App Engine
This is Rietveld 408576698