Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit 7c19c19

Browse files
Nobodymaterial-automation
authored andcommitted
Add imageViewSize property to MDCChipView.
PiperOrigin-RevId: 750667661
1 parent fff6a96 commit 7c19c19

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

components/Chips/src/MDCChipView.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,16 @@ When @c centerVisibleArea is @c NO, this value is @c UIEdgeInsetsZero.
162162
@property(nonatomic, readonly) UIEdgeInsets visibleAreaInsets;
163163

164164
/**
165-
A block that is invoked when the MDCChipView receives a call to @c
165+
The size of the image of the Chip.
166+
167+
If this property is set to a size other than @c CGSizeZero, the chip will use this size for its
168+
image. If this property is set to @c CGSizeZero, the chip will use the image's default size.
169+
170+
The default value is CGSizeZero.
171+
*/
172+
@property(nonatomic, assign) CGSize imageViewSize;
173+
174+
/**
166175
traitCollectionDidChange:. The block is called after the call to the superclass.
167176
*/
168177
@property(nonatomic, copy, nullable) void (^traitCollectionDidChangeBlock)

components/Chips/src/MDCChipView.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ - (void)commonMDCChipViewInit {
169169
_minimumSize = kMDCChipMinimumSizeDefault;
170170
self.isAccessibilityElement = YES;
171171
self.accessibilityTraits = UIAccessibilityTraitButton;
172+
self.imageViewSize = CGSizeZero;
172173
_mdc_overrideBaseElevation = -1;
173174
_currentElevation = 0;
174175
if (gEnablePerformantShadow) {
@@ -958,7 +959,9 @@ - (CGRect)frameForImageView:(UIImageView *)imageView visible:(BOOL)visible {
958959
CGRect contentRect = self.contentRect;
959960
CGRect frame = CGRectMake(CGRectGetMinX(contentRect), CGRectGetMidY(contentRect), 0, 0);
960961
if (visible) {
961-
CGSize selectedSize = [self sizeForImageView:imageView maxSize:contentRect.size];
962+
CGSize selectedSize = CGSizeEqualToSize(self.imageViewSize, CGSizeZero)
963+
? [self sizeForImageView:imageView maxSize:contentRect.size]
964+
: self.imageViewSize;
962965
frame = MDCChipBuildFrame(_imagePadding, selectedSize,
963966
CGPointMake(CGRectGetMinX(contentRect), CGRectGetMinY(contentRect)),
964967
CGRectGetHeight(contentRect), self.pixelScale);

components/Chips/tests/unit/ChipsTests.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ - (void)testDefaults {
105105

106106
// Then
107107
CGSize expectedMinimumSize = CGSizeMake(0, 32);
108+
CGSize expectedImageViewSize = CGSizeZero;
108109
UIEdgeInsets expectedContentPadding = UIEdgeInsetsMake(4, 4, 4, 4);
109110
UIEdgeInsets expectedImagePadding = UIEdgeInsetsZero;
110111
UIEdgeInsets expectedAccessoryPadding = UIEdgeInsetsZero;
111112
UIEdgeInsets expectedTitlePadding = UIEdgeInsetsMake(3, 8, 4, 8);
112113
XCTAssertTrue(CGSizeEqualToSize(chip.minimumSize, expectedMinimumSize),
113114
@"(%@) is not equal to (%@)", NSStringFromCGSize(chip.minimumSize),
114115
NSStringFromCGSize(expectedMinimumSize));
116+
XCTAssertTrue(CGSizeEqualToSize(chip.imageViewSize, expectedImageViewSize),
117+
@"(%@) is not equal to (%@)", NSStringFromCGSize(chip.imageViewSize),
118+
NSStringFromCGSize(expectedImageViewSize));
115119
XCTAssertFalse(chip.mdc_adjustsFontForContentSizeCategory);
116120
XCTAssertNotNil(chip.selectedImageView);
117121
XCTAssertNotNil(chip.titleLabel);

0 commit comments

Comments
 (0)