Skip to content

Commit

Permalink
Added a fixed vertical margin between chips for large and small fonts:
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 679056065
  • Loading branch information
Nobody authored and material-automation committed Sep 26, 2024
1 parent 8c0ddb0 commit f692bd8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions components/Chips/src/MDCChipField.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,25 @@ - (void)layoutSubviews {
- (CGFloat)getChipHeight {
if (self.adjustChipHeightForTextSize) {
CGFloat chipDynamicHeight = self.textField.font.lineHeight;
return _chipHeight > chipDynamicHeight ? _chipHeight : chipDynamicHeight + 5;
return _chipHeight > chipDynamicHeight ? _chipHeight : chipDynamicHeight;
} else {
return _chipHeight;
}
}

- (CGFloat)getChipYCoordinateForHeight:(CGFloat)chipFullHeight row:(NSUInteger)row {
if (self.adjustChipHeightForTextSize) {
// Smaller chip heights need more vertical padding to accommodate a touch target size of at
// least 44. At larger text sizes, the padding can shrink to reduce wasted space.
return chipFullHeight >= 36
? self.contentEdgeInsets.top + (row * (chipFullHeight + MDCChipFieldVerticalMargin))
: self.contentEdgeInsets.top +
(row * (chipFullHeight + MDCChipFieldVerticalMargin + 4));
} else {
return self.contentEdgeInsets.top + (row * (_chipHeight + MDCChipFieldVerticalMargin));
}
}

- (void)updateTextFieldPlaceholderText {
// There should be no placeholder if showPlaceholderWithChips is NO and there are chips.
if (!self.showPlaceholderWithChips && self.chips.count > 0) {
Expand Down Expand Up @@ -708,8 +721,7 @@ - (BOOL)isTextFieldEmpty {
row++;
currentOriginX = self.contentEdgeInsets.left;
}
CGFloat currentOriginY =
self.contentEdgeInsets.top + (row * ([self getChipHeight] + MDCChipFieldVerticalMargin));
CGFloat currentOriginY = [self getChipYCoordinateForHeight:chipSize.height row:(row)];
CGRect chipFrame = CGRectMake(currentOriginX, currentOriginY, chipSize.width, chipSize.height);
[chipFrames addObject:[NSValue valueWithCGRect:chipFrame]];
currentOriginX = CGRectGetMaxX(chipFrame) + MDCChipFieldHorizontalMargin;
Expand Down

0 comments on commit f692bd8

Please sign in to comment.