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; ...@@ -139,15 +139,24 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
self.swipeRecognizer.enabled = NO; self.swipeRecognizer.enabled = NO;
[self.contentView addGestureRecognizer:self.swipeRecognizer]; [self.contentView addGestureRecognizer:self.swipeRecognizer];
BOOL isAccessibilityContentSize = auto GetAlertWidth = ^CGFloat(void) {
UIContentSizeCategoryIsAccessibilityCategory( BOOL isAccessibilityContentSize =
[UIApplication sharedApplication].preferredContentSizeCategory); UIContentSizeCategoryIsAccessibilityCategory(
const CGFloat alertWidth = [UIApplication sharedApplication].preferredContentSizeCategory);
isAccessibilityContentSize ? kAlertWidthAccessibilty : kAlertWidth; return isAccessibilityContentSize ? kAlertWidthAccessibilty : kAlertWidth;
};
NSLayoutConstraint* widthConstraint = NSLayoutConstraint* widthConstraint =
[self.contentView.widthAnchor constraintEqualToConstant:alertWidth]; [self.contentView.widthAnchor constraintEqualToConstant:GetAlertWidth()];
widthConstraint.priority = UILayoutPriorityRequired - 1; widthConstraint.priority = UILayoutPriorityRequired - 1;
[[NSNotificationCenter defaultCenter]
addObserverForName:UIContentSizeCategoryDidChangeNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* _Nonnull note) {
widthConstraint.constant = GetAlertWidth();
}];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
widthConstraint, widthConstraint,
...@@ -214,6 +223,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -214,6 +223,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
UILabel* titleLabel = [[UILabel alloc] init]; UILabel* titleLabel = [[UILabel alloc] init];
titleLabel.font = titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
titleLabel.adjustsFontForContentSizeCategory = YES;
titleLabel.textAlignment = NSTextAlignmentCenter; titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = self.title; titleLabel.text = self.title;
titleLabel.translatesAutoresizingMaskIntoConstraints = NO; titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
...@@ -232,6 +242,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -232,6 +242,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
messageLabel.numberOfLines = 0; messageLabel.numberOfLines = 0;
messageLabel.font = messageLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]; [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
messageLabel.adjustsFontForContentSizeCategory = YES;
messageLabel.textAlignment = NSTextAlignmentCenter; messageLabel.textAlignment = NSTextAlignmentCenter;
messageLabel.text = self.message; messageLabel.text = self.message;
messageLabel.translatesAutoresizingMaskIntoConstraints = NO; messageLabel.translatesAutoresizingMaskIntoConstraints = NO;
...@@ -315,6 +326,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -315,6 +326,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
textField.translatesAutoresizingMaskIntoConstraints = NO; textField.translatesAutoresizingMaskIntoConstraints = NO;
textField.delegate = self; textField.delegate = self;
textField.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; textField.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
textField.adjustsFontForContentSizeCategory = YES;
[fieldStack addArrangedSubview:textField]; [fieldStack addArrangedSubview:textField];
ChromeDirectionalEdgeInsets fieldInsets = ChromeDirectionalEdgeInsetsMake( ChromeDirectionalEdgeInsets fieldInsets = ChromeDirectionalEdgeInsetsMake(
...@@ -353,7 +365,9 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -353,7 +365,9 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
textColor = UIColorFromRGB(kButtonTextDestructiveColor); textColor = UIColorFromRGB(kButtonTextDestructiveColor);
} }
[button.titleLabel setFont:font]; button.titleLabel.font = font;
button.titleLabel.adjustsFontForContentSizeCategory = YES;
[button setTitleColor:textColor forState:UIControlStateNormal]; [button setTitleColor:textColor forState:UIControlStateNormal];
[button setTitle:action.title 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