react-native-macos/React/Base
Ramanpreet Nara 0ceefb40d5 Enable module lookup in TurboModules
Summary:
NativeModules are instantiated by the bridge. If they choose, they can capture the bridge instance that instantiated them. From within the NativeModule, the bridge can then be used to lookup other NativeModules. TurboModules have no way to do such a lookup.

Both NativeModules and TurboModules need to be able to query for one another. Therefore, we have four cases:
1. NativeModule accesses NativeModule.
2. NativeModule accesses TurboModule.
3. TurboModule accesses NativeModule.
4. TurboModule accesses TurboModule.

In summary, this solution extends the bridge to support querying TurboModules. It also introduces a `RCTTurboModuleLookupDelegate` protocol, which, implemented by `RCTTurboModuleManager`, supports querying TurboModules:
```
protocol RCTTurboModuleLookupDelegate <NSObject>
- (id)moduleForName:(NSString *)moduleName;
- (id)moduleForName:(NSString *)moduleName warnOnLookupFailure:(BOOL)warnOnLookupFailure;
- (BOOL)moduleIsInitialized:(NSString *)moduleName
end
```

If TurboModules want to query other TurboModules, then they need to implement this protocol and synthesize `turboModuleLookupDelegate`:

```
protocol RCTTurboModuleWithLookupCapabilities
property (nonatomic, weak) id<RCTTurboModuleLookupDelegate> turboModuleLookupDelegate;
end
```

NativeModules will continue to use `RCTBridge` to access other NativeModules. Nothing needs to change.

When we attach the bridge to `RCTTurboModuleManager`, we also attach `RCTTurboModuleManager` to the bridge as a `RCTTurboModuleLookupDelegate`. This allows the bridge to query TurboModules, which enables our NativeModules to transparently (i.e: without any NativeModule code modification) query TurboModules.

In an ideal world, all modules would be TurboModules. Until then, we're going to require that TurboModules use the bridge to query for NativeModules or TurboModules.

`RCTTurboModuleManager` keeps a map of all TurboModules that we instantiated. We simply search in this map and return the TurboModule.

This setup allows us to switch NativeModules to TurboModules without compromising their ability to use the bridge to search for other NativeModules (and TurboModules). When we write new TurboModules, we can have them use `RCTTurboModuleLookupDelegate` to do access other TurboModules. Eventually, after we migrate all NativeModules to TurboModules, we can migrate all old callsites to use `RCTTurboModuleLookupDelegate`.

Reviewed By: fkgozali

Differential Revision: D13553186

fbshipit-source-id: 4d0488eef081332c8b70782e1337eccf10717dae
2019-01-31 11:35:05 -08:00
..
Surface Removing warning for Pointer is missing a nullability type specifier … (#17872) 2019-01-16 09:50:48 -08:00
RCTAssert.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTAssert.m Update RCTFormatError to support segment ids 2018-12-18 16:23:39 -08:00
RCTBridge+Private.h Allow init of Native Module before bridge is initialized [2/N] 2018-11-26 17:28:11 -08:00
RCTBridge.h Enable module lookup in TurboModules 2019-01-31 11:35:05 -08:00
RCTBridge.m Enable module lookup in TurboModules 2019-01-31 11:35:05 -08:00
RCTBridgeDelegate.h iOS: register lazy nativemodules on startup when Chrome is attached 2018-11-02 00:16:16 -07:00
RCTBridgeMethod.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTBridgeModule.h Enable module lookup in TurboModules 2019-01-31 11:35:05 -08:00
RCTBundleURLProvider.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTBundleURLProvider.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTConvert.h Fix RNTester build 2018-09-17 12:33:01 -07:00
RCTConvert.m Replace deprecated `stringByReplacingPercentEscapesUsingEncoding:` with `stringByAddingPercentEncodingWithAllowedCharacters:` (#19792) 2019-01-25 05:25:39 -08:00
RCTCxxConvert.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTCxxConvert.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTDefines.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTDisplayLink.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTDisplayLink.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTErrorCustomizer.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTErrorInfo.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTErrorInfo.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTEventDispatcher.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTEventDispatcher.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTFrameUpdate.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTFrameUpdate.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTImageSource.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTImageSource.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTInvalidating.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTJSStackFrame.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTJSStackFrame.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTJavaScriptExecutor.h iOS changes to switch to JSI 2018-10-18 01:06:24 -07:00
RCTJavaScriptLoader.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTJavaScriptLoader.mm iOS changes to switch to JSI 2018-10-18 01:06:24 -07:00
RCTKeyCommands.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTKeyCommands.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTLog.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTLog.mm Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTManagedPointer.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTManagedPointer.mm Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTModuleData.h Allow init of Native Module before bridge is initialized [2/N] 2018-11-26 17:28:11 -08:00
RCTModuleData.mm Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTModuleMethod.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTModuleMethod.mm Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTMultipartDataTask.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTMultipartDataTask.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTMultipartStreamReader.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTMultipartStreamReader.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTNullability.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTParserUtils.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTParserUtils.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTPerformanceLogger.h Refactor ReactBridgeStartupData to work with QPL and remove unused fields 2018-10-22 16:18:33 -07:00
RCTPerformanceLogger.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTPlatform.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTPlatform.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTReloadCommand.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTReloadCommand.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRootContentView.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRootContentView.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRootView.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRootView.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRootViewDelegate.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRootViewInternal.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTVRemoteHandler.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTVRemoteHandler.m Differentiate swipe and tap events (#22916) 2019-01-15 16:29:38 -08:00
RCTTouchEvent.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTouchEvent.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTouchHandler.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTouchHandler.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTURLRequestDelegate.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTURLRequestHandler.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTUtils.h Fix LazilyLoadView lookup so that it can drop RCT prefixes. 2018-10-26 11:50:01 -07:00
RCTUtils.m Fix LazilyLoadView lookup so that it can drop RCT prefixes. 2018-10-26 11:50:01 -07:00
RCTVersion.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTVersion.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00