Skip to content

Commit 6c26601

Browse files
committed
Move logic for setting testId, label on tab item
1 parent 4e91e66 commit 6c26601

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

ios/bottom-tabs/host/RNSTabBarController.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ - (void)reactMountingTransactionDidMount
9797
[self updateReactChildrenControllersIfNeeded];
9898
[self updateSelectedViewControllerIfNeeded];
9999
[self updateTabBarAppearanceIfNeeded];
100+
[self updateTabBarA11yIfNeeded];
100101
[self updateOrientationIfNeeded];
101102
}
102103

@@ -184,6 +185,20 @@ - (void)updateTabBarAppearance
184185
imageLoader:[self.tabsHostComponentView reactImageLoader]];
185186
}
186187

188+
- (void)updateTabBarA11yIfNeeded
189+
{
190+
for (RNSTabsScreenViewController *tabViewController in self.viewControllers) {
191+
auto screenView = static_cast<RNSBottomTabsScreenComponentView *>(tabViewController.tabScreenComponentView);
192+
if (!screenView.tabBarItemNeedsA11yUpdate) {
193+
continue;
194+
}
195+
196+
screenView.tabBarItemNeedsA11yUpdate = NO;
197+
tabViewController.tabBarItem.accessibilityIdentifier = screenView.tabItemTestID;
198+
tabViewController.tabBarItem.accessibilityLabel = screenView.tabItemAccessibilityLabel;
199+
}
200+
}
201+
187202
#if !defined(NDEBUG)
188203
- (void)assertExactlyOneFocusedTab
189204
{

ios/bottom-tabs/screen/RNSBottomTabsScreenComponentView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ NS_ASSUME_NONNULL_BEGIN
8787

8888
@property (nonatomic, readonly) BOOL overrideScrollViewContentInsetAdjustmentBehavior;
8989

90+
@property (nonatomic, nullable) NSString *tabItemTestID;
91+
@property (nonatomic, nullable) NSString *tabItemAccessibilityLabel;
92+
@property (nonatomic) BOOL tabBarItemNeedsA11yUpdate;
93+
9094
@property (nonatomic) RNSScrollEdgeEffect bottomScrollEdgeEffect;
9195
@property (nonatomic) RNSScrollEdgeEffect leftScrollEdgeEffect;
9296
@property (nonatomic) RNSScrollEdgeEffect rightScrollEdgeEffect;

ios/bottom-tabs/screen/RNSBottomTabsScreenComponentView.mm

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
260260
bool tabBarItemNeedsRecreation{false};
261261
bool tabBarItemNeedsUpdate{false};
262262
bool scrollEdgeEffectsNeedUpdate{false};
263-
bool tabBarItemNeedsA11yUpdate{false};
264263

265264
if (newComponentProps.title != oldComponentProps.title ||
266265
newComponentProps.isTitleUndefined != oldComponentProps.isTitleUndefined) {
@@ -297,14 +296,13 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
297296
}
298297

299298
if (newComponentProps.tabBarItemTestID != oldComponentProps.tabBarItemTestID) {
300-
_controller.tabItemTestID = RCTNSStringFromStringNilIfEmpty(newComponentProps.tabBarItemTestID);
301-
tabBarItemNeedsA11yUpdate = YES;
299+
_tabItemTestID = RCTNSStringFromStringNilIfEmpty(newComponentProps.tabBarItemTestID);
300+
_tabBarItemNeedsA11yUpdate = YES;
302301
}
303302

304303
if (newComponentProps.tabBarItemAccessibilityLabel != oldComponentProps.tabBarItemAccessibilityLabel) {
305-
_controller.tabItemAccessibilityLabel =
306-
RCTNSStringFromStringNilIfEmpty(newComponentProps.tabBarItemAccessibilityLabel);
307-
tabBarItemNeedsA11yUpdate = YES;
304+
_tabItemAccessibilityLabel = RCTNSStringFromStringNilIfEmpty(newComponentProps.tabBarItemAccessibilityLabel);
305+
_tabBarItemNeedsA11yUpdate = YES;
308306
}
309307

310308
if (newComponentProps.standardAppearance != oldComponentProps.standardAppearance) {
@@ -426,6 +424,7 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
426424
if (tabBarItemNeedsRecreation) {
427425
[self createTabBarItem];
428426
tabBarItemNeedsUpdate = YES;
427+
_tabBarItemNeedsA11yUpdate = YES;
429428
}
430429

431430
if (tabBarItemNeedsUpdate) {
@@ -435,10 +434,6 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
435434
tabItemNeedsAppearanceUpdate = YES;
436435
}
437436

438-
if (tabBarItemNeedsA11yUpdate) {
439-
[_controller updateTabItemA11yProps];
440-
}
441-
442437
if (tabItemNeedsAppearanceUpdate) {
443438
[_controller tabItemAppearanceHasChanged];
444439
}

ios/bottom-tabs/screen/RNSTabsScreenViewController.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ NS_ASSUME_NONNULL_BEGIN
1717

1818
@property (nonatomic, strong, readonly, nullable) RNSBottomTabsScreenComponentView *tabScreenComponentView;
1919
@property (nonatomic, weak, readonly, nullable) id<RNSBottomTabsSpecialEffectsSupporting> tabsSpecialEffectsDelegate;
20-
@property (nonatomic, nullable) NSString *tabItemTestID;
21-
@property (nonatomic, nullable) NSString *tabItemAccessibilityLabel;
2220

2321
/**
2422
* Tell the controller that the tab screen it owns has got its react-props-focus changed.

ios/bottom-tabs/screen/RNSTabsScreenViewController.mm

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,6 @@ - (RNSOrientation)evaluateOrientation
130130
return self.tabScreenComponentView.orientation;
131131
}
132132

133-
- (void)updateTabItemA11yProps
134-
{
135-
self.tabBarItem.accessibilityIdentifier = _tabItemTestID;
136-
self.tabBarItem.accessibilityLabel = _tabItemAccessibilityLabel;
137-
}
138-
139133
#endif // !TARGET_OS_TV
140134

141135
@end

0 commit comments

Comments
 (0)