Skip to content

Commit

Permalink
Fix it & hold it with a knee so it does not strike back
Browse files Browse the repository at this point in the history
  • Loading branch information
kkafar committed Nov 16, 2023
1 parent 1c8bd7c commit b01b67a
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,11 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
// for the duration of transition. There are couple of scenarios:
// (1) No modals are presented or all modals were presented by this RNSNavigationController,
// (2) There are modals presented by other RNSNavigationControllers (nested/outer)
NSUInteger changeRootIndex = 0;

// Last controller that is common for both _presentedModals & controllers
UIViewController *changeRootController = _controller;
// Last common controller index + 1
NSUInteger changeRootIndex = 0;
for (NSUInteger i = 0; i < MIN(_presentedModals.count, controllers.count); i++) {
if (_presentedModals[i] == controllers[i]) {
changeRootController = controllers[i];
Expand Down Expand Up @@ -457,6 +460,30 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
}
};

// if (changeRootController.presentedViewController != nil) {
// BOOL shouldAnimate = changeRootIndex == controllers.count &&
// [changeRootController.presentedViewController isKindOfClass:[RNSScreen class]] &&
// ((RNSScreen *)changeRootController.presentedViewController).screenView.stackAnimation !=
// RNSScreenStackAnimationNone;
//
// if ([_presentedModals containsObject:changeRootController.presentedViewController]) {
// BOOL shouldAnimate = changeRootIndex == controllers.count &&
// [changeRootController.presentedViewController isKindOfClass:[RNSScreen class]] &&
// ((RNSScreen *)changeRootController.presentedViewController).screenView.stackAnimation !=
// RNSScreenStackAnimationNone;
// [changeRootController dismissViewControllerAnimated:shouldAnimate completion:finish];
// } else if (newControllers.count > 0) {
// finish();
// } else {
// // So the currently presented view controller is not in _presentedModals ==> it was presented by
// // different stack ==> we need to apply the changes from there.
// // Please note that this code is not robust (TODO explanation)
// [changeRootController.presentedViewController dismissViewControllerAnimated:shouldAnimate completion:finish];
// }
// } else {
// finish();
// }

if (changeRootController.presentedViewController != nil &&
[_presentedModals containsObject:changeRootController.presentedViewController]) {
BOOL shouldAnimate = changeRootIndex == controllers.count &&
Expand All @@ -468,6 +495,16 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
// we present modals on top of changeRootController (which may be the this stack VC)
NSLog(@"StackView %p is dismissing all VCs on top of %p", self, changeRootController);
[changeRootController dismissViewControllerAnimated:shouldAnimate completion:finish];
} else if (
changeRootController.presentedViewController != nil &&
changeRootController.presentedViewController.presentedViewController != nil) {
BOOL shouldAnimate = changeRootIndex == controllers.count &&
[changeRootController.presentedViewController isKindOfClass:[RNSScreen class]] &&
((RNSScreen *)changeRootController.presentedViewController).screenView.stackAnimation !=
RNSScreenStackAnimationNone;
[changeRootController.presentedViewController.presentedViewController dismissViewControllerAnimated:shouldAnimate
completion:finish];
// RCTAssert(realVisibleViewController != nil, @"NO REAL VISIBLE VIEW CONTROLLER");
} else {
NSLog(@"StackView %p is only presenting new modals", self);
finish();
Expand Down

0 comments on commit b01b67a

Please sign in to comment.