Skip to content

Commit 46c77dc

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Fix crash inside RCTRedBox when trying to present same UIViewController twice
Summary: Calling `-[RCTRedBox showErrorMessage]` twice causes a crash We used `-[UIViewController isBeingPresented]` to tell whether view controller is already presented. But from the documentation: > A Boolean value indicating whether the view controller is being presented. Source: https://developer.apple.com/documentation/uikit/uiviewcontroller/2097564-beingpresented?language=objc# --- So this means that if you present it, wait until presentation animation is finished and then call `-[RCTRedBox showErrorMessage]` again, following exception will be thrown. ``` *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <UIViewController: 0x7fc33e422f50>.' ``` Changelog: Fix crash caused by presenting view controller twice from RCTRedBox Reviewed By: PeteTheHeat Differential Revision: D20946645 fbshipit-source-id: 763066e37db4e56efb0118b2e7867ad0724bae81
1 parent 8988a07 commit 46c77dc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

React/CoreModules/RCTRedBox.mm

+4-3
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,11 @@ - (void)showErrorMessage:(NSString *)message
235235
// Remove ANSI color codes from the message
236236
NSString *messageWithoutAnsi = [self stripAnsi:message];
237237

238+
BOOL isRootViewControllerPresented = self.rootViewController.presentingViewController != nil;
238239
// Show if this is a new message, or if we're updating the previous message
239-
BOOL isNew = !self.rootViewController.isBeingPresented && !isUpdate;
240+
BOOL isNew = !isRootViewControllerPresented && !isUpdate;
240241
BOOL isUpdateForSameMessage = !isNew &&
241-
(self.rootViewController.isBeingPresented && isUpdate &&
242+
(isRootViewControllerPresented && isUpdate &&
242243
((errorCookie == -1 && [_lastErrorMessage isEqualToString:messageWithoutAnsi]) ||
243244
(errorCookie == _lastErrorCookie)));
244245
if (isNew || isUpdateForSameMessage) {
@@ -250,7 +251,7 @@ - (void)showErrorMessage:(NSString *)message
250251

251252
[_stackTraceTableView reloadData];
252253

253-
if (!self.rootViewController.isBeingPresented) {
254+
if (!isRootViewControllerPresented) {
254255
[_stackTraceTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
255256
atScrollPosition:UITableViewScrollPositionTop
256257
animated:NO];

0 commit comments

Comments
 (0)