Commit 0195ac20 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Add DynamicType to AutofillEditItem

This CL adds support for Dynamic Type in the AutofillEditItem.

Bug: 894791
Change-Id: I1e25084fed4cb176b332fc7fa7e4af0e7957323c
Reviewed-on: https://chromium-review.googlesource.com/c/1346454
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611675}
parent 22d620d8
...@@ -24,6 +24,7 @@ source_set("cells") { ...@@ -24,6 +24,7 @@ source_set("cells") {
"//ios/chrome/browser/ui/autofill:autofill_ui", "//ios/chrome/browser/ui/autofill:autofill_ui",
"//ios/chrome/browser/ui/collection_view/cells", "//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/colors", "//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/table_view:styler",
"//ios/chrome/browser/ui/table_view/cells", "//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/common/ui_util", "//ios/chrome/common/ui_util",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/browser/ui/util/rtl_geometry.h" #import "ios/chrome/browser/ui/util/rtl_geometry.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h" #import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h" #import "ios/chrome/common/ui_util/constraints_ui_util.h"
...@@ -45,6 +46,13 @@ const CGFloat kLabelAndFieldGap = 5; ...@@ -45,6 +46,13 @@ const CGFloat kLabelAndFieldGap = 5;
cell.textField.accessibilityIdentifier = cell.textField.accessibilityIdentifier =
[NSString stringWithFormat:@"%@_textField", self.textFieldName]; [NSString stringWithFormat:@"%@_textField", self.textFieldName];
} }
if (styler.cellBackgroundColor) {
cell.textLabel.backgroundColor = styler.cellBackgroundColor;
cell.textField.backgroundColor = styler.cellBackgroundColor;
} else {
cell.textLabel.backgroundColor = styler.tableViewBackgroundColor;
cell.textField.backgroundColor = styler.tableViewBackgroundColor;
}
cell.textField.enabled = self.textFieldEnabled; cell.textField.enabled = self.textFieldEnabled;
cell.textField.textColor = cell.textField.textColor =
self.textFieldEnabled self.textFieldEnabled
...@@ -75,6 +83,15 @@ const CGFloat kLabelAndFieldGap = 5; ...@@ -75,6 +83,15 @@ const CGFloat kLabelAndFieldGap = 5;
@property(nonatomic, strong) NSLayoutConstraint* iconHeightConstraint; @property(nonatomic, strong) NSLayoutConstraint* iconHeightConstraint;
@property(nonatomic, strong) NSLayoutConstraint* iconWidthConstraint; @property(nonatomic, strong) NSLayoutConstraint* iconWidthConstraint;
@property(nonatomic, strong) NSLayoutConstraint* textFieldTrailingConstraint; @property(nonatomic, strong) NSLayoutConstraint* textFieldTrailingConstraint;
@property(nonatomic, strong) NSLayoutConstraint* textLabelTrailingConstraint;
// When they are activated, the label and the text field are on one line.
// They conflict with the |accessibilityConstraints|.
@property(nonatomic, strong) NSArray<NSLayoutConstraint*>* standardConstraints;
// When they are activated, the label is on one line, the text field is on
// another line. They conflict with the |standardConstraints|.
@property(nonatomic, strong)
NSArray<NSLayoutConstraint*>* accessibilityConstraints;
// UIImageView containing the icon identifying |textField| or its current value. // UIImageView containing the icon identifying |textField| or its current value.
@property(nonatomic, readonly, strong) UIImageView* identifyingIconView; @property(nonatomic, readonly, strong) UIImageView* identifyingIconView;
...@@ -96,18 +113,24 @@ const CGFloat kLabelAndFieldGap = 5; ...@@ -96,18 +113,24 @@ const CGFloat kLabelAndFieldGap = 5;
_textLabel.translatesAutoresizingMaskIntoConstraints = NO; _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
[_textLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh [_textLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal]; forAxis:UILayoutConstraintAxisHorizontal];
_textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
_textLabel.adjustsFontForContentSizeCategory = YES;
[contentView addSubview:_textLabel]; [contentView addSubview:_textLabel];
_textField = [[UITextField alloc] init]; _textField = [[UITextField alloc] init];
_textField.translatesAutoresizingMaskIntoConstraints = NO; _textField.translatesAutoresizingMaskIntoConstraints = NO;
_textField.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
_textField.adjustsFontForContentSizeCategory = YES;
[_textField
setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
forAxis:
UILayoutConstraintAxisHorizontal];
[contentView addSubview:_textField]; [contentView addSubview:_textField];
_textField.autocorrectionType = UITextAutocorrectionTypeNo; _textField.autocorrectionType = UITextAutocorrectionTypeNo;
_textField.clearButtonMode = UITextFieldViewModeWhileEditing; _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
_textField.contentVerticalAlignment = _textField.contentVerticalAlignment =
UIControlContentVerticalAlignmentCenter; UIControlContentVerticalAlignmentCenter;
_textField.textAlignment =
UseRTLLayout() ? NSTextAlignmentLeft : NSTextAlignmentRight;
// Card type icon. // Card type icon.
_identifyingIconView = [[UIImageView alloc] initWithFrame:CGRectZero]; _identifyingIconView = [[UIImageView alloc] initWithFrame:CGRectZero];
...@@ -123,6 +146,25 @@ const CGFloat kLabelAndFieldGap = 5; ...@@ -123,6 +146,25 @@ const CGFloat kLabelAndFieldGap = 5;
_textFieldTrailingConstraint = [_textField.trailingAnchor _textFieldTrailingConstraint = [_textField.trailingAnchor
constraintEqualToAnchor:_identifyingIconView.leadingAnchor]; constraintEqualToAnchor:_identifyingIconView.leadingAnchor];
_textLabelTrailingConstraint = [_textLabel.trailingAnchor
constraintEqualToAnchor:_identifyingIconView.leadingAnchor];
_standardConstraints = @[
[_textField.firstBaselineAnchor
constraintEqualToAnchor:_textLabel.firstBaselineAnchor],
[_textField.leadingAnchor
constraintEqualToAnchor:_textLabel.trailingAnchor
constant:kLabelAndFieldGap],
];
_accessibilityConstraints = @[
[_textField.topAnchor constraintEqualToAnchor:_textLabel.bottomAnchor
constant:kTableViewVerticalSpacing],
[_textField.leadingAnchor
constraintEqualToAnchor:contentView.leadingAnchor
constant:kTableViewHorizontalSpacing],
_textLabelTrailingConstraint,
];
// Set up the constraints. // Set up the constraints.
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
...@@ -130,11 +172,6 @@ const CGFloat kLabelAndFieldGap = 5; ...@@ -130,11 +172,6 @@ const CGFloat kLabelAndFieldGap = 5;
constraintEqualToAnchor:contentView.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor
constant:kTableViewHorizontalSpacing], constant:kTableViewHorizontalSpacing],
_textFieldTrailingConstraint, _textFieldTrailingConstraint,
[_textField.firstBaselineAnchor
constraintEqualToAnchor:_textLabel.firstBaselineAnchor],
[_textField.leadingAnchor
constraintEqualToAnchor:_textLabel.trailingAnchor
constant:kLabelAndFieldGap],
[_identifyingIconView.trailingAnchor [_identifyingIconView.trailingAnchor
constraintEqualToAnchor:contentView.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor
constant:-kTableViewHorizontalSpacing], constant:-kTableViewHorizontalSpacing],
...@@ -145,6 +182,12 @@ const CGFloat kLabelAndFieldGap = 5; ...@@ -145,6 +182,12 @@ const CGFloat kLabelAndFieldGap = 5;
]]; ]];
AddOptionalVerticalPadding(contentView, _textLabel, AddOptionalVerticalPadding(contentView, _textLabel,
kTableViewLargeVerticalSpacing); kTableViewLargeVerticalSpacing);
AddOptionalVerticalPadding(contentView, _textField,
kTableViewLargeVerticalSpacing);
[self updateForAccessibilityContentSizeCategory:
UIContentSizeCategoryIsAccessibilityCategory(
self.traitCollection.preferredContentSizeCategory)];
} }
return self; return self;
} }
...@@ -155,17 +198,32 @@ const CGFloat kLabelAndFieldGap = 5; ...@@ -155,17 +198,32 @@ const CGFloat kLabelAndFieldGap = 5;
self.identifyingIconView.image = icon; self.identifyingIconView.image = icon;
if (icon) { if (icon) {
self.textFieldTrailingConstraint.constant = -kLabelAndFieldGap; self.textFieldTrailingConstraint.constant = -kLabelAndFieldGap;
self.textLabelTrailingConstraint.constant = -kLabelAndFieldGap;
// Set the size constraints of the icon view to the dimensions of the image. // Set the size constraints of the icon view to the dimensions of the image.
self.iconHeightConstraint.constant = icon.size.height; self.iconHeightConstraint.constant = icon.size.height;
self.iconWidthConstraint.constant = icon.size.width; self.iconWidthConstraint.constant = icon.size.width;
} else { } else {
self.textFieldTrailingConstraint.constant = 0; self.textFieldTrailingConstraint.constant = 0;
self.textLabelTrailingConstraint.constant = 0;
self.iconHeightConstraint.constant = 0; self.iconHeightConstraint.constant = 0;
self.iconWidthConstraint.constant = 0; self.iconWidthConstraint.constant = 0;
} }
} }
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
BOOL isCurrentCategoryAccessibility =
UIContentSizeCategoryIsAccessibilityCategory(
self.traitCollection.preferredContentSizeCategory);
if (isCurrentCategoryAccessibility !=
UIContentSizeCategoryIsAccessibilityCategory(
previousTraitCollection.preferredContentSizeCategory)) {
[self updateForAccessibilityContentSizeCategory:
isCurrentCategoryAccessibility];
}
}
#pragma mark UITableViewCell #pragma mark UITableViewCell
- (void)prepareForReuse { - (void)prepareForReuse {
...@@ -193,4 +251,24 @@ const CGFloat kLabelAndFieldGap = 5; ...@@ -193,4 +251,24 @@ const CGFloat kLabelAndFieldGap = 5;
stringWithFormat:@"%@, %@", self.textLabel.text, self.textField.text]; stringWithFormat:@"%@, %@", self.textLabel.text, self.textField.text];
} }
#pragma mark Private
// Updates the cell such as it is layouted correctly with regard to the
// preferred content size category, if it is an
// |accessibilityContentSizeCategory| or not.
- (void)updateForAccessibilityContentSizeCategory:
(BOOL)accessibilityContentSizeCategory {
if (accessibilityContentSizeCategory) {
[NSLayoutConstraint deactivateConstraints:_standardConstraints];
[NSLayoutConstraint activateConstraints:_accessibilityConstraints];
_textField.textAlignment =
UseRTLLayout() ? NSTextAlignmentRight : NSTextAlignmentLeft;
} else {
[NSLayoutConstraint deactivateConstraints:_accessibilityConstraints];
[NSLayoutConstraint activateConstraints:_standardConstraints];
_textField.textAlignment =
UseRTLLayout() ? NSTextAlignmentLeft : NSTextAlignmentRight;
}
}
@end @end
...@@ -177,6 +177,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -177,6 +177,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
[[AutofillEditItem alloc] initWithType:ItemTypeAutofillEditItem]; [[AutofillEditItem alloc] initWithType:ItemTypeAutofillEditItem];
autofillEditItem.textFieldName = @"Autofill field"; autofillEditItem.textFieldName = @"Autofill field";
autofillEditItem.textFieldValue = @" with a value"; autofillEditItem.textFieldValue = @" with a value";
autofillEditItem.identifyingIcon =
[UIImage imageNamed:@"table_view_cell_check_mark"];
[model addItem:autofillEditItem [model addItem:autofillEditItem
toSectionWithIdentifier:SectionIdentifierAutofill]; toSectionWithIdentifier:SectionIdentifierAutofill];
......
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