Skip to content

Commit

Permalink
[Banner] Fix height when no action button shows. (#9218)
Browse files Browse the repository at this point in the history
closes https://github.com/material-components/material-components-ios/issues/9217.

`leadingButton`'s height shouldn't be taken into consideration when it is hidden.
  • Loading branch information
wenyuzhang666 committed Dec 10, 2019
1 parent b472663 commit 95c9b0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions components/Banner/src/MDCBannerView.m
Expand Up @@ -358,17 +358,22 @@ - (CGSize)sizeThatFits:(CGSize)size {
switch (layoutStyle) {
case MDCBannerViewLayoutStyleSingleRow: {
frameHeight += kTopPaddingSmall + kBottomPadding;
[self.leadingButton sizeToFit];
CGFloat buttonWidth = CGRectGetWidth(self.leadingButton.frame);
CGFloat widthLimit = contentSize.width;
widthLimit -= (buttonWidth + kHorizontalSpaceBetweenTextViewAndButton);
if (!self.leadingButton.hidden) {
[self.leadingButton sizeToFit];
CGFloat buttonWidth = CGRectGetWidth(self.leadingButton.frame);
widthLimit -= (buttonWidth + kHorizontalSpaceBetweenTextViewAndButton);
}
if (!self.imageView.hidden) {
widthLimit -= kImageViewSideLength;
widthLimit -= kSpaceBetweenIconImageAndTextView;
}
CGSize textViewSize = [self.textView sizeThatFits:CGSizeMake(widthLimit, CGFLOAT_MAX)];
CGSize leadingButtonSize = [self.leadingButton sizeThatFits:CGSizeZero];
CGFloat maximumHeight = MAX(textViewSize.height, leadingButtonSize.height);
CGFloat maximumHeight = textViewSize.height;
if (!self.leadingButton.hidden) {
CGSize leadingButtonSize = [self.leadingButton sizeThatFits:CGSizeZero];
maximumHeight = MAX(leadingButtonSize.height, maximumHeight);
}
if (!self.imageView.hidden) {
maximumHeight = MAX(kImageViewSideLength, maximumHeight);
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 95c9b0b

Please sign in to comment.