mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Call RCTInitializing initialize on NativeModules
Summary: After D28435078, NativeModules can conform to the RCTInitializing protocol, and implement the `-(void)initialize` method. This diff makes the NativeModule system execute the module's initialize method after the infra is done setting it up. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D28435430 fbshipit-source-id: 1ce00c3fb3c63b024d7e24895ff96c541a6fa654
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9b45df1fce
commit
269fefb065
@@ -15,6 +15,7 @@
|
||||
|
||||
#import "RCTBridge+Private.h"
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTInitializing.h"
|
||||
#import "RCTLog.h"
|
||||
#import "RCTModuleMethod.h"
|
||||
#import "RCTProfile.h"
|
||||
@@ -52,6 +53,7 @@ BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled()
|
||||
RCTViewRegistry *_viewRegistry_DEPRECATED;
|
||||
RCTBundleManager *_bundleManager;
|
||||
RCTCallableJSModules *_callableJSModules;
|
||||
BOOL _isInitialized;
|
||||
}
|
||||
|
||||
@synthesize methods = _methods;
|
||||
@@ -222,6 +224,10 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init);
|
||||
}
|
||||
|
||||
[self setUpMethodQueue];
|
||||
|
||||
if (shouldSetup) {
|
||||
[self _initializeModule];
|
||||
}
|
||||
}
|
||||
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");
|
||||
|
||||
@@ -335,6 +341,14 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_initializeModule
|
||||
{
|
||||
if (!_isInitialized && [_instance respondsToSelector:@selector(initialize)]) {
|
||||
_isInitialized = YES;
|
||||
[(id<RCTInitializing>)_instance initialize];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)finishSetupForInstance
|
||||
{
|
||||
if (!_setupComplete && _instance) {
|
||||
|
||||
Reference in New Issue
Block a user