RCTUIManager.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/RCTBridge.h>
  9. #import <React/RCTBridgeModule.h>
  10. #import <React/RCTInvalidating.h>
  11. #import <React/RCTRootView.h>
  12. #import <React/RCTViewManager.h>
  13. /**
  14. * Posted right before re-render happens. This is a chance for views to invalidate their state so
  15. * next render cycle will pick up updated views and layout appropriately.
  16. */
  17. RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification;
  18. @class RCTLayoutAnimationGroup;
  19. @class RCTUIManagerObserverCoordinator;
  20. /**
  21. * The RCTUIManager is the module responsible for updating the view hierarchy.
  22. */
  23. @interface RCTUIManager : NSObject <RCTBridgeModule, RCTInvalidating>
  24. /**
  25. * Register a root view tag and creates corresponding `rootView` and
  26. * `rootShadowView`.
  27. */
  28. - (void)registerRootViewTag:(NSNumber *)rootTag;
  29. /**
  30. * Register a root view with the RCTUIManager.
  31. */
  32. - (void)registerRootView:(UIView *)rootView;
  33. /**
  34. * Gets the view name associated with a reactTag.
  35. */
  36. - (NSString *)viewNameForReactTag:(NSNumber *)reactTag;
  37. /**
  38. * Gets the view associated with a reactTag.
  39. */
  40. - (UIView *)viewForReactTag:(NSNumber *)reactTag;
  41. /**
  42. * Gets the shadow view associated with a reactTag.
  43. */
  44. - (RCTShadowView *)shadowViewForReactTag:(NSNumber *)reactTag;
  45. /**
  46. * Set the available size (`availableSize` property) for a root view.
  47. * This might be used in response to changes in external layout constraints.
  48. * This value will be directly trasmitted to layout engine and defines how big viewport is;
  49. * this value does not affect root node size style properties.
  50. * Can be considered as something similar to `setSize:forView:` but applicable only for root view.
  51. */
  52. - (void)setAvailableSize:(CGSize)availableSize forRootView:(UIView *)rootView;
  53. /**
  54. * Sets local data for a shadow view corresponded with given view.
  55. * In some cases we need a way to specify some environmental data to shadow view
  56. * to improve layout (or do something similar), so `localData` serves these needs.
  57. * For example, any stateful embedded native views may benefit from this.
  58. * Have in mind that this data is not supposed to interfere with the state of
  59. * the shadow view.
  60. * Please respect one-directional data flow of React.
  61. */
  62. - (void)setLocalData:(NSObject *)localData forView:(UIView *)view;
  63. /**
  64. * Set the size of a view. This might be in response to a screen rotation
  65. * or some other layout event outside of the React-managed view hierarchy.
  66. */
  67. - (void)setSize:(CGSize)size forView:(UIView *)view;
  68. /**
  69. * Set the natural size of a view, which is used when no explicit size is set.
  70. * Use `UIViewNoIntrinsicMetric` to ignore a dimension.
  71. * The `size` must NOT include padding and border.
  72. */
  73. - (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)view;
  74. /**
  75. * Sets up layout animation which will perform on next layout pass.
  76. * The animation will affect only one next layout pass.
  77. * Must be called on the main queue.
  78. */
  79. - (void)setNextLayoutAnimationGroup:(RCTLayoutAnimationGroup *)layoutAnimationGroup;
  80. /**
  81. * Schedule a block to be executed on the UI thread. Useful if you need to execute
  82. * view logic after all currently queued view updates have completed.
  83. */
  84. - (void)addUIBlock:(RCTViewManagerUIBlock)block;
  85. /**
  86. * Schedule a block to be executed on the UI thread. Useful if you need to execute
  87. * view logic before all currently queued view updates have completed.
  88. */
  89. - (void)prependUIBlock:(RCTViewManagerUIBlock)block;
  90. /**
  91. * Used by native animated module to bypass the process of updating the values through the shadow
  92. * view hierarchy. This method will directly update native views, which means that updates for
  93. * layout-related propertied won't be handled properly.
  94. * Make sure you know what you're doing before calling this method :)
  95. */
  96. - (void)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag
  97. viewName:(NSString *)viewName
  98. props:(NSDictionary *)props;
  99. /**
  100. * Given a reactTag from a component, find its root view, if possible.
  101. * Otherwise, this will give back nil.
  102. *
  103. * @param reactTag the component tag
  104. * @param completion the completion block that will hand over the rootView, if any.
  105. *
  106. */
  107. - (void)rootViewForReactTag:(NSNumber *)reactTag withCompletion:(void (^)(UIView *view))completion;
  108. /**
  109. * Finds a view that is tagged with nativeID as its nativeID prop
  110. * with the associated rootTag root tag view hierarchy. Returns the
  111. * view if found, nil otherwise.
  112. *
  113. * @param nativeID the id reference to native component relative to root view.
  114. * @param rootTag the react tag of root view hierarchy from which to find the view.
  115. */
  116. - (UIView *)viewForNativeID:(NSString *)nativeID withRootTag:(NSNumber *)rootTag;
  117. /**
  118. * Register a view that is tagged with nativeID as its nativeID prop
  119. *
  120. * @param nativeID the id reference to native component relative to root view.
  121. * @param view the view that is tagged with nativeID as its nativeID prop.
  122. */
  123. - (void)setNativeID:(NSString *)nativeID forView:(UIView *)view;
  124. /**
  125. * The view that is currently first responder, according to the JS context.
  126. */
  127. + (UIView *)JSResponder;
  128. /**
  129. * In some cases we might want to trigger layout from native side.
  130. * React won't be aware of this, so we need to make sure it happens.
  131. */
  132. - (void)setNeedsLayout;
  133. /**
  134. * Dedicated object for subscribing for UIManager events.
  135. * See `RCTUIManagerObserver` protocol for more details.
  136. */
  137. @property (atomic, retain, readonly) RCTUIManagerObserverCoordinator *observerCoordinator;
  138. @end
  139. /**
  140. * This category makes the current RCTUIManager instance available via the
  141. * RCTBridge, which is useful for RCTBridgeModules or RCTViewManagers that
  142. * need to access the RCTUIManager.
  143. */
  144. @interface RCTBridge (RCTUIManager)
  145. @property (nonatomic, readonly) RCTUIManager *uiManager;
  146. @end