Skip to content

Commit

Permalink
[Tabs] Fix a bug that where an item cell title can be missing (#2202)
Browse files Browse the repository at this point in the history
* [Tabs] Fix a bug that where an item cell title can be missing after an appearance change.

* Updates per code-review.
  • Loading branch information
csilv authored and ianegordon committed Oct 17, 2017
1 parent b6f95bb commit 5797b17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
4 changes: 1 addition & 3 deletions components/Tabs/src/private/MDCItemBarCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,7 @@ - (void)updateDisplayedImage {
}

- (void)updateDisplayedTitle {
if (!_titleLabel.hidden) {
_titleLabel.text = [[self class] displayedTitleForTitle:_title style:_style];
}
_titleLabel.text = [[self class] displayedTitleForTitle:_title style:_style];
}

@end
35 changes: 30 additions & 5 deletions components/Tabs/tests/unit/MDCItemBarCellTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ - (void)testTitleNumberOfLines {
style.shouldDisplayTitle = YES;

// When
[cellWithImageAndText setImage:[UIImage imageNamed:@"TabBarDemo_ic_info"]];
[cellWithImageOnly setImage:[UIImage imageNamed:@"TabBarDemo_ic_info"]];
cellWithImageAndText.image = [UIImage imageNamed:@"TabBarDemo_ic_info"];
cellWithImageOnly.image = [UIImage imageNamed:@"TabBarDemo_ic_info"];

[cellWithImageAndText setTitle:@"A title"];
[cellWithTextAndMissingImage setTitle:@"A title"];
[cellWithTextOnly setTitle:@"A title"];
cellWithImageAndText.title = @"A title";
cellWithTextAndMissingImage.title = @"A title";
cellWithTextOnly.title = @"A title";

[cellWithImageAndText applyStyle:style];
[cellWithImageOnly applyStyle:style];
Expand All @@ -59,4 +59,29 @@ - (void)testTitleNumberOfLines {
XCTAssertEqual(cellWithTextOnly.titleLabel.numberOfLines, 2);
}

/// Tests that a cell that was initially configured as image-only style, and then changed to
/// image-and-title style, will result in the correct title text.
- (void)testTitleAfterStyleChange {
MDCItemBarStyle *iconOnlyStyle = [[MDCItemBarStyle alloc] init];
iconOnlyStyle.shouldDisplayImage = YES;
iconOnlyStyle.shouldDisplayTitle = NO;

MDCItemBarStyle *iconAndTextStyle = [[MDCItemBarStyle alloc] init];
iconAndTextStyle.shouldDisplayImage = YES;
iconAndTextStyle.shouldDisplayTitle = YES;

// Create a cell and set the style before settting the image/title. That is the order items will
// be configured in the app runtime.
MDCItemBarCell *cell = [[MDCItemBarCell alloc] initWithFrame:CGRectZero];
[cell applyStyle:iconOnlyStyle];
cell.image = [UIImage imageNamed:@"TabBarDemo_ic_info"];
cell.title = @"A title";
XCTAssertEqual(cell.titleLabel.hidden, YES);

// Change the style to show image-and-title.
[cell applyStyle:iconAndTextStyle];
XCTAssertEqual(cell.titleLabel.hidden, NO);
XCTAssertEqualObjects(cell.titleLabel.text, @"A TITLE");
}

@end

0 comments on commit 5797b17

Please sign in to comment.