Skip to content

Commit b5db214

Browse files
realsoelynnfacebook-github-bot
authored andcommitted
Deprecate RedBox from RCTBridge to RCTModuleRegistry (#43717)
Summary: Pull Request resolved: #43717 As we are going to bridgeless in new architecture, we want to clean up the usage of RCTBridge to use RCTModuleRegistry to access NativeModule. Changelog: [iOS][Breaking] Remove `RCTRedBox` access through `RCTBridge` Reviewed By: philIip Differential Revision: D55532209 fbshipit-source-id: 62aa2a24b60ab54d7f3cf25c34beda4449aaeaed
1 parent bf1a5d4 commit b5db214

File tree

5 files changed

+12
-58
lines changed

5 files changed

+12
-58
lines changed

packages/react-native/React/Base/RCTBridgeModule.h

+3
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ RCT_EXTERN_C_END
370370
- (id)moduleForName:(const char *)moduleName;
371371
- (id)moduleForName:(const char *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyLoad;
372372
- (BOOL)moduleIsInitialized:(Class)moduleClass;
373+
374+
// Note: This method lazily load the module as necessary.
375+
- (id)moduleForClass:(Class)moduleClass;
373376
@end
374377

375378
typedef UIView * (^RCTBridgelessComponentViewProvider)(NSNumber *);

packages/react-native/React/Base/RCTModuleRegistry.m

+5
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,9 @@ - (BOOL)moduleIsInitialized:(Class)moduleClass
6464
return NO;
6565
}
6666

67+
- (id)moduleForClass:(Class)moduleClass
68+
{
69+
return [self moduleForName:RCTBridgeModuleNameForClass(moduleClass).UTF8String];
70+
}
71+
6772
@end

packages/react-native/React/CoreModules/RCTRedBox.h

-18
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
#import <UIKit/UIKit.h>
99

10-
#import <React/RCTBridge.h>
1110
#import <React/RCTBridgeModule.h>
12-
#import <React/RCTBridgeProxy.h>
1311
#import <React/RCTErrorCustomizer.h>
1412

1513
@class RCTJSStackFrame;
@@ -48,19 +46,3 @@ typedef void (^RCTRedBoxButtonPressHandler)(void);
4846
@property (nonatomic, strong) dispatch_block_t overrideReloadAction;
4947

5048
@end
51-
52-
/**
53-
* This category makes the red box instance available via the RCTBridge, which
54-
* is useful for any class that needs to access the red box or error log.
55-
*/
56-
@interface RCTBridge (RCTRedBox)
57-
58-
@property (nonatomic, readonly) RCTRedBox *redBox;
59-
60-
@end
61-
62-
@interface RCTBridgeProxy (RCTRedBox)
63-
64-
@property (nonatomic, readonly) RCTRedBox *redBox;
65-
66-
@end

packages/react-native/React/CoreModules/RCTRedBox.mm

-38
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
#import "RCTRedBox.h"
99

1010
#import <FBReactNativeSpec/FBReactNativeSpec.h>
11-
#import <React/RCTBridge.h>
1211
#import <React/RCTConvert.h>
1312
#import <React/RCTDefines.h>
1413
#import <React/RCTErrorInfo.h>
1514
#import <React/RCTEventDispatcherProtocol.h>
1615
#import <React/RCTJSStackFrame.h>
1716
#import <React/RCTRedBoxExtraDataViewController.h>
18-
#import <React/RCTRedBoxSetEnabled.h>
1917
#import <React/RCTReloadCommand.h>
2018
#import <React/RCTUtils.h>
2119

@@ -712,24 +710,6 @@ - (void)addCustomButton:(NSString *)title onPressHandler:(RCTRedBoxButtonPressHa
712710

713711
@end
714712

715-
@implementation RCTBridge (RCTRedBox)
716-
717-
- (RCTRedBox *)redBox
718-
{
719-
return RCTRedBoxGetEnabled() ? [self moduleForClass:[RCTRedBox class]] : nil;
720-
}
721-
722-
@end
723-
724-
@implementation RCTBridgeProxy (RCTRedBox)
725-
726-
- (RCTRedBox *)redBox
727-
{
728-
return RCTRedBoxGetEnabled() ? [self moduleForClass:[RCTRedBox class]] : nil;
729-
}
730-
731-
@end
732-
733713
#else // Disabled
734714

735715
@interface RCTRedBox () <NativeRedBoxSpec>
@@ -806,24 +786,6 @@ - (void)addCustomButton:(NSString *)title onPressHandler:(RCTRedBoxButtonPressHa
806786

807787
@end
808788

809-
@implementation RCTBridge (RCTRedBox)
810-
811-
- (RCTRedBox *)redBox
812-
{
813-
return nil;
814-
}
815-
816-
@end
817-
818-
@implementation RCTBridgeProxy (RCTRedBox)
819-
820-
- (RCTRedBox *)redBox
821-
{
822-
return nil;
823-
}
824-
825-
@end
826-
827789
#endif
828790

829791
Class RCTRedBoxCls(void)

packages/react-native/React/CxxBridge/RCTCxxBridge.mm

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import <React/RCTPerformanceLogger.h>
3030
#import <React/RCTProfile.h>
3131
#import <React/RCTRedBox.h>
32+
#import <React/RCTRedBoxSetEnabled.h>
3233
#import <React/RCTReloadCommand.h>
3334
#import <React/RCTTurboModuleRegistry.h>
3435
#import <React/RCTUtils.h>
@@ -1085,7 +1086,8 @@ - (void)handleError:(NSError *)error
10851086

10861087
if (self->_valid && !self->_loading) {
10871088
if ([error userInfo][RCTJSRawStackTraceKey]) {
1088-
[self.redBox showErrorMessage:[error localizedDescription] withRawStack:[error userInfo][RCTJSRawStackTraceKey]];
1089+
RCTRedBox *redBox = RCTRedBoxGetEnabled() ? [self.moduleRegistry moduleForName:"RedBox"] : nil;
1090+
[redBox showErrorMessage:[error localizedDescription] withRawStack:[error userInfo][RCTJSRawStackTraceKey]];
10891091
}
10901092

10911093
RCTFatal(error);
@@ -1100,7 +1102,7 @@ - (void)handleError:(NSError *)error
11001102

11011103
// Hack: once the bridge is invalidated below, it won't initialize any new native
11021104
// modules. Initialize the redbox module now so we can still report this error.
1103-
RCTRedBox *redBox = [self redBox];
1105+
RCTRedBox *redBox = RCTRedBoxGetEnabled() ? [self.moduleRegistry moduleForName:"RedBox"] : nil;
11041106

11051107
_loading = NO;
11061108
_valid = NO;

0 commit comments

Comments
 (0)