diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m index 239973ca0..b90a384e4 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m @@ -16,6 +16,7 @@ #import #import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTContextExecutor.h" #import "RCTModuleMethod.h" #import "RCTRootView.h" @@ -29,12 +30,6 @@ while ((CONDITION) && [timeout timeIntervalSinceNow] > 0) { \ } \ _Pragma("clang diagnostic pop") -@interface RCTBridge (RCTAllocationTests) - -@property (nonatomic, weak) RCTBridge *batchedBridge; - -@end - @interface RCTJavaScriptContext : NSObject @property (nonatomic, assign, readonly) JSGlobalContextRef ctx; diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m index 54a58787e..1a0afe0bf 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m @@ -16,19 +16,11 @@ #import #import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTBridgeModule.h" #import "RCTJavaScriptExecutor.h" #import "RCTUtils.h" -@interface RCTBridge (Testing) - -@property (nonatomic, strong, readonly) RCTBridge *batchedBridge; - -- (void)handleBuffer:(id)buffer; -- (void)setUp; - -@end - @interface TestExecutor : NSObject @property (nonatomic, readonly, copy) NSMutableDictionary *injectedStuff; diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index 1999f32b0..21d35a6e1 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -11,6 +11,7 @@ #import "RCTAssert.h" #import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTBridgeMethod.h" #import "RCTConvert.h" #import "RCTContextExecutor.h" @@ -42,15 +43,6 @@ typedef NS_ENUM(NSUInteger, RCTBridgeFields) { RCT_EXTERN NSArray *RCTGetModuleClasses(void); -@interface RCTBridge () - -+ (instancetype)currentBridge; -+ (void)setCurrentBridge:(RCTBridge *)bridge; - -@property (nonatomic, copy, readonly) RCTBridgeModuleProviderBlock moduleProvider; - -@end - @interface RCTBatchedBridge : RCTBridge @property (nonatomic, weak) RCTBridge *parentBridge; diff --git a/React/Base/RCTBridge+Private.h b/React/Base/RCTBridge+Private.h new file mode 100644 index 000000000..bb87cc173 --- /dev/null +++ b/React/Base/RCTBridge+Private.h @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "RCTBridge.h" + +@class RCTModuleData; + +@interface RCTBridge () + ++ (instancetype)currentBridge; ++ (void)setCurrentBridge:(RCTBridge *)bridge; + +/** + * Bridge setup code - creates an instance of RCTBachedBridge. Exposed for + * test only + */ +- (void)setUp; + +/** + * This method is used to invoke a callback that was registered in the + * JavaScript application context. Safe to call from any thread. + */ +- (void)enqueueCallback:(NSNumber *)cbID args:(NSArray *)args; + +/** + * This property is mostly used on the main thread, but may be touched from + * a background thread if the RCTBridge happens to deallocate on a background + * thread. Therefore, we want all writes to it to be seen atomically. + */ +@property (atomic, strong) RCTBridge *batchedBridge; + +/** + * The block that creates the modules' instances to be added to the bridge. + * Exposed for the RCTBatchedBridge + */ +@property (nonatomic, copy, readonly) RCTBridgeModuleProviderBlock moduleProvider; + +@end + +@interface RCTBridge (RCTBatchedBridge) + +- (void)registerModuleForFrameUpdates:(RCTModuleData *)moduleData; + +/** + * Dispatch work to a module's queue - this is also suports the fake RCTJSThread + * queue. Exposed for the RCTProfiler + */ +- (void)dispatchBlock:(dispatch_block_t)block queue:(dispatch_queue_t)queue; + +/** + * Systrace profiler toggling methods exposed for the RCTDevMenu + */ +- (void)startProfiling; +- (void)stopProfiling:(void (^)(NSData *))callback; + +/** + * Executes native calls sent by JavaScript. Exposed for testing purposes only + */ +- (void)handleBuffer:(NSArray *)buffer; + +/** + * Exposed for the RCTContextExecutor for sending native methods called from + * JavaScript in the middle of a batch. + */ +- (void)handleBuffer:(NSArray *)buffer batchEnded:(BOOL)hasEnded; + +/** + * Exposed for the RCTContextExecutor for lazily loading native modules + */ +- (NSArray *)configForModuleName:(NSString *)moduleName; + +/** + * Hook exposed for RCTLog to send logs to JavaScript when not running in JSC + */ +- (void)logMessage:(NSString *)message level:(NSString *)level; + +/** + * Allow super fast, one time, timers to skip the queue and be directly executed + */ +- (void)_immediatelyCallTimer:(NSNumber *)timer; + +@end diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index c0b89be0a..1dfac45b3 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -7,7 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#import "RCTBridge.h" +#import "RCTBridge+Private.h" #import @@ -24,8 +24,6 @@ NSString *const RCTJavaScriptDidLoadNotification = @"RCTJavaScriptDidLoadNotific NSString *const RCTJavaScriptDidFailToLoadNotification = @"RCTJavaScriptDidFailToLoadNotification"; NSString *const RCTDidCreateNativeModules = @"RCTDidCreateNativeModules"; -@class RCTBatchedBridge; - @interface RCTBatchedBridge : RCTBridge @property (nonatomic, weak) RCTBridge *parentBridge; @@ -34,17 +32,6 @@ NSString *const RCTDidCreateNativeModules = @"RCTDidCreateNativeModules"; @end -@interface RCTBridge () - -// This property is mostly used on the main thread, but may be touched from -// a background thread if the RCTBridge happens to deallocate on a background -// thread. Therefore, we want all writes to it to be seen atomically. -@property (atomic, strong) RCTBatchedBridge *batchedBridge; - -@property (nonatomic, copy, readonly) RCTBridgeModuleProviderBlock moduleProvider; - -@end - static NSMutableArray *RCTModuleClasses; NSArray *RCTGetModuleClasses(void); NSArray *RCTGetModuleClasses(void) @@ -294,7 +281,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) - (void)invalidate { - RCTBatchedBridge *batchedBridge = self.batchedBridge; + RCTBatchedBridge *batchedBridge = (RCTBatchedBridge *)self.batchedBridge; self.batchedBridge = nil; if (batchedBridge) { @@ -304,20 +291,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) } } -- (void)logMessage:(NSString *)message level:(NSString *)level -{ - [self.batchedBridge logMessage:message level:level]; -} - - -#define RCT_INNER_BRIDGE_ONLY(...) \ -- (void)__VA_ARGS__ \ -{ \ - NSString *errorMessage = [NSString stringWithFormat:@"Called method \"%@\" on top level bridge. \ - This method should oly be called from bridge instance in a bridge module", @(__func__)]; \ - RCTFatal(RCTErrorWithMessage(errorMessage)); \ -} - - (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args { [self.batchedBridge enqueueJSCall:moduleDotMethod args:args]; diff --git a/React/Base/RCTLog.m b/React/Base/RCTLog.m index f09aff78b..28562bde2 100644 --- a/React/Base/RCTLog.m +++ b/React/Base/RCTLog.m @@ -13,16 +13,10 @@ #import "RCTAssert.h" #import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTDefines.h" #import "RCTRedBox.h" -@interface RCTBridge () - -+ (RCTBridge *)currentBridge; -- (void)logMessage:(NSString *)message level:(NSString *)level; - -@end - static NSString *const RCTLogFunctionStack = @"RCTLogFunctionStack"; const char *RCTLogLevels[] = { diff --git a/React/Base/RCTModuleData.m b/React/Base/RCTModuleData.m index d254509a7..d247f532f 100644 --- a/React/Base/RCTModuleData.m +++ b/React/Base/RCTModuleData.m @@ -10,16 +10,11 @@ #import "RCTModuleData.h" #import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTModuleMethod.h" #import "RCTLog.h" #import "RCTUtils.h" -@interface RCTBridge (Private) - -- (void)registerModuleForFrameUpdates:(RCTModuleData *)moduleData; - -@end - @implementation RCTModuleData { NSString *_queueName; diff --git a/React/Base/RCTModuleMethod.m b/React/Base/RCTModuleMethod.m index 407fed3da..8f54f2d9e 100644 --- a/React/Base/RCTModuleMethod.m +++ b/React/Base/RCTModuleMethod.m @@ -13,6 +13,7 @@ #import "RCTAssert.h" #import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTConvert.h" #import "RCTLog.h" #import "RCTParserUtils.h" @@ -36,16 +37,6 @@ typedef BOOL (^RCTArgumentBlock)(RCTBridge *, NSUInteger, id); @end -@interface RCTBridge (RCTModuleMethod) - -/** - * This method is used to invoke a callback that was registered in the - * JavaScript application context. Safe to call from any thread. - */ -- (void)enqueueCallback:(NSNumber *)cbID args:(NSArray *)args; - -@end - @implementation RCTModuleMethod { Class _moduleClass; diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 454e2e317..f53c278b3 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -14,7 +14,7 @@ #import #import "RCTAssert.h" -#import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTEventDispatcher.h" #import "RCTKeyCommands.h" #import "RCTLog.h" @@ -28,12 +28,6 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotification"; -@interface RCTBridge (RCTRootView) - -@property (nonatomic, weak, readonly) RCTBridge *batchedBridge; - -@end - @interface RCTUIManager (RCTRootView) - (NSNumber *)allocateRootTag; diff --git a/React/Executors/RCTContextExecutor.m b/React/Executors/RCTContextExecutor.m index 0d2d181de..5d8504fb2 100644 --- a/React/Executors/RCTContextExecutor.m +++ b/React/Executors/RCTContextExecutor.m @@ -15,6 +15,7 @@ #import #import "RCTAssert.h" +#import "RCTBridge+Private.h" #import "RCTDefines.h" #import "RCTDevMenu.h" #import "RCTLog.h" @@ -83,14 +84,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) @end -// Private bridge interface -@interface RCTBridge (RCTContextExecutor) - -- (void)handleBuffer:(NSArray *)buffer batchEnded:(BOOL)hasEnded; -- (NSArray *)configForModuleName:(NSString *)moduleName; - -@end - @implementation RCTContextExecutor { RCTJavaScriptContext *_context; diff --git a/React/Modules/RCTDevMenu.m b/React/Modules/RCTDevMenu.m index dd66c900b..5d98f8ad4 100644 --- a/React/Modules/RCTDevMenu.m +++ b/React/Modules/RCTDevMenu.m @@ -10,7 +10,7 @@ #import "RCTDevMenu.h" #import "RCTAssert.h" -#import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTDefines.h" #import "RCTEventDispatcher.h" #import "RCTKeyCommands.h" @@ -22,13 +22,6 @@ #if RCT_DEV -@interface RCTBridge (Profiling) - -- (void)startProfiling; -- (void)stopProfiling:(void (^)(NSData *))callback; - -@end - static NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification"; static NSString *const RCTDevMenuSettingsKey = @"RCTDevMenu"; diff --git a/React/Modules/RCTTiming.m b/React/Modules/RCTTiming.m index fc2d9e716..3aa084d30 100644 --- a/React/Modules/RCTTiming.m +++ b/React/Modules/RCTTiming.m @@ -11,18 +11,10 @@ #import "RCTAssert.h" #import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTLog.h" #import "RCTUtils.h" -@interface RCTBridge (Private) - -/** - * Allow super fast, one time, timers to skip the queue and be directly executed - */ -- (void)_immediatelyCallTimer:(NSNumber *)timer; - -@end - @interface RCTTimer : NSObject @property (nonatomic, strong, readonly) NSDate *target; diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index a51b099c2..9cc0ae1d9 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -20,6 +20,7 @@ #import "RCTAssert.h" #import "RCTBridge.h" +#import "RCTBridge+Private.h" #import "RCTComponentData.h" #import "RCTDefines.h" #import "RCTLog.h" @@ -32,13 +33,6 @@ NSString *const RCTProfileDidEndProfiling = @"RCTProfileDidEndProfiling"; #if RCT_DEV -@interface RCTBridge () - -- (void)dispatchBlock:(dispatch_block_t)block - queue:(dispatch_queue_t)queue; - -@end - #pragma mark - Constants NSString const *RCTProfileTraceEvents = @"traceEvents"; diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index c7f7294cc..fa4397f54 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -221,6 +221,7 @@ 1450FF831BCFF28A00208362 /* RCTProfileTrampoline-arm64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = "RCTProfileTrampoline-arm64.S"; sourceTree = ""; }; 1450FF851BCFF28A00208362 /* RCTProfileTrampoline-x86_64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = "RCTProfileTrampoline-x86_64.S"; sourceTree = ""; }; 1482F9E61B55B927000ADFF3 /* RCTBridgeDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTBridgeDelegate.h; sourceTree = ""; }; + 14A43DB81C1F849600794BC8 /* RCTBridge+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTBridge+Private.h"; sourceTree = ""; }; 14BF717F1C04793D00C97D0C /* RCTProfileTrampoline-i386.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = "RCTProfileTrampoline-i386.S"; sourceTree = ""; }; 14BF71811C04795500C97D0C /* RCTMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTMacros.h; sourceTree = ""; }; 14C2CA6F1B3AC63800E6CBB2 /* RCTModuleMethod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTModuleMethod.h; sourceTree = ""; }; @@ -538,6 +539,7 @@ 83CBBA501A601E3B00E9B192 /* RCTUtils.m */, 13BB3D001BECD54500932C10 /* RCTImageSource.h */, 13BB3D011BECD54500932C10 /* RCTImageSource.m */, + 14A43DB81C1F849600794BC8 /* RCTBridge+Private.h */, ); path = Base; sourceTree = "";