@@ -97,7 +97,7 @@ public interface CallbackWithBundleLoader {
97
97
private final DefaultNativeModuleCallExceptionHandler mDefaultNativeModuleCallExceptionHandler ;
98
98
private final DevLoadingViewController mDevLoadingViewController ;
99
99
100
- private @ Nullable RedBoxDialog mRedBoxDialog ;
100
+ private @ Nullable SurfaceDelegate mRedBoxSurfaceDelegate ;
101
101
private @ Nullable AlertDialog mDevOptionsDialog ;
102
102
private @ Nullable DebugOverlayController mDebugOverlayController ;
103
103
private boolean mDevLoadingViewVisible = false ;
@@ -273,7 +273,8 @@ public void registerErrorCustomizer(ErrorCustomizer errorCustomizer) {
273
273
mErrorCustomizers .add (errorCustomizer );
274
274
}
275
275
276
- private Pair <String , StackFrame []> processErrorCustomizers (Pair <String , StackFrame []> errorInfo ) {
276
+ @ Override
277
+ public Pair <String , StackFrame []> processErrorCustomizers (Pair <String , StackFrame []> errorInfo ) {
277
278
if (mErrorCustomizers == null ) {
278
279
return errorInfo ;
279
280
} else {
@@ -297,33 +298,25 @@ public void run() {
297
298
// Since we only show the first JS error in a succession of JS errors, make sure we only
298
299
// update the error message for that error message. This assumes that updateJSError
299
300
// belongs to the most recent showNewJSError
300
- if (mRedBoxDialog == null
301
- || !mRedBoxDialog .isShowing ()
302
- || errorCookie != mLastErrorCookie ) {
301
+ if (!mRedBoxSurfaceDelegate .isShowing () || errorCookie != mLastErrorCookie ) {
303
302
return ;
304
303
}
305
- StackFrame [] stack = StackTraceHelper .convertJsStackTrace (details );
306
- Pair <String , StackFrame []> errorInfo =
307
- processErrorCustomizers (Pair .create (message , stack ));
308
- mRedBoxDialog .setExceptionDetails (errorInfo .first , errorInfo .second );
309
- updateLastErrorInfo (message , stack , errorCookie , ErrorType .JS );
310
- // JS errors are reported here after source mapping.
311
- if (mRedBoxHandler != null ) {
312
- mRedBoxHandler .handleRedbox (message , stack , ErrorType .JS );
313
- mRedBoxDialog .resetReporting ();
314
- }
315
- mRedBoxDialog .show ();
304
+
305
+ // The RedBox surface delegate will always show the latest error
306
+ updateLastErrorInfo (
307
+ message , StackTraceHelper .convertJsStackTrace (details ), errorCookie , ErrorType .JS );
308
+ mRedBoxSurfaceDelegate .show ();
316
309
}
317
310
});
318
311
}
319
312
320
313
@ Override
321
314
public void hideRedboxDialog () {
322
- // dismiss redbox if exists
323
- if (mRedBoxDialog != null ) {
324
- mRedBoxDialog .dismiss ();
325
- mRedBoxDialog = null ;
315
+ if (mRedBoxSurfaceDelegate == null ) {
316
+ return ;
326
317
}
318
+
319
+ mRedBoxSurfaceDelegate .hide ();
327
320
}
328
321
329
322
public @ Nullable View createRootView (String appKey ) {
@@ -350,41 +343,27 @@ private void showNewError(
350
343
new Runnable () {
351
344
@ Override
352
345
public void run () {
353
- Activity context = mReactInstanceDevHelper .getCurrentActivity ();
354
- if (context != null && !context .isFinishing () && currentActivity != context ) {
355
- currentActivity = context ;
356
- // Create a new RedBox when currentActivity get updated
357
- mRedBoxDialog =
358
- new RedBoxDialog (currentActivity , DevSupportManagerBase .this , mRedBoxHandler );
359
- }
360
- if (currentActivity == null || currentActivity .isFinishing ()) {
361
- FLog .e (
362
- ReactConstants .TAG ,
363
- "Unable to launch redbox because react activity "
364
- + "is not available, here is the error that redbox would've displayed: "
365
- + message );
366
- return ;
367
- }
368
- if (mRedBoxDialog == null ) {
369
- mRedBoxDialog =
370
- new RedBoxDialog (currentActivity , DevSupportManagerBase .this , mRedBoxHandler );
346
+ if (mRedBoxSurfaceDelegate == null ) {
347
+ @ Nullable SurfaceDelegate redBoxSurfaceDelegate = createSurfaceDelegate ("RedBox" );
348
+ if (redBoxSurfaceDelegate != null ) {
349
+ mRedBoxSurfaceDelegate = redBoxSurfaceDelegate ;
350
+ } else {
351
+ mRedBoxSurfaceDelegate =
352
+ new RedBoxDialogSurfaceDelegate (DevSupportManagerBase .this );
353
+ }
354
+
355
+ mRedBoxSurfaceDelegate .createContentView ("RedBox" );
371
356
}
372
- if (mRedBoxDialog .isShowing ()) {
357
+
358
+ if (mRedBoxSurfaceDelegate .isShowing ()) {
373
359
// Sometimes errors cause multiple errors to be thrown in JS in quick succession. Only
374
360
// show the first and most actionable one.
375
361
return ;
376
362
}
377
- Pair <String , StackFrame []> errorInfo =
378
- processErrorCustomizers (Pair .create (message , stack ));
379
- mRedBoxDialog .setExceptionDetails (errorInfo .first , errorInfo .second );
363
+
364
+ // The RedBox surface delegate will always show the latest error
380
365
updateLastErrorInfo (message , stack , errorCookie , errorType );
381
- // Only report native errors here. JS errors are reported
382
- // inside {@link #updateJSError} after source mapping.
383
- if (mRedBoxHandler != null && errorType == ErrorType .NATIVE ) {
384
- mRedBoxHandler .handleRedbox (message , stack , ErrorType .NATIVE );
385
- }
386
- mRedBoxDialog .resetReporting ();
387
- mRedBoxDialog .show ();
366
+ mRedBoxSurfaceDelegate .show ();
388
367
}
389
368
});
390
369
}
@@ -623,6 +602,11 @@ public DevInternalSettings getDevSettings() {
623
602
return mDevSettings ;
624
603
}
625
604
605
+ @ Override
606
+ public RedBoxHandler getRedBoxHandler () {
607
+ return mRedBoxHandler ;
608
+ }
609
+
626
610
@ Override
627
611
public void onNewReactContextCreated (ReactContext reactContext ) {
628
612
resetCurrentContext (reactContext );
@@ -888,6 +872,11 @@ public void run() {
888
872
return mLastErrorStack ;
889
873
}
890
874
875
+ @ Override
876
+ public int getLastErrorCookie () {
877
+ return mLastErrorCookie ;
878
+ }
879
+
891
880
@ Override
892
881
public @ Nullable ErrorType getLastErrorType () {
893
882
return mLastErrorType ;
0 commit comments