From 30df338682e1abd7d3e547ca59844d9ea4ff1b19 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Tue, 10 Dec 2019 15:00:33 -0500 Subject: [PATCH] Remove equality check when setting rippleColor to prevent crashes stemming from CIColor (#9237) Comparing a non-`UICIColor` (e.g., a `UIExtendedSRGBColorSpace` UIColor) with a `UICIColor` crashes with the message: > error: -[MDCActionSheetTableCellTest testSetRippleColor] : failed: caught "NSInvalidArgumentException", "-[UICIColor colorSpaceName]: unrecognized selector sent to instance 0x7ff1c02595b0" Because of this, and the fact that this check is likely an unnecessary optimization (and because `isEqual:` does not return YES for UIColors from different color spaces, even if they have the same RGBA values), this PR removes the equality check. Fixes #9236 --- .../ActionSheet/src/MDCActionSheetController.m | 4 ---- .../tests/unit/MDCActionSheetTableCellTest.m | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/components/ActionSheet/src/MDCActionSheetController.m b/components/ActionSheet/src/MDCActionSheetController.m index bc293eecb56..efed6d75f4e 100644 --- a/components/ActionSheet/src/MDCActionSheetController.m +++ b/components/ActionSheet/src/MDCActionSheetController.m @@ -523,11 +523,7 @@ - (void)setInkColor:(UIColor *)inkColor { } - (void)setRippleColor:(UIColor *)rippleColor { - if (_rippleColor == rippleColor || [_rippleColor isEqual:rippleColor]) { - return; - } _rippleColor = rippleColor; - [self.tableView reloadData]; } diff --git a/components/ActionSheet/tests/unit/MDCActionSheetTableCellTest.m b/components/ActionSheet/tests/unit/MDCActionSheetTableCellTest.m index adc3b6c6784..4a4f08c1b64 100644 --- a/components/ActionSheet/tests/unit/MDCActionSheetTableCellTest.m +++ b/components/ActionSheet/tests/unit/MDCActionSheetTableCellTest.m @@ -148,6 +148,20 @@ - (void)testSetInkColor { } } +- (void)testSetRippleColor { + // When + NSArray *colors = [MDCActionSheetTestHelper colorsToTest]; + + for (UIColor *color in colors) { + self.actionSheet.rippleColor = color; + NSArray *cells = [MDCActionSheetTestHelper getCellsFromActionSheet:self.actionSheet]; + for (MDCActionSheetItemTableViewCell *cell in cells) { + // Then + XCTAssertEqualObjects(cell.rippleColor, color); + } + } +} + - (void)testSetActionFont { // Given UIFont *actionFont = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];