Skip to content

Commit ea98952

Browse files
committed
feat(bottom-tabs,iOS): throw error on more than single focused tab in debug mode (#16)
## Description Added assertion, verifying that only a single tab is focused. The assertion is currently enabled only in debug mode. ## Test code and steps to reproduce Pass `isFocused={true}` to two tabs. ## Checklist - [ ] Ensured that CI passes
1 parent fe01c99 commit ea98952

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ios/bottom-tabs/RNSTabBarController.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ - (void)updateSelectedViewController
8888
{
8989
_needsUpdateOfSelectedTab = false;
9090

91+
#if !defined(NDEBUG)
92+
[self assertExactlyOneFocusedTab];
93+
#endif
94+
9195
UIViewController *_Nullable selectedViewController = nil;
9296
for (RNSTabsScreenViewController *tabViewController in self.viewControllers) {
9397
NSLog(
@@ -132,4 +136,18 @@ - (void)updateTabBarAppearance
132136
tabScreenControllers:_tabScreenControllers];
133137
}
134138

139+
#if !defined(NDEBUG)
140+
- (void)assertExactlyOneFocusedTab
141+
{
142+
int selectedCount = 0;
143+
for (RNSTabsScreenViewController *tabViewController in _tabScreenControllers) {
144+
if (tabViewController.tabScreenComponentView.isFocused) {
145+
++selectedCount;
146+
}
147+
}
148+
RCTAssert(
149+
selectedCount == 1, @"[RNScreens] Invariant violation. Expected exactly 1 focused tab, got: %d", selectedCount);
150+
}
151+
#endif
152+
135153
@end

0 commit comments

Comments
 (0)