mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8988a073b4
commit
46c77dc296
@@ -235,10 +235,11 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)
|
||||
// Remove ANSI color codes from the message
|
||||
NSString *messageWithoutAnsi = [self stripAnsi:message];
|
||||
|
||||
BOOL isRootViewControllerPresented = self.rootViewController.presentingViewController != nil;
|
||||
// Show if this is a new message, or if we're updating the previous message
|
||||
BOOL isNew = !self.rootViewController.isBeingPresented && !isUpdate;
|
||||
BOOL isNew = !isRootViewControllerPresented && !isUpdate;
|
||||
BOOL isUpdateForSameMessage = !isNew &&
|
||||
(self.rootViewController.isBeingPresented && isUpdate &&
|
||||
(isRootViewControllerPresented && isUpdate &&
|
||||
((errorCookie == -1 && [_lastErrorMessage isEqualToString:messageWithoutAnsi]) ||
|
||||
(errorCookie == _lastErrorCookie)));
|
||||
if (isNew || isUpdateForSameMessage) {
|
||||
@@ -250,7 +251,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)
|
||||
|
||||
[_stackTraceTableView reloadData];
|
||||
|
||||
if (!self.rootViewController.isBeingPresented) {
|
||||
if (!isRootViewControllerPresented) {
|
||||
[_stackTraceTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
||||
atScrollPosition:UITableViewScrollPositionTop
|
||||
animated:NO];
|
||||
|
||||
Reference in New Issue
Block a user