RCTBridge+Private.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/RCTBridge.h>
  8. @class RCTModuleData;
  9. @protocol RCTJavaScriptExecutor;
  10. RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
  11. RCT_EXTERN void RCTRegisterModule(Class);
  12. @interface RCTBridge ()
  13. // Private designated initializer
  14. - (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)delegate
  15. bundleURL:(NSURL *)bundleURL
  16. moduleProvider:(RCTBridgeModuleListProvider)block
  17. launchOptions:(NSDictionary *)launchOptions NS_DESIGNATED_INITIALIZER;
  18. // Used for the profiler flow events between JS and native
  19. @property (nonatomic, assign) int64_t flowID;
  20. @property (nonatomic, assign) CFMutableDictionaryRef flowIDMap;
  21. @property (nonatomic, strong) NSLock *flowIDMapLock;
  22. // Used by RCTDevMenu
  23. @property (nonatomic, copy) NSString *bridgeDescription;
  24. + (instancetype)currentBridge;
  25. + (void)setCurrentBridge:(RCTBridge *)bridge;
  26. /**
  27. * Bridge setup code - creates an instance of RCTBachedBridge. Exposed for
  28. * test only
  29. */
  30. - (void)setUp;
  31. /**
  32. * This method is used to invoke a callback that was registered in the
  33. * JavaScript application context. Safe to call from any thread.
  34. */
  35. - (void)enqueueCallback:(NSNumber *)cbID args:(NSArray *)args;
  36. /**
  37. * This property is mostly used on the main thread, but may be touched from
  38. * a background thread if the RCTBridge happens to deallocate on a background
  39. * thread. Therefore, we want all writes to it to be seen atomically.
  40. */
  41. @property (atomic, strong) RCTBridge *batchedBridge;
  42. /**
  43. * The block that creates the modules' instances to be added to the bridge.
  44. * Exposed for RCTCxxBridge
  45. */
  46. @property (nonatomic, copy, readonly) RCTBridgeModuleListProvider moduleProvider;
  47. /**
  48. * Used by RCTDevMenu to override the `hot` param of the current bundleURL.
  49. */
  50. @property (nonatomic, strong, readwrite) NSURL *bundleURL;
  51. @end
  52. @interface RCTBridge (RCTCxxBridge)
  53. /**
  54. * Used by RCTModuleData
  55. */
  56. @property (nonatomic, weak, readonly) RCTBridge *parentBridge;
  57. /**
  58. * Used by RCTModuleData
  59. */
  60. @property (nonatomic, assign, readonly) BOOL moduleSetupComplete;
  61. /**
  62. * Called on the child bridge to run the executor and start loading.
  63. */
  64. - (void)start;
  65. /**
  66. * Used by RCTModuleData to register the module for frame updates after it is
  67. * lazily initialized.
  68. */
  69. - (void)registerModuleForFrameUpdates:(id<RCTBridgeModule>)module withModuleData:(RCTModuleData *)moduleData;
  70. /**
  71. * Dispatch work to a module's queue - this is also suports the fake RCTJSThread
  72. * queue. Exposed for the RCTProfiler
  73. */
  74. - (void)dispatchBlock:(dispatch_block_t)block queue:(dispatch_queue_t)queue;
  75. /**
  76. * Get the module data for a given module name. Used by UIManager to implement
  77. * the `dispatchViewManagerCommand` method.
  78. */
  79. - (RCTModuleData *)moduleDataForName:(NSString *)moduleName;
  80. /**
  81. * Registers additional classes with the ModuleRegistry.
  82. */
  83. - (void)registerAdditionalModuleClasses:(NSArray<Class> *)newModules;
  84. /**
  85. * Updates the ModuleRegistry with a pre-initialized instance.
  86. */
  87. - (void)updateModuleWithInstance:(id<RCTBridgeModule>)instance;
  88. /**
  89. * Systrace profiler toggling methods exposed for the RCTDevMenu
  90. */
  91. - (void)startProfiling;
  92. - (void)stopProfiling:(void (^)(NSData *))callback;
  93. /**
  94. * Synchronously call a specific native module's method and return the result
  95. */
  96. - (id)callNativeModule:(NSUInteger)moduleID method:(NSUInteger)methodID params:(NSArray *)params;
  97. /**
  98. * Hook exposed for RCTLog to send logs to JavaScript when not running in JSC
  99. */
  100. - (void)logMessage:(NSString *)message level:(NSString *)level;
  101. /**
  102. * Allow super fast, one time, timers to skip the queue and be directly executed
  103. */
  104. - (void)_immediatelyCallTimer:(NSNumber *)timer;
  105. @end
  106. @interface RCTBridge (Inspector)
  107. @property (nonatomic, readonly, getter=isInspectable) BOOL inspectable;
  108. @end
  109. @interface RCTCxxBridge : RCTBridge
  110. // TODO(cjhopman): this seems unsafe unless we require that it is only called on the main js queue.
  111. @property (nonatomic, readonly) void *runtime;
  112. - (instancetype)initWithParentBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
  113. @end