Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 684937664
  • Loading branch information
codeman7 authored and material-automation committed Oct 11, 2024
1 parent 37654dc commit 55edb9a
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions components/Banner/src/MDCBannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

NS_ASSUME_NONNULL_BEGIN

static const NSInteger kTextNumberOfLineLimit = 0;
static const NSInteger kMinimumTextSizeForNextLine = 42;
static const NSInteger kMinimumCharactersLengthForNextLine = 10;
static const NSInteger kTextNumberOfLineLimit = 3;
static const CGFloat kImageViewSideLength = 40;
static const CGFloat kLeadingPadding = 16.0f;
static const CGFloat kTextTrailingPadding = 16.0f;
Expand All @@ -32,7 +30,6 @@
static const CGFloat kBottomPadding = 8.0f;
static const CGFloat kButtonHorizontalIntervalSpace = 8.0f;
static const CGFloat kButtonVerticalIntervalSpace = 8.0f;
static const CGFloat kButtonVerticalIntervalSpaceForLargeTextSize = 24.0f;
static const CGFloat kSpaceBetweenIconImageAndTextView = 16.0f;
static const CGFloat kHorizontalSpaceBetweenTextViewAndButton = 24.0f;
static const CGFloat kVerticalSpaceBetweenButtonAndTextView = 12.0f;
Expand Down Expand Up @@ -110,7 +107,6 @@ @interface MDCBannerView ()
@property(nonatomic, readwrite, strong) NSLayoutConstraint *trailingButtonConstraintTop;
@property(nonatomic, readwrite, strong) NSLayoutConstraint *trailingButtonConstraintTrailing;
@property(nonatomic, readwrite, strong) NSLayoutConstraint *trailingButtonConstraintHeightZero;
@property(nonatomic, readwrite, strong) NSLayoutConstraint *trailingButtonConstraintLeading;

@property(nonatomic, readwrite, strong) NSLayoutConstraint *dividerConstraintHeight;
@property(nonatomic, readwrite, strong) NSLayoutConstraint *dividerConstraintBottom;
Expand Down Expand Up @@ -172,6 +168,7 @@ - (void)commonBannerViewInit {
textView.textContainer.maximumNumberOfLines = kTextNumberOfLineLimit;
textView.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
textView.textContainer.lineFragmentPadding = 0;
textView.scrollEnabled = NO;
textView.editable = NO;
textView.textAlignment = NSTextAlignmentNatural;
textView.textContainerInset = UIEdgeInsetsZero;
Expand Down Expand Up @@ -381,9 +378,6 @@ - (void)setUpButtonsConstraints {
forAxis:UILayoutConstraintAxisHorizontal];
self.leadingButtonConstraintHeightZero =
[leadingButton.heightAnchor constraintEqualToConstant:0.f];
self.trailingButtonConstraintLeading =
[trailingButton.leadingAnchor constraintEqualToAnchor:self.buttonContainerView.leadingAnchor
constant:kButtonHorizontalIntervalSpace];
self.trailingButtonConstraintBottom =
[trailingButton.bottomAnchor constraintEqualToAnchor:self.buttonContainerView.bottomAnchor];
self.trailingButtonConstraintTop =
Expand Down Expand Up @@ -447,7 +441,6 @@ - (void)deactivateAllConstraints {
self.dividerConstraintHeight.active = NO;
self.dividerConstraintLeading.active = NO;
self.dividerConstraintWidth.active = NO;
self.trailingButtonConstraintLeading.active = NO;
}

#pragma mark - UIView overrides
Expand Down Expand Up @@ -624,36 +617,6 @@ - (void)updateButtonsConstraintsWithLayoutStyle:(MDCBannerViewLayoutStyle)layout
self.leadingButtonConstraintLeading.active = YES;
self.trailingButtonConstraintTrailing.active = YES;
self.trailingButtonConstraintBottom.active = YES;
self.trailingButtonConstraintLeading.active = YES;
[self adjustForDynamicText];
}
- (void)adjustForDynamicText {
UIButton *leadingButton = self.currentLeadingButton;
UIButton *trailingButton = self.currentTrailingButton;
leadingButton.titleLabel.numberOfLines = 0;
trailingButton.titleLabel.numberOfLines = 0;

CGSize leadingTextSize = [leadingButton.titleLabel intrinsicContentSize];
CGSize trailingTextSize = [trailingButton.titleLabel intrinsicContentSize];

CGFloat sumOfHeight = leadingTextSize.height + trailingTextSize.height;
CGFloat lengthOfLeadingButtonText = [leadingButton.titleLabel.text length];

if (leadingTextSize.height > kMinimumTextSizeForNextLine) {
sumOfHeight += kButtonVerticalIntervalSpaceForLargeTextSize;
}

if (sumOfHeight > kMinimumTextSizeForNextLine &&
lengthOfLeadingButtonText > kMinimumCharactersLengthForNextLine) {
self.textView.scrollEnabled = YES;
[NSLayoutConstraint activateConstraints:@[
[leadingButton.heightAnchor constraintEqualToConstant:sumOfHeight],
[trailingButton.heightAnchor constraintEqualToConstant:sumOfHeight],
]];
} else {
self.trailingButtonConstraintLeading.active = NO;
self.textView.scrollEnabled = NO;
}
}

- (MDCBannerViewLayoutStyle)layoutStyleForSizeToFit:(CGSize)sizeToFit {
Expand Down

0 comments on commit 55edb9a

Please sign in to comment.