44
55@implementation UITabBarController (RNNOptions)
66
7+ - (void )rnn_applyTestID : (NSString *)testID toTabView : (UIView *)tabView {
8+ tabView.accessibilityIdentifier = testID;
9+ if (testID)
10+ tabView.isAccessibilityElement = YES ;
11+ }
12+
13+ - (BOOL )rnn_applyTabBarItemTestIDs {
14+ NSArray <UITabBarItem *> *items = self.tabBar .items ?: @[];
15+ BOOL appliedAllKnownTestIDs = YES ;
16+
17+ for (NSUInteger tabIndex = 0 ; tabIndex < items.count ; tabIndex++) {
18+ UITabBarItem *item = items[tabIndex];
19+ UIView *tabView = [self .tabBar tabBarItemViewAtIndex: tabIndex];
20+ if (tabView) {
21+ [self rnn_applyTestID: item.accessibilityIdentifier toTabView: tabView];
22+ } else if (item.accessibilityIdentifier ) {
23+ appliedAllKnownTestIDs = NO ;
24+ }
25+ }
26+
27+ return appliedAllKnownTestIDs;
28+ }
29+
730- (void )setCurrentTabIndex : (NSUInteger )currentTabIndex {
831 [self setSelectedIndex: currentTabIndex];
932}
@@ -16,6 +39,21 @@ - (void)setTabBarTestID:(NSString *)testID {
1639 self.tabBar .accessibilityIdentifier = testID;
1740}
1841
42+ - (void )syncTabBarItemTestIDs {
43+ if ([self rnn_applyTabBarItemTestIDs ])
44+ return ;
45+
46+ __weak UITabBarController *weakSelf = self;
47+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(0.15 * NSEC_PER_SEC)),
48+ dispatch_get_main_queue (), ^{
49+ UITabBarController *controller = weakSelf;
50+ if (!controller)
51+ return ;
52+
53+ [controller rnn_applyTabBarItemTestIDs ];
54+ });
55+ }
56+
1957- (void )setTabBarStyle : (UIBarStyle)barStyle {
2058 self.tabBar .barStyle = barStyle;
2159}
0 commit comments