RCTModuleData.h 3.1 KB

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