Skip to content
Permalink
Browse files

[BottomNavigation] Give UITabBarItems' accessibilityIdentifiers to MD…

…CBottomNavigationBa… (#4599)

* Give UITabBarItems' accessibilityIdentifiers to MDCBottomNavigationBar's items' buttons

* KVO tab bar item accessibilityIdentifier in MDCBottomNavigationItemView

* Add unit test for tracking UITabBarItem accessibilityIdentifier

* Fix KVO and associated spec

* Move accessibilityIdentifier spec
  • Loading branch information
andrewoverton committed Jul 25, 2018
1 parent a0c3ee3 commit 87496292fff9a73ca671ab63939fcc2ed665fe34
@@ -44,6 +44,7 @@
// TODO: - Change to NSKeyValueChangeNewKey
static NSString *const kMDCBottomNavigationBarNewString = @"new";
static NSString *const kMDCBottomNavigationBarTitleString = @"title";
static NSString *const kMDCBottomNavigationBarAccessibilityIdentifier = @"accessibilityIdentifier";


static NSString *const kMDCBottomNavigationBarOfAnnouncement = @"of";
@@ -245,6 +246,10 @@ - (void)addObserversToTabBarItems {
forKeyPath:kMDCBottomNavigationBarTitleString
options:NSKeyValueObservingOptionNew
context:nil];
[item addObserver:self
forKeyPath:kMDCBottomNavigationBarAccessibilityIdentifier
options:NSKeyValueObservingOptionNew
context:nil];
}
}

@@ -259,6 +264,7 @@ - (void)removeObserversFromTabBarItems {
[item removeObserver:self
forKeyPath:kMDCBottomNavigationBarSelectedImageString];
[item removeObserver:self forKeyPath:kMDCBottomNavigationBarTitleString];
[item removeObserver:self forKeyPath:kMDCBottomNavigationBarAccessibilityIdentifier];
}
@catch (NSException *exception) {
if (exception) {
@@ -295,6 +301,8 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
itemView.selectedImage = change[kMDCBottomNavigationBarNewString];
} else if ([keyPath isEqualToString:kMDCBottomNavigationBarTitleString]) {
itemView.title = change[kMDCBottomNavigationBarNewString];
} else if ([keyPath isEqualToString:kMDCBottomNavigationBarAccessibilityIdentifier]) {
itemView.accessibilityIdentifier = change[kMDCBottomNavigationBarNewString];
}
}
}
@@ -377,6 +385,7 @@ - (void)setItems:(NSArray<UITabBarItem *> *)items {
itemView.titleVisibility = self.titleVisibility;
itemView.titleBelowIcon = self.titleBelowItem;
itemView.accessibilityValue = item.accessibilityValue;
itemView.accessibilityIdentifier = item.accessibilityIdentifier;
itemView.contentInsets = self.itemsContentInsets;
itemView.contentVerticalMargin = self.itemsContentVerticalMargin;
itemView.contentHorizontalMargin = self.itemsContentHorizontalMargin;
@@ -374,6 +374,14 @@ - (NSString *)accessibilityValue {
return self.button.accessibilityValue;
}

-(void)setAccessibilityIdentifier:(NSString *)accessibilityIdentifier {
self.button.accessibilityIdentifier = accessibilityIdentifier;
}

-(NSString *)accessibilityIdentifier {
return self.button.accessibilityIdentifier;
}

#pragma mark - Resource bundle

+ (NSBundle *)bundle {
@@ -128,4 +128,18 @@ -(void)testSelectedItemAfterReset {
XCTAssertNil(self.bottomNavBar.selectedItem);
}

- (void)testAccessibilityIdentifier {
NSString *oldIdentifier = @"oldIdentifier";
NSString *newIdentifier = @"newIdentifier";
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Home"
image:nil
tag:0];
tabBarItem.accessibilityIdentifier = oldIdentifier;
MDCBottomNavigationBar *bar = [[MDCBottomNavigationBar alloc] init];
bar.items = @[ tabBarItem ];
XCTAssert([bar.itemViews.firstObject.accessibilityIdentifier isEqualToString:oldIdentifier]);
tabBarItem.accessibilityIdentifier = newIdentifier;
XCTAssert([bar.itemViews.firstObject.accessibilityIdentifier isEqualToString:newIdentifier]);
}

@end

0 comments on commit 8749629

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