Commit 643f282c authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][Alert] Supports real time dynamic type

Updates the constraints related to dynamic type when the content size
category changes.
Sets all labels and text fields to automatically adjust fot the content
size category.

Bug: 959764, 951300
Change-Id: Ib072e40ef1821e20941740e07f194e5a17ccecdc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1611604
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Auto-Submit: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659962}
parent 017c9bbf
......@@ -139,15 +139,24 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
self.swipeRecognizer.enabled = NO;
[self.contentView addGestureRecognizer:self.swipeRecognizer];
BOOL isAccessibilityContentSize =
UIContentSizeCategoryIsAccessibilityCategory(
[UIApplication sharedApplication].preferredContentSizeCategory);
const CGFloat alertWidth =
isAccessibilityContentSize ? kAlertWidthAccessibilty : kAlertWidth;
auto GetAlertWidth = ^CGFloat(void) {
BOOL isAccessibilityContentSize =
UIContentSizeCategoryIsAccessibilityCategory(
[UIApplication sharedApplication].preferredContentSizeCategory);
return isAccessibilityContentSize ? kAlertWidthAccessibilty : kAlertWidth;
};
NSLayoutConstraint* widthConstraint =
[self.contentView.widthAnchor constraintEqualToConstant:alertWidth];
[self.contentView.widthAnchor constraintEqualToConstant:GetAlertWidth()];
widthConstraint.priority = UILayoutPriorityRequired - 1;
[[NSNotificationCenter defaultCenter]
addObserverForName:UIContentSizeCategoryDidChangeNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* _Nonnull note) {
widthConstraint.constant = GetAlertWidth();
}];
[NSLayoutConstraint activateConstraints:@[
widthConstraint,
......@@ -214,6 +223,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
UILabel* titleLabel = [[UILabel alloc] init];
titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
titleLabel.adjustsFontForContentSizeCategory = YES;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = self.title;
titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
......@@ -232,6 +242,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
messageLabel.numberOfLines = 0;
messageLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
messageLabel.adjustsFontForContentSizeCategory = YES;
messageLabel.textAlignment = NSTextAlignmentCenter;
messageLabel.text = self.message;
messageLabel.translatesAutoresizingMaskIntoConstraints = NO;
......@@ -315,6 +326,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
textField.translatesAutoresizingMaskIntoConstraints = NO;
textField.delegate = self;
textField.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
textField.adjustsFontForContentSizeCategory = YES;
[fieldStack addArrangedSubview:textField];
ChromeDirectionalEdgeInsets fieldInsets = ChromeDirectionalEdgeInsetsMake(
......@@ -353,7 +365,9 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
textColor = UIColorFromRGB(kButtonTextDestructiveColor);
}
[button.titleLabel setFont:font];
button.titleLabel.font = font;
button.titleLabel.adjustsFontForContentSizeCategory = YES;
[button setTitleColor:textColor forState:UIControlStateNormal];
[button setTitle:action.title forState:UIControlStateNormal];
......
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