Skip to content

Commit

Permalink
[Tabs] Fix image tint color when unselecting an item. (#7756)
Browse files Browse the repository at this point in the history
When the selected item became `nil`, the image tint color for the previously-selected item was not updated.

Follow-up to #7714
  • Loading branch information
Robert Moore committed Jul 1, 2019
1 parent febf914 commit 0e97389
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion components/Tabs/src/TabBarView/MDCTabBarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ - (void)setSelectedItem:(UITabBarItem *)selectedItem animated:(BOOL)animated {
if (!selectedItem) {
_selectedItem = selectedItem;
[self updateTitleColorForAllViews];
[self updateImageTintColorForAllViews];
[self updateTitleFontForAllViews];
return;
}

Expand All @@ -205,6 +207,7 @@ - (void)setSelectedItem:(UITabBarItem *)selectedItem animated:(BOOL)animated {
(newSelectedItemView.accessibilityTraits | UIAccessibilityTraitSelected);
[self updateTitleColorForAllViews];
[self updateImageTintColorForAllViews];
[self updateTitleFontForAllViews];
CGRect itemFrameInScrollViewBounds =
[self convertRect:self.containerView.arrangedSubviews[itemIndex].frame
fromView:self.containerView];
Expand Down Expand Up @@ -410,7 +413,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
[self updateTitleColorForAllViews];
}

#pragma mark - UIView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,27 @@ - (void)testChangingSelectedItemIgnoresSelectedImage {
[self generateSnapshotAndVerifyForView:self.tabBarView];
}

- (void)testRemovingSelectedItemUpdatesStyle {
// Given
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"One" image:self.typicalIcon1 tag:0];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"Two" image:self.typicalIcon2 tag:1];
self.tabBarView.items = @[ item1, item2 ];
[self.tabBarView sizeToFit];
[self.tabBarView setSelectedItem:item1 animated:NO];
[self.tabBarView setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
[self.tabBarView setImageTintColor:UIColor.blackColor forState:UIControlStateNormal];
[self.tabBarView setTitleFont:[UIFont systemFontOfSize:8] forState:UIControlStateNormal];
[self.tabBarView setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
[self.tabBarView setImageTintColor:UIColor.whiteColor forState:UIControlStateSelected];
[self.tabBarView setTitleFont:[UIFont systemFontOfSize:24] forState:UIControlStateSelected];

// When
[self.tabBarView setSelectedItem:nil animated:NO];

// Then
[self generateSnapshotAndVerifyForView:self.tabBarView];
}

- (void)testSelectedItemInitiallyVisibleLTRLatin {
// Given
self.tabBarView.bounds =
Expand Down Expand Up @@ -893,8 +914,10 @@ - (void)testChangingSelectionUpdatesItemStyle {
[self.tabBarView setSelectedItem:item2 animated:NO];
[self.tabBarView setTitleColor:UIColor.purpleColor forState:UIControlStateNormal];
[self.tabBarView setImageTintColor:UIColor.redColor forState:UIControlStateNormal];
[self.tabBarView setTitleFont:[UIFont systemFontOfSize:8] forState:UIControlStateNormal];
[self.tabBarView setTitleColor:UIColor.brownColor forState:UIControlStateSelected];
[self.tabBarView setImageTintColor:UIColor.blueColor forState:UIControlStateSelected];
[self.tabBarView setTitleFont:[UIFont systemFontOfSize:24] forState:UIControlStateSelected];

// When
[self.tabBarView setSelectedItem:item3 animated:NO];
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0e97389

Please sign in to comment.