1616#import < React/RCTRedBoxExtraDataViewController.h>
1717#import < React/RCTReloadCommand.h>
1818#import < React/RCTUtils.h>
19+ #import < react/featureflags/ReactNativeFeatureFlags.h>
1920
2021#import " CoreModulesPlugins.h"
22+ #import " RCTRedBox+Internal.h"
23+ #import " RCTRedBox2Controller+Internal.h"
2124#import " RCTRedBoxController+Internal.h"
2225
2326#if RCT_DEV_MENU
@@ -30,7 +33,7 @@ @interface RCTRedBox () <
3033@end
3134
3235@implementation RCTRedBox {
33- RCTRedBoxController * _controller;
36+ id <RCTRedBoxControlling> _controller;
3437 NSMutableArray <id <RCTErrorCustomizer>> *_errorCustomizers;
3538 RCTRedBoxExtraDataViewController *_extraDataViewController;
3639 NSMutableArray <NSString *> *_customButtonTitles;
@@ -178,14 +181,20 @@ - (void)showErrorMessage:(NSString *)message
178181 [[self ->_moduleRegistry moduleForName: " EventDispatcher" ] sendDeviceEventWithName: @" collectRedBoxExtraData"
179182 body: nil ];
180183#pragma clang diagnostic pop
181- if (!self->_controller ) {
182- self->_controller = [[RCTRedBoxController alloc ] initWithCustomButtonTitles: self ->_customButtonTitles
183- customButtonHandlers: self ->_customButtonHandlers];
184- self->_controller .actionDelegate = self;
185- }
186184
187185 RCTErrorInfo *errorInfo = [[RCTErrorInfo alloc ] initWithErrorMessage: message stack: stack];
188186 errorInfo = [self _customizeError: errorInfo];
187+
188+ if (self->_controller == nullptr ) {
189+ if (facebook::react::ReactNativeFeatureFlags::redBoxV2IOS ()) {
190+ self->_controller = [[RCTRedBox2Controller alloc ] initWithCustomButtonTitles: self ->_customButtonTitles
191+ customButtonHandlers: self ->_customButtonHandlers];
192+ } else {
193+ self->_controller = [[RCTRedBoxController alloc ] initWithCustomButtonTitles: self ->_customButtonTitles
194+ customButtonHandlers: self ->_customButtonHandlers];
195+ }
196+ self->_controller .actionDelegate = self;
197+ }
189198 [self ->_controller showErrorMessage: errorInfo.errorMessage
190199 withStack: errorInfo.stack
191200 isUpdate: isUpdate
@@ -196,9 +205,10 @@ - (void)showErrorMessage:(NSString *)message
196205- (void )loadExtraDataViewController
197206{
198207 dispatch_async (dispatch_get_main_queue (), ^{
208+ UIViewController *controller = static_cast <UIViewController *>(self->_controller );
199209 // Make sure the CMD+E shortcut doesn't call this twice
200- if (self->_extraDataViewController != nil && ![ self ->_controller presentedViewController ]) {
201- [self ->_controller presentViewController: self ->_extraDataViewController animated: YES completion: nil ];
210+ if (self->_extraDataViewController != nil && ([controller presentedViewController ] == nullptr ) ) {
211+ [controller presentViewController: self ->_extraDataViewController animated: YES completion: nil ];
202212 }
203213 });
204214}
@@ -220,7 +230,7 @@ - (void)invalidate
220230 [self dismiss ];
221231}
222232
223- - (void )redBoxController : (__unused RCTRedBoxController *)redBoxController
233+ - (void )redBoxController : (__unused UIViewController *)redBoxController
224234 openStackFrameInEditor : (RCTJSStackFrame *)stackFrame
225235{
226236 NSURL *const bundleURL = _overrideBundleURL ?: _bundleManager.bundleURL ;
@@ -247,7 +257,7 @@ - (void)reload
247257 [self reloadFromRedBoxController: nil ];
248258}
249259
250- - (void )reloadFromRedBoxController : (__unused RCTRedBoxController *)redBoxController
260+ - (void )reloadFromRedBoxController : (__unused UIViewController *)redBoxController
251261{
252262 if (_overrideReloadAction) {
253263 _overrideReloadAction ();
0 commit comments