Skip to content

Commit b6c325b

Browse files
authored
refactor(iOS): simplify code structure in "finish" block in modal update code (#2961)
## Description There is no reason to introduce a branch there, just makes the code harder to read. See the diff. ## Test code and steps to reproduce N/A ## Checklist - [ ] Ensured that CI passes
1 parent d4c2522 commit b6c325b

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

ios/RNSScreenStack.mm

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -475,45 +475,46 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
475475
}
476476
BOOL isAttached =
477477
changeRootController.parentViewController != nil || changeRootController.presentingViewController != nil;
478+
478479
if (!isAttached || changeRootIndex >= controllers.count) {
479480
// if change controller view is not attached, presenting modals will silently fail on iOS.
480481
// In such a case we trigger controllers update from didMoveToWindow.
481482
// We also don't run any present transitions if changeRootIndex is greater or equal to the size
482483
// of new controllers array. This means that no new controllers should be presented.
483484
afterTransitions();
484485
return;
485-
} else {
486-
UIViewController *previous = changeRootController;
486+
}
487487

488-
for (NSUInteger i = changeRootIndex; i < controllers.count; i++) {
489-
UIViewController *next = controllers[i];
490-
BOOL lastModal = (i == controllers.count - 1);
488+
UIViewController *previous = changeRootController;
491489

492-
// Inherit UI style from its parent - solves an issue with incorrect style being applied to some UIKit views
493-
// like date picker or segmented control.
494-
next.overrideUserInterfaceStyle = self->_controller.overrideUserInterfaceStyle;
490+
for (NSUInteger i = changeRootIndex; i < controllers.count; i++) {
491+
UIViewController *next = controllers[i];
492+
BOOL lastModal = (i == controllers.count - 1);
495493

496-
BOOL shouldAnimate = lastModal && [next isKindOfClass:[RNSScreen class]] &&
497-
((RNSScreen *)next).screenView.stackAnimation != RNSScreenStackAnimationNone;
494+
// Inherit UI style from its parent - solves an issue with incorrect style being applied to some UIKit views
495+
// like date picker or segmented control.
496+
next.overrideUserInterfaceStyle = self->_controller.overrideUserInterfaceStyle;
498497

499-
// if you want to present another modal quick enough after dismissing the previous one,
500-
// it will result in wrong changeRootController, see repro in
501-
// https://github.com/software-mansion/react-native-screens/issues/1299 We call `updateContainer` again in
502-
// `presentationControllerDidDismiss` to cover this case and present new controller
503-
if (previous.beingDismissed) {
504-
return;
505-
}
498+
BOOL shouldAnimate = lastModal && [next isKindOfClass:[RNSScreen class]] &&
499+
((RNSScreen *)next).screenView.stackAnimation != RNSScreenStackAnimationNone;
506500

507-
[previous presentViewController:next
508-
animated:shouldAnimate
509-
completion:^{
510-
[weakSelf.presentedModals addObject:next];
511-
if (lastModal) {
512-
afterTransitions();
513-
};
514-
}];
515-
previous = next;
501+
// if you want to present another modal quick enough after dismissing the previous one,
502+
// it will result in wrong changeRootController, see repro in
503+
// https://github.com/software-mansion/react-native-screens/issues/1299 We call `updateContainer` again in
504+
// `presentationControllerDidDismiss` to cover this case and present new controller
505+
if (previous.beingDismissed) {
506+
return;
516507
}
508+
509+
[previous presentViewController:next
510+
animated:shouldAnimate
511+
completion:^{
512+
[weakSelf.presentedModals addObject:next];
513+
if (lastModal) {
514+
afterTransitions();
515+
};
516+
}];
517+
previous = next;
517518
}
518519
};
519520

0 commit comments

Comments
 (0)