RCTViewManager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <UIKit/UIKit.h>
  8. #import <React/RCTBridgeModule.h>
  9. #import <React/RCTConvert.h>
  10. #import <React/RCTDefines.h>
  11. #import <React/RCTEventDispatcher.h>
  12. #import <React/RCTLog.h>
  13. #import <React/UIView+React.h>
  14. @class RCTBridge;
  15. @class RCTShadowView;
  16. @class RCTSparseArray;
  17. @class RCTUIManager;
  18. typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry);
  19. @interface RCTViewManager : NSObject <RCTBridgeModule>
  20. /**
  21. * The bridge can be used to access both the RCTUIIManager and the RCTEventDispatcher,
  22. * allowing the manager (or the views that it manages) to manipulate the view
  23. * hierarchy and send events back to the JS context.
  24. */
  25. @property (nonatomic, weak) RCTBridge *bridge;
  26. /**
  27. * This method instantiates a native view to be managed by the module. Override
  28. * this to return a custom view instance, which may be preconfigured with default
  29. * properties, subviews, etc. This method will be called many times, and should
  30. * return a fresh instance each time. The view module MUST NOT cache the returned
  31. * view and return the same instance for subsequent calls.
  32. */
  33. - (UIView *)view;
  34. /**
  35. * This method instantiates a shadow view to be managed by the module. If omitted,
  36. * an ordinary RCTShadowView instance will be created, which is typically fine for
  37. * most view types. As with the -view method, the -shadowView method should return
  38. * a fresh instance each time it is called.
  39. */
  40. - (RCTShadowView *)shadowView;
  41. /**
  42. * DEPRECATED: declare properties of type RCTBubblingEventBlock instead
  43. *
  44. * Returns an array of names of events that can be sent by native views. This
  45. * should return bubbling, directly-dispatched event types. The event name
  46. * should not include a prefix such as 'on' or 'top', as this will be applied
  47. * as needed. When subscribing to the event, use the 'Captured' suffix to
  48. * indicate the captured form, or omit the suffix for the bubbling form.
  49. *
  50. * Note that this method is not inherited when you subclass a view module, and
  51. * you should not call [super customBubblingEventTypes] when overriding it.
  52. */
  53. - (NSArray<NSString *> *)customBubblingEventTypes __deprecated_msg("Use RCTBubblingEventBlock props instead.");
  54. /**
  55. * This handles the simple case, where JS and native property names match.
  56. */
  57. #define RCT_EXPORT_VIEW_PROPERTY(name, type) \
  58. +(NSArray<NSString *> *)propConfig_##name RCT_DYNAMIC \
  59. { \
  60. return @[ @ #type ]; \
  61. }
  62. /**
  63. * This macro maps a named property to an arbitrary key path in the view.
  64. */
  65. #define RCT_REMAP_VIEW_PROPERTY(name, keyPath, type) \
  66. +(NSArray<NSString *> *)propConfig_##name RCT_DYNAMIC \
  67. { \
  68. return @[ @ #type, @ #keyPath ]; \
  69. }
  70. /**
  71. * This macro can be used when you need to provide custom logic for setting
  72. * view properties. The macro should be followed by a method body, which can
  73. * refer to "json", "view" and "defaultView" to implement the required logic.
  74. */
  75. #define RCT_CUSTOM_VIEW_PROPERTY(name, type, viewClass) \
  76. RCT_REMAP_VIEW_PROPERTY(name, __custom__, type) \
  77. -(void)set_##name : (id)json forView : (viewClass *)view withDefaultView : (viewClass *)defaultView RCT_DYNAMIC
  78. /**
  79. * This macro is used to map properties to the shadow view, instead of the view.
  80. */
  81. #define RCT_EXPORT_SHADOW_PROPERTY(name, type) \
  82. +(NSArray<NSString *> *)propConfigShadow_##name RCT_DYNAMIC \
  83. { \
  84. return @[ @ #type ]; \
  85. }
  86. /**
  87. * This macro maps a named property to an arbitrary key path in the shadow view.
  88. */
  89. #define RCT_REMAP_SHADOW_PROPERTY(name, keyPath, type) \
  90. +(NSArray<NSString *> *)propConfigShadow_##name RCT_DYNAMIC \
  91. { \
  92. return @[ @ #type, @ #keyPath ]; \
  93. }
  94. /**
  95. * This macro can be used when you need to provide custom logic for setting
  96. * shadow view properties. The macro should be followed by a method body, which can
  97. * refer to "json" and "view".
  98. */
  99. #define RCT_CUSTOM_SHADOW_PROPERTY(name, type, viewClass) \
  100. RCT_REMAP_SHADOW_PROPERTY(name, __custom__, type) \
  101. -(void)set_##name : (id)json forShadowView : (viewClass *)view RCT_DYNAMIC
  102. @end