Skip to content
Permalink
Browse files

[BottomNavigation] Delete `itemsContentInsets` API (#6584)

The `itemsContentInsets` API behaves unintuitively and is not used by
any internal clients. Since the Material Guidelines article for Bottom
Navigation does not allow customization of the positioning of the item
views within a Bottom Navigation, it's simply extra maintenance effort
without any clear value.

Resolves #6556
  • Loading branch information
romoore committed Feb 11, 2019
1 parent cd2a678 commit 0c2b2ea61b010242a74d57f726230d1d53a9df4b
@@ -139,14 +139,6 @@ typedef NS_ENUM(NSInteger, MDCBottomNavigationBarAlignment) {
*/
@property(nonatomic, assign, getter=isBackgroundBlurEnabled) BOOL backgroundBlurEnabled;

/**
The inset applied to each items bounds to determine the rect in which the items' contents will be
centered. The contents are centered in this rect, but not compressed, so they may still extend
beyond these bounds. Defaults to {0, 0, 0, 0}. The inset is flipped for RTL.
*/
@property(nonatomic, assign)
UIEdgeInsets itemsContentInsets __deprecated_msg("This API will be removed.");

/**
The margin between the item's icon and title when alignment is either Justified or Centered.
Defaults to 0.
@@ -445,10 +445,6 @@ - (void)setItems:(NSArray<UITabBarItem *> *)items {
itemView.accessibilityLabel = item.accessibilityLabel;
itemView.accessibilityHint = item.accessibilityHint;
itemView.isAccessibilityElement = item.isAccessibilityElement;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
itemView.contentInsets = self.itemsContentInsets;
#pragma clang diagnostic pop
itemView.contentVerticalMargin = self.itemsContentVerticalMargin;
itemView.contentHorizontalMargin = self.itemsContentHorizontalMargin;
MDCInkTouchController *controller = [[MDCInkTouchController alloc] initWithView:itemView];
@@ -517,18 +513,6 @@ - (void)setSelectedItem:(UITabBarItem *)selectedItem animated:(BOOL)animated {
}
}

- (void)setItemsContentInsets:(UIEdgeInsets)itemsContentInsets {
if (UIEdgeInsetsEqualToEdgeInsets(_itemsContentInsets, itemsContentInsets)) {
return;
}
_itemsContentInsets = itemsContentInsets;
for (NSUInteger i = 0; i < self.items.count; i++) {
MDCBottomNavigationItemView *itemView = self.itemViews[i];
itemView.contentInsets = itemsContentInsets;
}
[self setNeedsLayout];
}

- (void)setItemsContentVerticalMargin:(CGFloat)itemsContentsVerticalMargin {
if (MDCCGFloatEqual(_itemsContentVerticalMargin, itemsContentsVerticalMargin)) {
return;
@@ -37,8 +37,6 @@
@property(nonatomic, strong) UIColor *unselectedItemTintColor UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *selectedItemTitleColor;

@property(nonatomic, assign) UIEdgeInsets contentInsets;

@property(nonatomic, assign) CGFloat contentVerticalMargin;
@property(nonatomic, assign) CGFloat contentHorizontalMargin;

@@ -217,7 +217,7 @@ - (void)layoutSubviews {
}

- (void)centerLayoutAnimated:(BOOL)animated {
CGRect contentBoundingRect = UIEdgeInsetsInsetRect(self.bounds, self.contentInsets);
CGRect contentBoundingRect = CGRectStandardize(self.bounds);
CGFloat centerY = CGRectGetMidY(contentBoundingRect);
CGFloat centerX = CGRectGetMidX(contentBoundingRect);
UIUserInterfaceLayoutDirection layoutDirection = self.mdf_effectiveUserInterfaceLayoutDirection;
@@ -299,90 +299,4 @@ - (void)testTypicalWidthTallHeightLongTitleEmptyBadgeAdjacentRTL {
[self generateAndVerifySnapshot];
}

#pragma mark - ContentInsets

- (void)testContentInsetsStackedLTR {
// When
// Shift DOWN and RIGHT
self.itemView.titleBelowIcon = YES;
self.itemView.contentInsets = UIEdgeInsetsMake(10, 5, -10, -5);
self.itemView.frame = CGRectMake(0, 0, kWidthTypical, kHeightTypical);

[self generateAndVerifySnapshot];
}

- (void)testContentInsetsStackedRTL {
// When
// Shift DOWN and LEFT
[self changeToRTLAndArabicWithBadgeValue:kBadgeTitleEmpty];
self.itemView.titleBelowIcon = YES;
self.itemView.contentInsets = UIEdgeInsetsMake(10, 5, -10, -5);
self.itemView.frame = CGRectMake(0, 0, kWidthTypical, kHeightTypical);

[self generateAndVerifySnapshot];
}

- (void)testContentInsetsNoopStackedLTR {
// When
self.itemView.titleBelowIcon = YES;
self.itemView.contentInsets = UIEdgeInsetsMake(kHeightTypical / 2, kWidthTypical / 2,
kHeightTypical / 2, kWidthTypical / 2);
self.itemView.frame = CGRectMake(0, 0, kWidthTypical, kHeightTypical);

[self generateAndVerifySnapshot];
}

- (void)testContentInsetsNoopStackedRTL {
// When
[self changeToRTLAndArabicWithBadgeValue:kBadgeTitleEmpty];
self.itemView.titleBelowIcon = YES;
self.itemView.contentInsets = UIEdgeInsetsMake(kHeightTypical / 2, kWidthTypical / 2,
kHeightTypical / 2, kWidthTypical / 2);
self.itemView.frame = CGRectMake(0, 0, kWidthTypical, kHeightTypical);

[self generateAndVerifySnapshot];
}

- (void)testContentInsetsAdjacentLTR {
// When
// Shift UP and LEFT
self.itemView.titleBelowIcon = NO;
self.itemView.contentInsets = UIEdgeInsetsMake(-5, -10, 5, 10);
self.itemView.frame = CGRectMake(0, 0, kWidthTypical, kHeightTypical);

[self generateAndVerifySnapshot];
}

- (void)testContentInsetsAdjacentRTL {
// When
// Shift UP and RIGHT
[self changeToRTLAndArabicWithBadgeValue:kBadgeTitleEmpty];
self.itemView.titleBelowIcon = NO;
self.itemView.contentInsets = UIEdgeInsetsMake(-5, -10, 5, 10);
self.itemView.frame = CGRectMake(0, 0, kWidthTypical, kHeightTypical);

[self generateAndVerifySnapshot];
}

- (void)testContentInsetsNoopAdjacentLTR {
// When
self.itemView.titleBelowIcon = NO;
self.itemView.contentInsets = UIEdgeInsetsMake(kHeightTypical / 2, kWidthTypical / 2,
kHeightTypical / 2, kWidthTypical / 2);
self.itemView.frame = CGRectMake(0, 0, kWidthTypical, kHeightTypical);

[self generateAndVerifySnapshot];
}

- (void)testContentInsetsNoopAdjacentRTL {
// When
[self changeToRTLAndArabicWithBadgeValue:kBadgeTitleEmpty];
self.itemView.titleBelowIcon = NO;
self.itemView.contentInsets = UIEdgeInsetsMake(kHeightTypical / 2, kWidthTypical / 2,
kHeightTypical / 2, kWidthTypical / 2);
self.itemView.frame = CGRectMake(0, 0, kWidthTypical, kHeightTypical);

[self generateAndVerifySnapshot];
}

@end
@@ -86,30 +86,6 @@ - (void)testHorizontalMarginLayout {
(CGFloat)0.001);
}

- (void)testContentInsetLayout {
// Given
MDCBottomNavigationItemView *view = [[MDCBottomNavigationItemView alloc] init];
view.title = @"Test Content";
view.image = fakeImage();
view.bounds = CGRectMake(0, 0, 100, 100);
view.contentVerticalMargin = 20;
view.contentHorizontalMargin = 20;
view.titleVisibility = MDCBottomNavigationBarTitleVisibilityAlways;

// When
view.titleBelowIcon = YES;
view.contentInsets = UIEdgeInsetsMake(10, 10, 5, 5);
[view layoutSubviews];

// Then
CGRect contentRect = UIEdgeInsetsInsetRect(view.bounds, view.contentInsets);
XCTAssert(view.label.center.x == CGRectGetMidX(contentRect));
XCTAssert(view.iconImageView.center.x == CGRectGetMidX(contentRect));
CGFloat contentSpan = CGRectGetMaxY(view.label.frame) - CGRectGetMinY(view.iconImageView.frame);
XCTAssertEqualWithAccuracy(CGRectGetMinY(view.iconImageView.frame) + contentSpan / 2,
CGRectGetMidY(contentRect), (CGFloat)0.001);
}

- (void)testSetSelectedItemTintColorUpdatesInkColor {
// Given
MDCBottomNavigationItemView *item1 = [[MDCBottomNavigationItemView alloc] init];
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 0c2b2ea

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