RCTModuleData.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <Foundation/Foundation.h>
  8. #import <React/RCTInvalidating.h>
  9. @protocol RCTBridgeMethod;
  10. @protocol RCTBridgeModule;
  11. @class RCTBridge;
  12. typedef id<RCTBridgeModule>(^RCTBridgeModuleProvider)(void);
  13. @interface RCTModuleData : NSObject <RCTInvalidating>
  14. - (instancetype)initWithModuleClass:(Class)moduleClass
  15. bridge:(RCTBridge *)bridge;
  16. - (instancetype)initWithModuleClass:(Class)moduleClass
  17. moduleProvider:(RCTBridgeModuleProvider)moduleProvider
  18. bridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
  19. - (instancetype)initWithModuleInstance:(id<RCTBridgeModule>)instance
  20. bridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
  21. /**
  22. * Calls `constantsToExport` on the module and stores the result. Note that
  23. * this will init the module if it has not already been created. This method
  24. * can be called on any thread, but may block the main thread briefly if the
  25. * module implements `constantsToExport`.
  26. */
  27. - (void)gatherConstants;
  28. @property (nonatomic, strong, readonly) Class moduleClass;
  29. @property (nonatomic, copy, readonly) NSString *name;
  30. /**
  31. * Returns the module methods. Note that this will gather the methods the first
  32. * time it is called and then memoize the results.
  33. */
  34. @property (nonatomic, copy, readonly) NSArray<id<RCTBridgeMethod>> *methods;
  35. /**
  36. * Returns the module's constants, if it exports any
  37. */
  38. @property (nonatomic, copy, readonly) NSDictionary<NSString *, id> *exportedConstants;
  39. /**
  40. * Returns YES if module instance has already been initialized; NO otherwise.
  41. */
  42. @property (nonatomic, assign, readonly) BOOL hasInstance;
  43. /**
  44. * Returns YES if module instance must be created on the main thread.
  45. */
  46. @property (nonatomic, assign) BOOL requiresMainQueueSetup;
  47. /**
  48. * Returns YES if module has constants to export.
  49. */
  50. @property (nonatomic, assign, readonly) BOOL hasConstantsToExport;
  51. /**
  52. * Returns the current module instance. Note that this will init the instance
  53. * if it has not already been created. To check if the module instance exists
  54. * without causing it to be created, use `hasInstance` instead.
  55. */
  56. @property (nonatomic, strong, readwrite) id<RCTBridgeModule> instance;
  57. /**
  58. * Returns the module method dispatch queue. Note that this will init both the
  59. * queue and the module itself if they have not already been created.
  60. */
  61. @property (nonatomic, strong, readonly) dispatch_queue_t methodQueue;
  62. /**
  63. * Whether the receiver has a valid `instance` which implements -batchDidComplete.
  64. */
  65. @property (nonatomic, assign, readonly) BOOL implementsBatchDidComplete;
  66. /**
  67. * Whether the receiver has a valid `instance` which implements
  68. * -partialBatchDidFlush.
  69. */
  70. @property (nonatomic, assign, readonly) BOOL implementsPartialBatchDidFlush;
  71. @end