Skip to content

Commit decc506

Browse files
Janette Jamesmaterial-automation
Janette James
authored andcommitted
[Bottom Navigation] Remove deprecated badge properties and update tests to reflect new behavior.
PiperOrigin-RevId: 702506989
1 parent 3694092 commit decc506

File tree

5 files changed

+108
-120
lines changed

5 files changed

+108
-120
lines changed

components/BottomNavigation/src/MDCBottomNavigationBar.h

+4-35
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#import "MaterialShadow.h"
2626
#import "MaterialShadowElevations.h"
2727

28+
NS_ASSUME_NONNULL_BEGIN
29+
2830
@protocol MDCBottomNavigationBarDelegate;
2931

3032
/** States used to configure bottom navigation on when to show item titles. */
@@ -353,21 +355,6 @@ traitCollectionDidChange:. The block is called after the call to the superclass.
353355
*/
354356
@property(nonatomic, copy, nonnull) MDCBadgeAppearance *itemBadgeAppearance;
355357

356-
/**
357-
Default background color for badges.
358-
359-
If a given UITabBarItem's `badgeColor` is non-nil, then the item's `badgeColor` is used instead of
360-
this value.
361-
362-
This property is a proxy for itemBadgeAppearance.backgroundColor, with the exception that assigning
363-
nil will be treated as [UIColor clearColor].
364-
365-
Default is a red color.
366-
*/
367-
@property(nonatomic, copy, nullable)
368-
UIColor *itemBadgeBackgroundColor API_DEPRECATED_WITH_REPLACEMENT(
369-
"itemBadgeAppearance.backgroundColor", ios(12, 12));
370-
371358
/**
372359
X-offset for Badge position.
373360
@@ -381,26 +368,6 @@ traitCollectionDidChange:. The block is called after the call to the superclass.
381368
*/
382369
@property(nonatomic, assign) CGFloat itemBadgeHorizontalOffset;
383370

384-
/**
385-
Text color for badges.
386-
387-
This property is a proxy for itemBadgeAppearance.textColor.
388-
389-
Default is white.
390-
*/
391-
@property(nonatomic, copy, nullable) UIColor *itemBadgeTextColor API_DEPRECATED_WITH_REPLACEMENT(
392-
"itemBadgeAppearance.textColor", ios(12, 12));
393-
394-
/**
395-
Text font for badges.
396-
397-
This property is a proxy for itemBadgeAppearance.font.
398-
399-
Default is a small system font.
400-
*/
401-
@property(nonatomic, copy, nullable) UIFont *itemBadgeTextFont API_DEPRECATED_WITH_REPLACEMENT(
402-
"itemBadgeAppearance.font", ios(12, 12));
403-
404371
@end
405372

406373
#if MDC_AVAILABLE_SDK_IOS(13_0) && !TARGET_OS_TV
@@ -424,3 +391,5 @@ API_UNAVAILABLE(tvos, watchos)
424391
UILargeContentViewerInteractionDelegate>
425392
@end
426393
#endif // MDC_AVAILABLE_SDK_IOS(13_0)
394+
395+
NS_ASSUME_NONNULL_END

components/BottomNavigation/src/MDCBottomNavigationBar.m

+4-36
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ - (void)commonMDCBottomNavigationBarInit {
133133
_rippleEnabled = YES;
134134
_itemsAlignmentInVerticalMode = MDCNavigationBarItemsVerticalAlignmentCenter;
135135
_itemBadgeAppearance = [[MDCBadgeAppearance alloc] init];
136+
_itemBadgeAppearance.textColor = UIColor.whiteColor;
137+
_itemBadgeAppearance.font = [UIFont systemFontOfSize:kBadgeFontSize];
138+
_itemBadgeAppearance.backgroundColor = MDCPalette.redPalette.tint700;
136139

137-
// TODO(featherless): Delete once everyone has migrated to itemBadgeAppearance.
138-
_itemBadgeTextColor = UIColor.whiteColor;
139-
_itemBadgeTextFont = [UIFont systemFontOfSize:kBadgeFontSize];
140-
_itemBadgeBackgroundColor = MDCPalette.redPalette.tint700;
141140
_itemsHorizontalPadding = kDefaultItemHorizontalPadding;
142141
_showsSelectionIndicator = NO;
143142
_selectionIndicatorColor = [UIColor colorWithRed:195.f / 255.f
@@ -914,6 +913,7 @@ - (void)setItems:(NSArray<UITabBarItem *> *)items {
914913
itemView.selected = NO;
915914
itemView.displayTitleInVerticalLayout = self.displayItemTitlesInVerticalLayout;
916915
itemView.enableVerticalLayout = self.enableVerticalLayout;
916+
itemView.badgeAppearance = _itemBadgeAppearance;
917917

918918
itemView.selectionIndicatorColor = self.selectionIndicatorColor;
919919
itemView.selectionIndicatorSize = self.selectionIndicatorSize;
@@ -1305,38 +1305,6 @@ - (void)setItemBadgeHorizontalOffset:(CGFloat)itemBadgeHorizontalOffset {
13051305
}
13061306
}
13071307

1308-
// TODO(featherless): Delete once everyone has migrated to itemBadgeAppearance.
1309-
- (void)setItemBadgeBackgroundColor:(nullable UIColor *)itemBadgeBackgroundColor {
1310-
_itemBadgeBackgroundColor = itemBadgeBackgroundColor;
1311-
1312-
for (NSUInteger i = 0; i < self.items.count; ++i) {
1313-
UITabBarItem *item = self.items[i];
1314-
if (item.badgeColor) {
1315-
continue;
1316-
}
1317-
MDCBottomNavigationItemView *itemView = self.itemViews[i];
1318-
itemView.badgeColor = itemBadgeBackgroundColor;
1319-
}
1320-
}
1321-
1322-
// TODO(featherless): Delete once everyone has migrated to itemBadgeAppearance.
1323-
- (void)setItemBadgeTextColor:(nullable UIColor *)itemBadgeTextColor {
1324-
_itemBadgeTextColor = itemBadgeTextColor;
1325-
1326-
for (MDCBottomNavigationItemView *itemView in self.itemViews) {
1327-
itemView.badgeTextColor = itemBadgeTextColor;
1328-
}
1329-
}
1330-
1331-
// TODO(featherless): Delete once everyone has migrated to itemBadgeAppearance.
1332-
- (void)setItemBadgeTextFont:(nullable UIFont *)itemBadgeTextFont {
1333-
_itemBadgeTextFont = itemBadgeTextFont;
1334-
1335-
for (MDCBottomNavigationItemView *itemView in self.itemViews) {
1336-
itemView.badgeFont = itemBadgeTextFont;
1337-
}
1338-
}
1339-
13401308
// TODO(b/244765238): Remove branching layout logic after GM3 migrations
13411309
// Assume that setting itemBadgeHorizontalOffset to any value other than its default (0) should
13421310
// activate the new anchored/GM3 layout, and assume that anyone applying GM3 branding for Bottom

components/BottomNavigation/src/private/MDCBottomNavigationBar+ItemView.m

+4-11
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
#import <UIKit/UIKit.h>
1616

17-
#import "MDCAvailability.h"
1817
#import "MDCBottomNavigationBar.h"
1918
#import "MDCBottomNavigationBar+ItemView.h"
2019
#import "MDCBottomNavigationBar+Private.h"
2120
#import "MDCBottomNavigationItemView.h"
2221

22+
NS_ASSUME_NONNULL_BEGIN
23+
2324
@implementation MDCBottomNavigationBar (ItemViewConfiguration)
2425

2526
#pragma mark - Public
@@ -37,21 +38,11 @@ - (void)configureAppearanceForItemView:(MDCBottomNavigationItemView *)itemView {
3738
itemView.selectionIndicatorSize = self.selectionIndicatorSize;
3839
itemView.showsSelectionIndicator = self.showsSelectionIndicator;
3940

40-
// TODO(b/234850214): Delete once everyone has migrated to itemBadgeAppearance.
41-
[self configureBadgeForItemViewLegacy:itemView];
42-
4341
[self configureColorsForItemView:itemView];
4442
[self configureMarginForItemView:itemView];
4543
[self configureTitleForItemView:itemView];
4644
}
4745

48-
// TODO(b/234850214): Delete once everyone has migrated to itemBadgeAppearance.
49-
- (void)configureBadgeForItemViewLegacy:(MDCBottomNavigationItemView *)itemView {
50-
itemView.badgeColor = self.itemBadgeBackgroundColor;
51-
itemView.badgeFont = self.itemBadgeTextFont;
52-
itemView.badgeTextColor = self.itemBadgeTextColor;
53-
}
54-
5546
- (void)configureColorsForItemView:(MDCBottomNavigationItemView *)itemView {
5647
// rippleColor must be set before selectedItemTintColor because selectedItemTintColor's behavior
5748
// depends on the value of rippleColor.
@@ -113,3 +104,5 @@ - (void)configurePointerInteractionForItemView:(MDCBottomNavigationItemView *)it
113104
}
114105

115106
@end
107+
108+
NS_ASSUME_NONNULL_END

components/BottomNavigation/tests/snapshot/MDCBottomNavigationBarSnapshotTests.m

+96-18
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414

1515
#import <UIKit/UIKit.h>
1616
#import <XCTest/XCTest.h>
17+
#import "MDCBadgeAppearance.h"
1718

1819
#pragma clang diagnostic push
1920
#pragma clang diagnostic ignored "-Wprivate-header"
21+
#import "MDCBottomNavigationBarItem.h"
2022
#import "MDCBottomNavigationItemView.h"
2123
#pragma clang diagnostic pop
2224

2325
#import "supplemental/MDCBottomNavigationSnapshotTestMutableTraitCollection.h"
2426
#import "supplemental/MDCBottomNavigationSnapshotTestUtilities.h"
2527
#import "supplemental/MDCFakeBottomNavigationBar.h"
2628
#import "MDCAvailability.h"
29+
#import "MDCBadgeAppearance.h"
2730
#import "MDCBottomNavigationBar.h"
2831
#import "MDCRippleTouchController.h"
2932
#import "MDCRippleView.h"
@@ -401,7 +404,7 @@ - (void)testShadowColorRespondsToDynamicColor {
401404

402405
#pragma mark - Badging
403406

404-
- (void)testCustomBadgeColorsSetAfterItems {
407+
- (void)testCustomBadgeColorsOverrideDefaultBadgeAppearanceWhenSetAfterBarItems {
405408
// Given
406409
self.tabItem1.badgeValue = @"";
407410
self.tabItem2.badgeValue = @"Gray on Yellow";
@@ -410,15 +413,34 @@ - (void)testCustomBadgeColorsSetAfterItems {
410413
MDCBottomNavigationBarTestHeightTypical);
411414

412415
// When
413-
self.tabItem3.badgeColor = UIColor.greenColor;
414-
self.navigationBar.itemBadgeBackgroundColor = UIColor.yellowColor;
415-
self.navigationBar.itemBadgeTextColor = UIColor.darkGrayColor;
416+
MDCBadgeAppearance *greenAppearance = [[MDCBadgeAppearance alloc] init];
417+
greenAppearance.font = [UIFont systemFontOfSize:8.0];
418+
greenAppearance.backgroundColor = UIColor.greenColor;
419+
greenAppearance.textColor = UIColor.darkGrayColor;
420+
MDCBottomNavigationBarItem *barItem1 =
421+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem1];
422+
MDCBottomNavigationBarItem *barItem2 =
423+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem2];
424+
MDCBottomNavigationBarItem *barItem3 =
425+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem3
426+
badgeAppearance:greenAppearance];
427+
MDCBottomNavigationBarItem *barItem4 =
428+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem4];
429+
MDCBottomNavigationBarItem *barItem5 =
430+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem5];
431+
self.navigationBar.barItems = @[ barItem1, barItem2, barItem3, barItem4, barItem5 ];
432+
433+
MDCBadgeAppearance *badgeAppearance = [[MDCBadgeAppearance alloc] init];
434+
badgeAppearance.font = [UIFont systemFontOfSize:8.0];
435+
badgeAppearance.backgroundColor = UIColor.yellowColor;
436+
badgeAppearance.textColor = UIColor.darkGrayColor;
437+
self.navigationBar.itemBadgeAppearance = badgeAppearance;
416438

417439
// Then
418440
[self generateAndVerifySnapshot];
419441
}
420442

421-
- (void)testCustomBadgeColorsSetBeforeItems {
443+
- (void)testCustomBadgeColorsOverrideDefaultBadgeAppearanceWhenSetBeforeBarItems {
422444
// Given
423445
self.tabItem1.badgeValue = @"";
424446
self.tabItem2.badgeValue = @"Gray on Yellow";
@@ -427,11 +449,27 @@ - (void)testCustomBadgeColorsSetBeforeItems {
427449
MDCBottomNavigationBarTestHeightTypical);
428450

429451
// When
430-
self.tabItem3.badgeColor = UIColor.greenColor;
431-
self.navigationBar.itemBadgeBackgroundColor = UIColor.yellowColor;
432-
self.navigationBar.itemBadgeTextColor = UIColor.darkGrayColor;
433-
self.navigationBar.items =
434-
@[ self.tabItem1, self.tabItem2, self.tabItem3, self.tabItem4, self.tabItem5 ];
452+
MDCBadgeAppearance *badgeAppearance = [[MDCBadgeAppearance alloc] init];
453+
badgeAppearance.font = [UIFont systemFontOfSize:8.0];
454+
badgeAppearance.backgroundColor = UIColor.yellowColor;
455+
badgeAppearance.textColor = UIColor.darkGrayColor;
456+
self.navigationBar.itemBadgeAppearance = badgeAppearance;
457+
MDCBadgeAppearance *greenAppearance = [[MDCBadgeAppearance alloc] init];
458+
greenAppearance.font = [UIFont systemFontOfSize:8.0];
459+
greenAppearance.backgroundColor = UIColor.greenColor;
460+
greenAppearance.textColor = UIColor.darkGrayColor;
461+
MDCBottomNavigationBarItem *barItem1 =
462+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem1];
463+
MDCBottomNavigationBarItem *barItem2 =
464+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem2];
465+
MDCBottomNavigationBarItem *barItem3 =
466+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem3
467+
badgeAppearance:greenAppearance];
468+
MDCBottomNavigationBarItem *barItem4 =
469+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem4];
470+
MDCBottomNavigationBarItem *barItem5 =
471+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem5];
472+
self.navigationBar.barItems = @[ barItem1, barItem2, barItem3, barItem4, barItem5 ];
435473

436474
// Then
437475
[self generateAndVerifySnapshot];
@@ -446,9 +484,27 @@ - (void)testClearBadgeColorsRendersClearBackgroundAndUILabelDefaultTextColor {
446484
MDCBottomNavigationBarTestHeightTypical);
447485

448486
// When
449-
self.tabItem3.badgeColor = UIColor.greenColor;
450-
self.navigationBar.itemBadgeBackgroundColor = [UIColor clearColor];
451-
self.navigationBar.itemBadgeTextColor = nil;
487+
MDCBadgeAppearance *greenAppearance = [[MDCBadgeAppearance alloc] init];
488+
greenAppearance.font = [UIFont systemFontOfSize:8.0];
489+
greenAppearance.backgroundColor = UIColor.greenColor;
490+
greenAppearance.textColor = UIColor.blackColor;
491+
MDCBottomNavigationBarItem *barItem1 =
492+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem1];
493+
MDCBottomNavigationBarItem *barItem2 =
494+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem2];
495+
MDCBottomNavigationBarItem *barItem3 =
496+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem3
497+
badgeAppearance:greenAppearance];
498+
MDCBottomNavigationBarItem *barItem4 =
499+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem4];
500+
MDCBottomNavigationBarItem *barItem5 =
501+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem5];
502+
self.navigationBar.barItems = @[ barItem1, barItem2, barItem3, barItem4, barItem5 ];
503+
MDCBadgeAppearance *badgeAppearance = [[MDCBadgeAppearance alloc] init];
504+
badgeAppearance.font = [UIFont systemFontOfSize:8.0];
505+
badgeAppearance.backgroundColor = UIColor.clearColor;
506+
badgeAppearance.textColor = nil;
507+
self.navigationBar.itemBadgeAppearance = badgeAppearance;
452508

453509
// Then
454510
[self generateAndVerifySnapshot];
@@ -463,9 +519,27 @@ - (void)testNilBadgeColorsRendersTintBackgroundAndUILabelDefaultTextColor {
463519
MDCBottomNavigationBarTestHeightTypical);
464520

465521
// When
466-
self.tabItem3.badgeColor = UIColor.greenColor;
467-
self.navigationBar.itemBadgeBackgroundColor = nil;
468-
self.navigationBar.itemBadgeTextColor = nil;
522+
MDCBadgeAppearance *greenAppearance = [[MDCBadgeAppearance alloc] init];
523+
greenAppearance.font = [UIFont systemFontOfSize:8.0];
524+
greenAppearance.backgroundColor = UIColor.greenColor;
525+
greenAppearance.textColor = UIColor.blackColor;
526+
MDCBottomNavigationBarItem *barItem1 =
527+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem1];
528+
MDCBottomNavigationBarItem *barItem2 =
529+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem2];
530+
MDCBottomNavigationBarItem *barItem3 =
531+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem3
532+
badgeAppearance:greenAppearance];
533+
MDCBottomNavigationBarItem *barItem4 =
534+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem4];
535+
MDCBottomNavigationBarItem *barItem5 =
536+
[[MDCBottomNavigationBarItem alloc] initWithBarItem:self.tabItem5];
537+
self.navigationBar.barItems = @[ barItem1, barItem2, barItem3, barItem4, barItem5 ];
538+
MDCBadgeAppearance *badgeAppearance = [[MDCBadgeAppearance alloc] init];
539+
badgeAppearance.font = [UIFont systemFontOfSize:8.0];
540+
badgeAppearance.backgroundColor = nil;
541+
badgeAppearance.textColor = nil;
542+
self.navigationBar.itemBadgeAppearance = badgeAppearance;
469543

470544
// Then
471545
[self generateAndVerifySnapshot];
@@ -479,7 +553,9 @@ - (void)testCustomBadgeTextFontSetBeforeItems {
479553
MDCBottomNavigationBarTestHeightTypical);
480554

481555
// When
482-
self.navigationBar.itemBadgeTextFont = [UIFont systemFontOfSize:10.0];
556+
MDCBadgeAppearance *badgeAppearance = [[MDCBadgeAppearance alloc] init];
557+
badgeAppearance.font = [UIFont systemFontOfSize:10.0];
558+
self.navigationBar.itemBadgeAppearance = badgeAppearance;
483559
self.navigationBar.items =
484560
@[ self.tabItem1, self.tabItem2, self.tabItem3, self.tabItem4, self.tabItem5 ];
485561

@@ -497,7 +573,9 @@ - (void)testCustomBadgeTextFontSetAfterItems {
497573
// When
498574
self.navigationBar.items =
499575
@[ self.tabItem1, self.tabItem2, self.tabItem3, self.tabItem4, self.tabItem5 ];
500-
self.navigationBar.itemBadgeTextFont = [UIFont systemFontOfSize:10.0];
576+
MDCBadgeAppearance *badgeAppearance = [[MDCBadgeAppearance alloc] init];
577+
badgeAppearance.font = [UIFont systemFontOfSize:10.0];
578+
self.navigationBar.itemBadgeAppearance = badgeAppearance;
501579

502580
// Then
503581
[self generateAndVerifySnapshot];

components/BottomNavigation/tests/unit/MDCBottomNavigationBarTests.m

-20
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#pragma clang diagnostic pop
2222
#import "MDCAvailability.h"
2323
#import "MDCBottomNavigationBar.h"
24-
#import "MDCPalettes.h"
2524
#import "MDCShadowElevations.h"
2625

2726
NS_ASSUME_NONNULL_BEGIN
@@ -66,25 +65,6 @@ - (void)tearDown {
6665
self.bottomNavBar = nil;
6766
}
6867

69-
- (void)testDefaultValues {
70-
// When
71-
MDCBottomNavigationBar *bar = [[MDCBottomNavigationBar alloc] init];
72-
73-
// Then
74-
XCTAssertEqualObjects(bar.backgroundColor, UIColor.whiteColor);
75-
XCTAssertFalse(bar.isBackgroundBlurEnabled);
76-
XCTAssertEqual(bar.backgroundBlurEffectStyle, UIBlurEffectStyleExtraLight);
77-
XCTAssertEqualWithAccuracy(self.bottomNavBar.elevation, MDCShadowElevationBottomNavigationBar,
78-
0.001);
79-
XCTAssertEqualWithAccuracy(self.bottomNavBar.mdc_currentElevation, self.bottomNavBar.elevation,
80-
0.001);
81-
XCTAssertLessThan(self.bottomNavBar.mdc_overrideBaseElevation, 0);
82-
XCTAssertNil(self.bottomNavBar.mdc_elevationDidChangeBlock);
83-
XCTAssertEqualObjects(self.bottomNavBar.itemBadgeTextColor, UIColor.whiteColor);
84-
XCTAssertEqualObjects(self.bottomNavBar.itemBadgeTextFont, [UIFont systemFontOfSize:8.0]);
85-
XCTAssertEqualObjects(self.bottomNavBar.itemBadgeBackgroundColor, MDCPalette.redPalette.tint700);
86-
}
87-
8868
#pragma mark - Fonts
8969

9070
- (void)testItemTitleFontDefault {

0 commit comments

Comments
 (0)