Skip to content

Commit

Permalink
Update MDCAlertControllerView to more explicitly expose the differe…
Browse files Browse the repository at this point in the history
…ntiated `contentInsets` that are used in the `M3C` variation of the component.

PiperOrigin-RevId: 579938835
  • Loading branch information
jakerockland authored and material-automation committed Nov 6, 2023
1 parent 107548a commit 3d505b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 10 additions & 0 deletions components/Dialogs/src/MDCAlertControllerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@
*/
@property(nonatomic, assign) UIEdgeInsets contentInsets;

/**
The edge insets around the content view (which includes the message, and the accessory view if it
is set) against the dialog edges or its neighbor elements, the title and the actions.
In GM3, the bottom content inset is not needed due to the top action inset provding 24 spacing.
Default value is UIEdgeInsets(top: 24, leading: 24, bottom: 0, trailing: 24).
*/
@property(nonatomic, assign) UIEdgeInsets M3CDialogContentInsets;

/**
The edge insets around the actions against the dialog edges and its neighbor, which could be any of
the other elements: the message, accessory view, title, title icon or title icon view.
Expand Down
18 changes: 8 additions & 10 deletions components/Dialogs/src/private/MDCAlertControllerView+Private.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

static const CGFloat MDCDialogMessageOpacity = 0.54f;

static const UIEdgeInsets M3CDialogContentInsets = (UIEdgeInsets){24.0f, 24.0f, 0.0f, 24.0f};

/** KVO context for this file. */
static char *const kKVOContextMDCAlertControllerViewPrivate =
"kKVOContextMDCAlertControllerViewPrivate";
Expand Down Expand Up @@ -117,6 +115,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
self.titleInsets = UIEdgeInsetsMake(24.0f, 24.0f, 20.0f, 24.0f);
self.contentInsets = UIEdgeInsetsMake(24.0f, 24.0f, 24.0f, 24.0f);
self.actionsInsets = UIEdgeInsetsMake(8.0f, 8.0f, 8.0f, 8.0f);
self.M3CDialogContentInsets = UIEdgeInsetsMake(24.0f, 24.0f, 0.0f, 24.0f);
self.M3CButtonActionsInsets = UIEdgeInsetsMake(24.0f, 24.0f, 24.0f, 24.0f);
self.actionsHorizontalMargin = 8.0f;
self.M3CButtonActionsVerticalMargin = 8.0f;
Expand Down Expand Up @@ -178,6 +177,13 @@ - (instancetype)initWithFrame:(CGRect)frame {
return self;
}

- (UIEdgeInsets)contentInsets {
if (self.M3CButtonEnabled) {
return self.M3CDialogContentInsets;
}
return _contentInsets;
}

- (NSString *)title {
return self.titleLabel.text;
}
Expand All @@ -188,14 +194,6 @@ - (void)setTitle:(NSString *)title {
[self setNeedsLayout];
}

- (void)setM3CButtonEnabled:(BOOL)M3CButtonEnabled {
if (M3CButtonEnabled) {
// Bottom content inset is not needed due to the top action inset.
self.contentInsets = M3CDialogContentInsets;
}
_M3CButtonEnabled = M3CButtonEnabled;
}

- (void)setBackgroundColor:(UIColor *_Nullable)backgroundColor {
super.backgroundColor = backgroundColor;
self.titleView.backgroundColor = backgroundColor;
Expand Down

0 comments on commit 3d505b9

Please sign in to comment.