Add a minimum dialog width.
MODIFY
components/Dialogs/src/private/MDCAlertControllerView+Private.m
components/Dialogs/src/private/MDCAlertControllerView+Private.m
@@ -27,6 +27,7 @@ static const MDCFontTextStyle kMessageTextStyle = MDCFontTextStyleBody1;
static const MDCFontTextStyle kButtonTextStyle = MDCFontTextStyleButton;
static const CGFloat MDCDialogMaximumWidth = 560.0f;
+static const CGFloat MDCDialogMinimumWidth = 280.0f;
static const CGFloat MDCDialogActionButtonMinimumHeight = 36.0f;
static const CGFloat MDCDialogActionButtonMinimumWidth = 48.0f;
@@ -547,7 +548,7 @@ static const CGFloat MDCDialogMessageOpacity = 0.54f;
// @param boundsSize should not include any internal margins or padding
- (CGSize)calculatePreferredContentSizeForBounds:(CGSize)boundsSize {
// Even if we have more room, limit our maximum width
- boundsSize.width = MIN(boundsSize.width, MDCDialogMaximumWidth);
+ boundsSize.width = MIN(MAX(boundsSize.width, MDCDialogMinimumWidth), MDCDialogMaximumWidth);
// Title, Content & Actions
CGSize titleViewSize = [self calculateTitleViewSizeThatFitsWidth:boundsSize.width];
@@ -556,7 +557,8 @@ static const CGFloat MDCDialogMessageOpacity = 0.54f;
// Final Sizing
CGSize totalSize;
- totalSize.width = MAX(titleViewSize.width, MAX(contentSize.width, actionSize.width));
+ totalSize.width = MAX(MAX(titleViewSize.width, MAX(contentSize.width, actionSize.width)),
+ MDCDialogMinimumWidth);
totalSize.height = titleViewSize.height + contentSize.height + actionSize.height;
return totalSize;

MODIFY
components/Dialogs/tests/snapshot/MDCAlertControllerConfigurationsTests.m
components/Dialogs/tests/snapshot/MDCAlertControllerConfigurationsTests.m
#import "MaterialContainerScheme.h"
static NSString *const kTitleShortLatin = @"Title";
+static NSString *const kTitleLongLatin =
+ @"It's a long long long long long long long long long long long long long long long long long "
+ "long long long title";
static NSString *const kMessageShortLatin = @"A short message.";
static NSString *const kMessageLongLatin =
@"Lorem ipsum dolor sit amet, consul docendi indoctum id quo, ad unum suavitate incorrupte "
"sea. An his meis consul cotidieque, eam recteque mnesarchum et, mundi volumus cu cum. Quo "
"falli dicunt an. Praesent molestiae vim ut.";
+static NSString *const kMessageVeryLongLatin =
+ @"Lorem ipsum dolor sit amet, consul docendi indoctum id quo, ad unum suavitate incorrupte "
+ "sea. An his meis consul cotidieque, eam recteque mnesarchum et, mundi volumus cu cum. Quo "
+ "falli dicunt an. Praesent molestiae vim ut. Lorem ipsum dolor sit amet, consul docendi "
+ "indoctum id quo, ad unum suavitate incorrupte sea. An his meis consul cotidieque, eam "
+ "recteque mnesarchum et, mundi volumus cu cum. Quo falli dicunt an. Praesent molestiae vim "
+ "ut. Lorem ipsum dolor sit amet, consul docendi indoctum id quo, ad unum suavitate incorrupte "
+ "sea. An his meis consul cotidieque, eam recteque mnesarchum et, mundi volumus cu cum. Quo "
+ "falli dicunt an. Praesent molestiae vim ut. Lorem ipsum dolor sit amet, consul docendi "
+ "indoctum id quo, ad unum suavitate incorrupte sea. An his meis consul cotidieque, eam "
+ "recteque mnesarchum et, mundi volumus cu cum. Quo falli dicunt an. Praesent molestiae vim "
+ "ut. Lorem ipsum dolor sit amet, consul docendi indoctum id quo, ad unum suavitate incorrupte "
+ "sea. An his meis consul cotidieque, eam recteque mnesarchum et, mundi volumus cu cum. Quo "
+ "falli dicunt an. Praesent molestiae vim ut. Lorem ipsum dolor sit amet, consul docendi "
+ "indoctum id quo, ad unum suavitate incorrupte sea. An his meis consul cotidieque, eam "
+ "recteque mnesarchum et, mundi volumus cu cum. Quo falli dicunt an. Praesent molestiae vim "
+ "ut.";
+
@interface MDCAlertControllerConfigurationsTests : MDCSnapshotTestCase
@property(nonatomic, strong) MDCAlertController *alertController;
@property(nonatomic, strong) MDCContainerScheme *containerScheme2019;
@@ -935,4 +956,37 @@ static NSString *const kMessageLongLatin =
[self generateHighlightedSnapshotAndVerifyForAlert:self.alertController];
}
+// Min title
+- (void)testMinSizeDialog {
+ // Given
+ [self addOutlinedActionWithTitle:@"Cancel"];
+ self.alertController.title = @"A";
+
+ // When
+ [self.alertController applyThemeWithScheme:self.containerScheme2019];
+
+ // Then
+ self.alertController.view.bounds = CGRectMake(0.f, 0.f, 100.f, 100.f);
+ [self.alertController.view layoutIfNeeded];
+ [self sizeAlertToFitContent];
+ [self generateSizedSnapshotAndVerifyForView:self.alertController.view];
+}
+
+// Max size message
+- (void)testMaxSizeDialog {
+ // Given
+ [self addOutlinedActionWithTitle:@"Cancel"];
+ self.alertController.title = kTitleLongLatin;
+ self.alertController.message = kMessageVeryLongLatin;
+
+ // When
+ [self.alertController applyThemeWithScheme:self.containerScheme2019];
+
+ // Then
+ self.alertController.view.bounds = CGRectMake(0.f, 0.f, 1000.f, 1000.f);
+ [self.alertController.view layoutIfNeeded];
+ [self sizeAlertToFitContent];
+ [self generateSizedSnapshotAndVerifyForView:self.alertController.view];
+}
+
@end

Add a minimum dialog width.

PiperOrigin-RevId: 304494482