Skip to content

Commit 0c37478

Browse files
authored
fix(iOS, Tabs): fix diverging behavior of JS updates requesting moreNavigationController on various Apple platforms (#3813)
Fix-up `moreNavigationController` handling on platforms where it is not available I've introduced a bug in [#3785](https://github.com/software-mansion/react-native-screens/pull/3785/changes#diff-24866ece8ac586353673ecc0296de6ac8be5c1df28f12039774c9580bd5750d3). If the code runs on a platform where `moreNavigationController` is not available, the whole code for handling update requesting the `moreNavigationController` won't execute - the update will not be rejected as on other platforms, but rather the asserts will crash (in debug).
1 parent 4ac9ca1 commit 0c37478

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

ios/tabs/host/RNSTabBarController.mm

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,20 +349,19 @@ - (void)updateSelectedViewController
349349
UIViewController *nextSelectedViewController = nil;
350350
BOOL isNextMoreNavigationController = NO;
351351

352-
#if RNS_MORE_NAVIGATION_CONTROLLER_AVAILABLE
353352
if ([self isMoreNavigationControllerRequestedByOperation:_pendingOperation]) {
354353
if (![self isMoreNavigationControllerPresentInTabBar]) {
355354
// If the controller is not visible atm. we'll crash the app.
356355
// TODO: Emit rejection event
357356
_pendingOperation = nil;
358357
return;
359358
}
360-
nextSelectedViewController = self.moreNavigationController;
359+
nextSelectedViewController = [self resolveMoreNavigationController];
360+
RCTAssert(nextSelectedViewController != nil, @"[RNScreens] Expected non-nil moreNavigationController");
361361
isNextMoreNavigationController = YES;
362362
} else {
363363
nextSelectedViewController = [self findChildViewControllerForKey:nextSelectedViewControllerKey];
364364
}
365-
#endif // RNS_MORE_NAVIGATION_CONTROLLER_AVAILABLE
366365

367366
RCTAssert(
368367
nextSelectedViewController != nil,
@@ -605,6 +604,23 @@ - (void)setupMoreNavigationControllerDelegateIfNeeded
605604
#endif // RNS_MORE_NAVIGATION_CONTROLLER_AVAILABLE
606605
}
607606

607+
/**
608+
* This method allows getting the `moreNavigationController` instance under a couple of conditions.
609+
*
610+
* First, it verifies whether we are on an appropriate platform, where the `moreNavigationController`
611+
* is available.
612+
* Second, it verifies whether the `moreNavigationController` can even be in the interface right now.
613+
*/
614+
- (nullable UINavigationController *)resolveMoreNavigationController
615+
{
616+
#if RNS_MORE_NAVIGATION_CONTROLLER_AVAILABLE
617+
if ([self canHaveMoreNavigationController]) {
618+
return self.moreNavigationController;
619+
}
620+
#endif // RNS_MORE_NAVIGATION_CONTROLLER_AVAILABLE
621+
return nil;
622+
}
623+
608624
#if !RCT_NEW_ARCH_ENABLED
609625

610626
#pragma mark - LEGACY Paper scheduling methods

0 commit comments

Comments
 (0)