Skip to content

Commit

Permalink
[BottomNavigation] Delete itemsContentInsets API (#6584)
Browse files Browse the repository at this point in the history
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
Robert Moore committed Feb 11, 2019
1 parent cd2a678 commit 0c2b2ea
Show file tree
Hide file tree
Showing 14 changed files with 1 addition and 137 deletions.
8 changes: 0 additions & 8 deletions components/BottomNavigation/src/MDCBottomNavigationBar.h
Expand Up @@ -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.
Expand Down
16 changes: 0 additions & 16 deletions components/BottomNavigation/src/MDCBottomNavigationBar.m
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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;

Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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
Expand Up @@ -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];
Expand Down
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.