Commit 755d6f95 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Support Accessibility ContentSize on NTP header

This CL changes the header of the "Articles for you" section of the NTP
to have a better support for the "accessibility" categories of preferred
content size chosen by the user.

Bug: 893524
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I56ed6f89e7767697083c3e8e5d5a796db3066aee
Reviewed-on: https://chromium-review.googlesource.com/c/1273522
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599145}
parent c245af46
......@@ -70,6 +70,14 @@ const int kLabelColorRGB = 0x6D6D72;
#pragma mark - ContentSuggestionsArticlesHeaderCell
@interface ContentSuggestionsArticlesHeaderCell ()
@property(nonatomic, strong) NSArray<NSLayoutConstraint*>* standardConstraints;
@property(nonatomic, strong)
NSArray<NSLayoutConstraint*>* accessibilityConstraints;
@end
@implementation ContentSuggestionsArticlesHeaderCell
@synthesize button = _button;
......@@ -83,34 +91,62 @@ const int kLabelColorRGB = 0x6D6D72;
_label.translatesAutoresizingMaskIntoConstraints = NO;
_label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
_label.textColor = UIColorFromRGB(kLabelColorRGB, 1.0);
_label.adjustsFontForContentSizeCategory = YES;
_label.adjustsFontSizeToFitWidth = YES;
_button = [UIButton buttonWithType:UIButtonTypeSystem];
_button.translatesAutoresizingMaskIntoConstraints = NO;
_button.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
_button.titleLabel.adjustsFontForContentSizeCategory = YES;
[_button addTarget:self
action:@selector(buttonTapped)
forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_button];
[self.contentView addSubview:_label];
[NSLayoutConstraint activateConstraints:@[
[_label.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kTextMargin],
[_label.topAnchor constraintEqualToAnchor:self.contentView.topAnchor],
_standardConstraints = @[
[_label.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor],
[_button.topAnchor constraintEqualToAnchor:self.contentView.topAnchor],
[_label.trailingAnchor
constraintLessThanOrEqualToAnchor:_button.leadingAnchor],
[_button.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kTextMargin],
[_button.topAnchor constraintEqualToAnchor:self.contentView.topAnchor],
];
_accessibilityConstraints = @[
[_label.bottomAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
[_button.topAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
[_label.trailingAnchor
constraintLessThanOrEqualToAnchor:self.contentView.trailingAnchor
constant:-kTextMargin],
[_button.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kTextMargin],
[_button.trailingAnchor
constraintLessThanOrEqualToAnchor:self.contentView.trailingAnchor
constant:-kTextMargin],
];
[NSLayoutConstraint activateConstraints:@[
[_label.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kTextMargin],
[_label.topAnchor constraintEqualToAnchor:self.contentView.topAnchor],
[_button.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor],
[_label.trailingAnchor
constraintLessThanOrEqualToAnchor:_button.leadingAnchor]
]];
if (ContentSizeCategoryIsAccessibilityCategory(
self.traitCollection.preferredContentSizeCategory)) {
[NSLayoutConstraint activateConstraints:_accessibilityConstraints];
} else {
[NSLayoutConstraint activateConstraints:_standardConstraints];
}
}
return self;
}
......@@ -120,6 +156,27 @@ const int kLabelColorRGB = 0x6D6D72;
self.delegate = nil;
}
#pragma mark - UIView
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
BOOL isCurrentCategoryAccessibility =
ContentSizeCategoryIsAccessibilityCategory(
self.traitCollection.preferredContentSizeCategory);
BOOL isPreviousCategoryAccessibility =
ContentSizeCategoryIsAccessibilityCategory(
previousTraitCollection.preferredContentSizeCategory);
if (isCurrentCategoryAccessibility != isPreviousCategoryAccessibility) {
if (isCurrentCategoryAccessibility) {
[NSLayoutConstraint deactivateConstraints:self.standardConstraints];
[NSLayoutConstraint activateConstraints:self.accessibilityConstraints];
} else {
[NSLayoutConstraint deactivateConstraints:self.accessibilityConstraints];
[NSLayoutConstraint activateConstraints:self.standardConstraints];
}
}
}
#pragma mark Private
// Callback for the button action.
......
......@@ -439,9 +439,16 @@ const CGFloat kCardBorderRadius = 11;
if ([self.collectionUpdater isHeaderSection:section]) {
return CGSizeMake(0, [self.headerSynchronizer headerHeight]);
}
return [super collectionView:collectionView
layout:collectionViewLayout
referenceSizeForHeaderInSection:section];
CGSize defaultSize = [super collectionView:collectionView
layout:collectionViewLayout
referenceSizeForHeaderInSection:section];
if (ContentSizeCategoryIsAccessibilityCategory(
self.traitCollection.preferredContentSizeCategory) &&
[self.collectionUpdater isContentSuggestionsSection:section]) {
// Double the size of the header as it is now on two lines.
defaultSize.height *= 2;
}
return defaultSize;
}
- (BOOL)collectionView:(nonnull UICollectionView*)collectionView
......
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