diff --git a/docs/NativeModulesIOS.md b/docs/NativeModulesIOS.md index a12818eb9..ac76ab7b9 100644 --- a/docs/NativeModulesIOS.md +++ b/docs/NativeModulesIOS.md @@ -250,6 +250,22 @@ RCT_EXPORT_METHOD(doSomethingExpensive:(NSString *)param callback:(RCTResponseSe > > The `methodQueue` method will be called once when the module is initialized, and then retained by the bridge, so there is no need to retain the queue yourself, unless you wish to make use of it within your module. However, if you wish to share the same queue between multiple modules then you will need to ensure that you retain and return the same queue instance for each of them; merely returning a queue of the same name for each won't work. +## Depedency Injection +The bridge initializes any registered RCTBridgeModules automatically, however you may wish to instantiate your own module instances (so you may inject dependencies, for example). + +You can do this by creating a class that implements the RTCBridgeDelegate Protocol, initializing an RTCBridge with the delegate as an argument and initialising a RTCRootView with the initialized bridge. + +```objective-c +id moduleInitialiser = [[classThatImplementsRTCBridgeDelegate alloc] init]; + +RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:moduleInitialiser launchOptions:nil]; + +RCTRootView *rootView = [[RCTRootView alloc] + initWithBridge:bridge + moduleName:kModuleName + initialProperties:nil]; +``` + ## Exporting Constants A native module can export constants that are immediately available to JavaScript at runtime. This is useful for communicating static data that would otherwise require a round-trip through the bridge.