Skip to content

Commit cb030e2

Browse files
committed
Fix iOS 26 bottom tab test IDs
1 parent 0b04656 commit cb030e2

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

ios/RNNBottomTabsController.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "RNNBottomTabsController.h"
2+
#import "UITabBarController+RNNOptions.h"
23
#import "UITabBarController+RNNUtils.h"
34

45
@interface RNNBottomTabsController ()
@@ -100,6 +101,8 @@ - (void)createTabBarItems:(NSArray<UIViewController *> *)childViewControllers {
100101
for (UIViewController *child in childViewControllers) {
101102
[_bottomTabPresenter applyOptions:child.resolveOptions child:child];
102103
}
104+
105+
[self syncTabBarItemTestIDs];
103106
}
104107

105108
- (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
@@ -111,6 +114,8 @@ - (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewControlle
111114
[_dotIndicatorPresenter mergeOptions:options
112115
resolvedOptions:childViewController.resolveOptions
113116
child:childViewController];
117+
118+
[self syncTabBarItemTestIDs];
114119
}
115120

116121
- (id<UITabBarControllerDelegate>)delegate {
@@ -123,6 +128,7 @@ - (void)render {
123128

124129
- (void)viewDidLayoutSubviews {
125130
[super viewDidLayoutSubviews];
131+
[self syncTabBarItemTestIDs];
126132
[self.presenter viewDidLayoutSubviews];
127133
[_dotIndicatorPresenter bottomTabsDidLayoutSubviews:self];
128134
}

ios/UITabBarController+RNNOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020

2121
- (void)hideTabBar:(BOOL)animated;
2222

23+
- (void)syncTabBarItemTestIDs;
24+
2325
@end

ios/UITabBarController+RNNOptions.mm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
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

Comments
 (0)