Skip to content

Commit

Permalink
Added RCTJSINativeModule protocol to allow enabling JSI-bound nativem…
Browse files Browse the repository at this point in the history
…odule

Summary:
Instead of asking existing modules to implement `+allowJSIBinding`, introduce a temporary "empty" protocol so modules can just adopt it for migration purpose.

Eventually this protocol may just go away.

Modules need to adopt both `RCTBridgeModule` and `RCTJSINativeModule` for time being for backward compatibility.

p.s. the entire system isn't enabled yet, this is just some of the pre-reqs for NativeModule improvements.

Reviewed By: mmmulani

Differential Revision: D9762913

fbshipit-source-id: 470f640f11a5991e5cfa9c48a1931da660ebfcd2
  • Loading branch information
fkgozali authored and facebook-github-bot committed Sep 11, 2018
1 parent adaeba2 commit 6052e97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions React/Base/RCTBridgeModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,6 @@ RCT_EXTERN void RCTRegisterModule(Class); \
*/
+ (BOOL)requiresMainQueueSetup;

/**
* Experimental.
* If YES, this module will be set up via JSI binding instead.
*/
+ (BOOL)allowJSIBinding;

/**
* Injects methods into JS. Entries in this array are used in addition to any
* methods defined using the macros above. This method is called only once,
Expand Down Expand Up @@ -327,3 +321,12 @@ RCT_EXTERN void RCTRegisterModule(Class); \
- (void)partialBatchDidFlush;

@end

/**
* Experimental.
* A protocol to declare that a class supports JSI-bound NativeModule.
* This may be removed in the future.
*/
@protocol RCTJSINativeModule <NSObject>

@end
2 changes: 1 addition & 1 deletion React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ - (void)_initializeBridge:(std::shared_ptr<JSExecutorFactory>)executorFactory
NSArray *moduleClassesCopy = [moduleClasses copy];
NSMutableArray<RCTModuleData *> *moduleDataByID = [NSMutableArray arrayWithCapacity:moduleClassesCopy.count];
for (Class moduleClass in moduleClassesCopy) {
if (RCTJSINativeModuleEnabled() && [moduleClass respondsToSelector:@selector(allowJSIBinding)] && [moduleClass allowJSIBinding]) {
if (RCTJSINativeModuleEnabled() && [moduleClass conformsToProtocol:@protocol(RCTJSINativeModule)]) {
continue;
}
NSString *moduleName = RCTBridgeModuleNameForClass(moduleClass);
Expand Down

0 comments on commit 6052e97

Please sign in to comment.