Skip to content
Permalink
Browse files

[Tabs] Minor refactoring of KVO code. (#7825)

The KVO code for title text and images requires invalidation of the intrinsic
content size and layout for both the item view and the tab bar. The code was
repeated and it was easy to miss one or more steps for any of the use cases.

Follow-up to #7814
  • Loading branch information
romoore committed Jul 10, 2019
1 parent fbf405b commit bd61834803047560d3f6095ffa72c4b52cba5934
Showing with 10 additions and 12 deletions.
  1. +10 −12 components/Tabs/src/TabBarView/MDCTabBarView.m
@@ -489,22 +489,13 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}
if ([keyPath isEqualToString:kImageKeyPath]) {
tabBarItemView.image = newValue;
[tabBarItemView invalidateIntrinsicContentSize];
[tabBarItemView setNeedsLayout];
[self invalidateIntrinsicContentSize];
[self setNeedsLayout];
[self markIntrinsicContentSizeAndLayoutNeedingUpdateForSelfAndItemView:tabBarItemView];
} else if ([keyPath isEqualToString:kSelectedImageKeyPath]) {
tabBarItemView.selectedImage = newValue;
[tabBarItemView invalidateIntrinsicContentSize];
[tabBarItemView setNeedsLayout];
[self invalidateIntrinsicContentSize];
[self setNeedsLayout];
[self markIntrinsicContentSizeAndLayoutNeedingUpdateForSelfAndItemView:tabBarItemView];
} else if ([keyPath isEqualToString:kTitleKeyPath]) {
tabBarItemView.titleLabel.text = newValue;
[tabBarItemView invalidateIntrinsicContentSize];
[tabBarItemView setNeedsLayout];
[self invalidateIntrinsicContentSize];
[self setNeedsLayout];
[self markIntrinsicContentSizeAndLayoutNeedingUpdateForSelfAndItemView:tabBarItemView];
} else if ([keyPath isEqualToString:kAccessibilityLabelKeyPath]) {
tabBarItemView.accessibilityLabel = newValue;
} else if ([keyPath isEqualToString:kAccessibilityHintKeyPath]) {
@@ -526,6 +517,13 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}
}

- (void)markIntrinsicContentSizeAndLayoutNeedingUpdateForSelfAndItemView:(UIView *)itemView {
[itemView invalidateIntrinsicContentSize];
[itemView setNeedsLayout];
[self invalidateIntrinsicContentSize];
[self setNeedsLayout];
}

#pragma mark - UIView

- (void)layoutSubviews {

0 comments on commit bd61834

Please sign in to comment.
You can’t perform that action at this time.