[Dialogs] Refactor title-icon, title-icon-view frames calculations to accommodate adjustable insets
diff --git a/components/Dialogs/src/private/MDCAlertControllerView+Private.m b/components/Dialogs/src/private/MDCAlertControllerView+Private.m
index 70c318d..58552c6 100644
--- a/components/Dialogs/src/private/MDCAlertControllerView+Private.m
+++ b/components/Dialogs/src/private/MDCAlertControllerView+Private.m
@@ -433,7 +433,11 @@
return size;
}
-- (BOOL)hasTitleIcon {
+- (BOOL)hasTitleIconOrImage {
+ return self.titleIconImageView.image.size.height > 0.f || self.titleIconView != nil;
+}
+
+- (BOOL)fixedLayoutHasTitleIcon {
return self.titleIconImageView.image.size.height > 0.f;
}
@@ -451,17 +455,17 @@
}
- (CGFloat)titleIconInsetBottom {
- return [self hasTitleIcon] && [self hasTitle] ? self.titleIconInsets.bottom : 0.0f;
+ return [self hasTitleIconOrImage] && [self hasTitle] ? self.titleIconInsets.bottom : 0.0f;
}
- (CGFloat)titleInsetTop {
- return [self hasTitleIcon] ? self.titleIconInsets.top : self.titleInsets.top;
+ return [self hasTitleIconOrImage] ? self.titleIconInsets.top : self.titleInsets.top;
}
- (CGFloat)titleInsetBottom {
if (![self hasMessage] && ![self hasAccessoryView]) {
return 0.0f;
- } else if ([self hasTitle] || [self hasTitleIcon]) {
+ } else if ([self hasTitle] || [self hasTitleIconOrImage]) {
return self.titleInsets.bottom;
} else {
return 0.0f;
@@ -469,30 +473,27 @@
}
- (CGFloat)accessoryVerticalInset {
- return [self hasMessage] && [self hasAccessoryView] ? self.accessoryViewVerticalInset : 0.f;
+ return ([self hasMessage] && [self hasAccessoryView]) ? self.accessoryViewVerticalInset : 0.f;
}
- (CGFloat)contentInternalVerticalPadding {
if (self.enableAdjustableInsets) {
return [self titleInsetBottom];
} else {
- return [self fixedInsetsContentInternalVerticalPadding];
+ return (([self hasTitle] || [self fixedLayoutHasTitleIcon]) && [self hasMessage])
+ ? MDCDialogContentVerticalPadding
+ : 0.0f;
}
}
-- (CGFloat)fixedInsetsContentInternalVerticalPadding {
- return (([self hasTitle] || [self hasTitleIcon]) && [self hasMessage])
- ? MDCDialogContentVerticalPadding
- : 0.0f;
-}
-
- (CGFloat)fixedInsetsContentTitleIconVerticalPadding {
- return ([self hasTitle] && [self hasTitleIcon]) ? MDCDialogTitleIconVerticalPadding : 0.0f;
+ return ([self hasTitle] && [self fixedLayoutHasTitleIcon]) ? MDCDialogTitleIconVerticalPadding
+ : 0.0f;
}
- (CGFloat)fixedInsetsContentAccessoryVerticalPaddingWithFittingSize:(CGSize)boundsSize {
CGSize accessoryViewSize = [self.accessoryView systemLayoutSizeFittingSize:boundsSize];
- return (([self hasTitle] || [self hasTitleIcon] || [self hasMessage]) &&
+ return (([self hasTitle] || [self fixedLayoutHasTitleIcon] || [self hasMessage]) &&
(0.0 < accessoryViewSize.height))
? MDCDialogContentVerticalPadding
: 0.0f;
@@ -531,20 +532,21 @@
- (CGRect)titleIconFrameWithTitleSize:(CGSize)titleSize {
CGSize titleIconViewSize = [self titleIconViewSize];
CGRect titleFrame = [self titleFrameWithTitleSize:titleSize];
+ UIEdgeInsets insets = self.enableAdjustableInsets ? self.titleIconInsets : MDCDialogContentInsets;
+
// match the titleIcon alignment to the title alignment
- CGFloat titleIconLeftPadding =
+ CGFloat leftInset =
self.enableAdjustableInsets ? self.titleInsets.left : MDCDialogContentInsets.left;
if (self.titleAlignment == NSTextAlignmentCenter) {
- titleIconLeftPadding =
+ leftInset =
CGRectGetMinX(titleFrame) + (CGRectGetWidth(titleFrame) - titleIconViewSize.width) / 2.0f;
} else if (self.titleAlignment == NSTextAlignmentRight ||
(self.titleAlignment == NSTextAlignmentNatural &&
[self mdf_effectiveUserInterfaceLayoutDirection] ==
UIUserInterfaceLayoutDirectionRightToLeft)) {
- titleIconLeftPadding = CGRectGetMaxX(titleFrame) - titleIconViewSize.width;
+ leftInset = CGRectGetMaxX(titleFrame) - titleIconViewSize.width;
}
- CGFloat top = (self.titleIconImageView != nil) ? MDCDialogContentInsets.top : 0.0f;
- return CGRectMake(titleIconLeftPadding, top, titleIconViewSize.width, titleIconViewSize.height);
+ return CGRectMake(leftInset, insets.top, titleIconViewSize.width, titleIconViewSize.height);
}
// @param boundsSize should not include any internal margins or padding