RCTBridgeDelegate.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/RCTJavaScriptLoader.h>
  8. @class RCTBridge;
  9. @protocol RCTBridgeModule;
  10. @protocol RCTBridgeDelegate <NSObject>
  11. /**
  12. * The location of the JavaScript source file. When running from the packager
  13. * this should be an absolute URL, e.g. `http://localhost:8081/index.ios.bundle`.
  14. * When running from a locally bundled JS file, this should be a `file://` url
  15. * pointing to a path inside the app resources, e.g. `file://.../main.jsbundle`.
  16. */
  17. - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge;
  18. @optional
  19. /**
  20. * The bridge initializes any registered RCTBridgeModules automatically, however
  21. * if you wish to instantiate your own module instances, you can return them
  22. * from this method.
  23. *
  24. * Note: You should always return a new instance for each call, rather than
  25. * returning the same instance each time the bridge is reloaded. Module instances
  26. * should not be shared between bridges, and this may cause unexpected behavior.
  27. *
  28. * It is also possible to override standard modules with your own implementations
  29. * by returning a class with the same `moduleName` from this method, but this is
  30. * not recommended in most cases - if the module methods and behavior do not
  31. * match exactly, it may lead to bugs or crashes.
  32. */
  33. - (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge;
  34. /**
  35. * Configure whether the JSCExecutor created should use the system JSC API or
  36. * alternative hooks provided. When returning YES from this method, you must have
  37. * previously called facebook::react::setCustomJSCWrapper.
  38. *
  39. * @experimental
  40. */
  41. - (BOOL)shouldBridgeUseCustomJSC:(RCTBridge *)bridge;
  42. /**
  43. * The bridge will call this method when a module been called from JS
  44. * cannot be found among registered modules.
  45. * It should return YES if the module with name 'moduleName' was registered
  46. * in the implementation, and the system must attempt to look for it again among registered.
  47. * If the module was not registered, return NO to prevent further searches.
  48. */
  49. - (BOOL)bridge:(RCTBridge *)bridge didNotFindModule:(NSString *)moduleName;
  50. /**
  51. * The bridge will automatically attempt to load the JS source code from the
  52. * location specified by the `sourceURLForBridge:` method, however, if you want
  53. * to handle loading the JS yourself, you can do so by implementing this method.
  54. */
  55. - (void)loadSourceForBridge:(RCTBridge *)bridge
  56. onProgress:(RCTSourceLoadProgressBlock)onProgress
  57. onComplete:(RCTSourceLoadBlock)loadCallback;
  58. /**
  59. * Similar to loadSourceForBridge:onProgress:onComplete: but without progress
  60. * reporting.
  61. */
  62. - (void)loadSourceForBridge:(RCTBridge *)bridge withBlock:(RCTSourceLoadBlock)loadCallback;
  63. /**
  64. * Retrieve the list of lazy-native-modules names for the given bridge.
  65. */
  66. - (NSDictionary<NSString *, Class> *)extraLazyModuleClassesForBridge:(RCTBridge *)bridge;
  67. @end