Commit 5b2ab789 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Add accessibility for IdentityPicker

This CL adds dynamic for the IdentityPicker, making sure that the name
and email can spread on multiple lines and respond nicely when the font
is increased.

Bug: 872277
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Iea05b977c7a6f6fe199c0e8d4e6325ac05936ef0
Reviewed-on: https://chromium-review.googlesource.com/1172423Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582588}
parent 335bd11f
......@@ -12,7 +12,7 @@ const CGFloat kAuthenticationHeaderImageHeight = 88.;
const CGFloat kAuthenticationHeaderImageWidth = 360.;
const UIFontTextStyle kAuthenticationTitleFontStyle = UIFontTextStyleTitle2;
const UIFontTextStyle kAuthenticationTextFontStyle = UIFontTextStyleCaption1;
const UIFontTextStyle kAuthenticationTextFontStyle = UIFontTextStyleFootnote;
const int kAuthenticationHeaderBackgroundColor = 0xf8f9fa;
const CGFloat kAuthenticationHorizontalMargin = 16.;
......
......@@ -14,11 +14,10 @@
namespace {
// Top margin for the label.
CGFloat kTopMargin = 24.;
CGFloat kTopMargin = 20.;
CGFloat kBottomMargin = 15;
// Leading margin for the label.
CGFloat kLeadingMargin = 24.;
// Label font size.
CGFloat kTitleFontSize = 14.;
// Label font color alpha.
CGFloat kFontAlpha = .87;
} // namespace
......@@ -35,7 +34,7 @@ CGFloat kFontAlpha = .87;
label.translatesAutoresizingMaskIntoConstraints = NO;
label.text =
l10n_util::GetNSString(IDS_IOS_ACCOUNT_IDENTITY_CHOOSER_CHOOSE_ACCOUNT);
label.font = [UIFont boldSystemFontOfSize:kTitleFontSize];
label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
label.textColor = [UIColor colorWithWhite:0. alpha:kFontAlpha];
[self.contentView addSubview:label];
NSDictionary* views = @{
......@@ -44,12 +43,13 @@ CGFloat kFontAlpha = .87;
NSDictionary* metrics = @{
@"LeadingMargin" : @(kLeadingMargin),
@"TopMargin" : @(kTopMargin),
@"BottomMargin" : @(kBottomMargin),
};
NSArray* constraints = @[
// Horitizontal constraints.
@"H:|-(LeadingMargin)-[label]-(>=0)-|",
// Vertical constraints.
@"V:|-(TopMargin)-[label]",
@"V:|-(TopMargin)-[label]-(BottomMargin)-|",
];
ApplyVisualConstraintsWithMetrics(constraints, views, metrics);
......
......@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_header_item.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_item.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_view_controller.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
#include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h"
......
......@@ -38,7 +38,7 @@ const CGFloat kFooterHeight = 17.;
self.tableView.sectionFooterHeight = 0;
// Setting -UITableView.rowHeight is required for iOS 10. On iOS 11, the row
// height is automatically set.
self.tableView.rowHeight = kRowHeight;
self.tableView.estimatedRowHeight = kRowHeight;
}
- (void)viewDidDisappear:(BOOL)animated {
......
......@@ -16,10 +16,8 @@ namespace {
// Sizes.
const CGFloat kAvatarSize = 40.;
const CGFloat kTitleFontSize = 14.;
const CGFloat kSubtitleFontSize = 12.;
// Distances/margins.
const CGFloat kTitleOffset = 2;
const CGFloat kTitleOffset = 4;
const CGFloat kHorizontalAvatarMargin = 16.;
const CGFloat kVerticalMargin = 12.;
// Colors
......@@ -66,22 +64,28 @@ const CGFloat kSubtitleTextColorAlpha = .54;
// Title.
_title = [[UILabel alloc] init];
_title.translatesAutoresizingMaskIntoConstraints = NO;
_title.numberOfLines = 0;
_title.textColor = [UIColor colorWithWhite:0 alpha:kTitleTextColorAlpha];
_title.font = [UIFont systemFontOfSize:kTitleFontSize];
_title.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
[self addSubview:_title];
// Subtitle.
_subtitle = [[UILabel alloc] init];
_subtitle.translatesAutoresizingMaskIntoConstraints = NO;
_subtitle.numberOfLines = 0;
_subtitle.textColor =
[UIColor colorWithWhite:0 alpha:kSubtitleTextColorAlpha];
_subtitle.font = [UIFont systemFontOfSize:kSubtitleFontSize];
_subtitle.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
[self addSubview:_subtitle];
// Text container.
UILayoutGuide* textContainerGuide = [[UILayoutGuide alloc] init];
[self addLayoutGuide:textContainerGuide];
// Layout constraints.
NSDictionary* views = @{
@"avatar" : _avatarView,
@"title" : _title,
@"container" : textContainerGuide,
@"subtitle" : _subtitle,
};
NSDictionary* metrics = @{
......@@ -91,7 +95,7 @@ const CGFloat kSubtitleTextColorAlpha = .54;
};
NSArray* constraints = @[
// Horizontal constraints.
@"H:|-(HAvatarMargin)-[avatar]-(HAvatarMargin)-[title]|",
@"H:|-(HAvatarMargin)-[avatar]-(HAvatarMargin)-[container]|",
// Vertical constraints.
// Size constraints.
@"H:[avatar(AvatarSize)]",
......@@ -102,22 +106,39 @@ const CGFloat kSubtitleTextColorAlpha = .54;
AddSameConstraintsToSides(_title, _subtitle,
LayoutSides::kLeading | LayoutSides::kTrailing);
_titleConstraintForNameAndEmail =
[self.centerYAnchor constraintEqualToAnchor:_title.bottomAnchor
constant:kTitleOffset];
_titleConstraintForEmailOnly =
[self.centerYAnchor constraintEqualToAnchor:_title.centerYAnchor];
[self.centerYAnchor constraintEqualToAnchor:_subtitle.topAnchor
constant:-kTitleOffset]
.active = YES;
[_subtitle.topAnchor constraintEqualToAnchor:_title.bottomAnchor
constant:kTitleOffset];
_titleConstraintForEmailOnly = [textContainerGuide.bottomAnchor
constraintEqualToAnchor:_title.bottomAnchor];
[NSLayoutConstraint activateConstraints:@[
[self.centerYAnchor
constraintEqualToAnchor:textContainerGuide.centerYAnchor],
[textContainerGuide.leadingAnchor
constraintEqualToAnchor:_title.leadingAnchor],
[textContainerGuide.leadingAnchor
constraintEqualToAnchor:_subtitle.leadingAnchor],
[textContainerGuide.trailingAnchor
constraintEqualToAnchor:_title.trailingAnchor],
[textContainerGuide.trailingAnchor
constraintEqualToAnchor:_subtitle.trailingAnchor],
[textContainerGuide.topAnchor constraintEqualToAnchor:_title.topAnchor],
[textContainerGuide.bottomAnchor
constraintEqualToAnchor:_subtitle.bottomAnchor],
]];
_verticalConstraints = @[
[_avatarView.topAnchor constraintEqualToAnchor:self.topAnchor
constant:kVerticalMargin],
[self.bottomAnchor constraintEqualToAnchor:_avatarView.bottomAnchor
constant:kVerticalMargin],
[_title.topAnchor constraintGreaterThanOrEqualToAnchor:self.topAnchor
constant:kVerticalMargin],
[_avatarView.topAnchor
constraintGreaterThanOrEqualToAnchor:self.topAnchor
constant:kVerticalMargin],
[self.bottomAnchor
constraintGreaterThanOrEqualToAnchor:_avatarView.bottomAnchor
constant:kVerticalMargin],
[textContainerGuide.topAnchor
constraintGreaterThanOrEqualToAnchor:self.topAnchor
constant:kVerticalMargin],
[self.bottomAnchor
constraintGreaterThanOrEqualToAnchor:_subtitle.bottomAnchor
constraintGreaterThanOrEqualToAnchor:textContainerGuide.bottomAnchor
constant:kVerticalMargin],
];
[NSLayoutConstraint activateConstraints:_verticalConstraints];
......
......@@ -125,10 +125,12 @@ NSString* const kSyncCompleteIconName = @"ic_sync_complete";
}
- (void)scrollToBottom {
// Add one point to make sure that it is actually scrolled to the bottom (as
// there are some issues when the fonts are increased).
CGPoint bottomOffset =
CGPointMake(0, self.scrollView.contentSize.height -
self.scrollView.bounds.size.height +
self.scrollView.contentInset.bottom);
self.scrollView.contentInset.bottom + 1);
[self.scrollView setContentOffset:bottomOffset animated:YES];
}
......
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