WXComponentManager.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #import <CoreGraphics/CoreGraphics.h>
  20. #import <Foundation/Foundation.h>
  21. #import "WXDisplayLinkManager.h"
  22. @class WXBridgeMethod;
  23. @class WXSDKInstance;
  24. @class WXComponent;
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. void WXPerformBlockOnComponentThread(void (^block)(void));
  29. void WXPerformBlockSyncOnComponentThread(void (^block)(void));
  30. #ifdef __cplusplus
  31. }
  32. #endif
  33. @interface WXComponentManager : NSObject <WXDisplayLinkClient>
  34. @property (nonatomic, readonly, weak) WXSDKInstance *weexInstance;
  35. @property (nonatomic, readonly, assign) BOOL isValid;
  36. /**
  37. * @abstract initialize with weex instance
  38. **/
  39. - (instancetype)initWithWeexInstance:(WXSDKInstance *)weexInstance;
  40. /**
  41. * @abstract return the component thread
  42. **/
  43. + (NSThread *)componentThread;
  44. /**
  45. * @abstract starting component tasks
  46. **/
  47. - (void)startComponentTasks;
  48. /**
  49. * @abstract tell the component manager that instance root view's frame has been changed
  50. **/
  51. - (void)rootViewFrameDidChange:(CGRect)frame;
  52. ///--------------------------------------
  53. /// @name Component Tree Building
  54. ///--------------------------------------
  55. /**
  56. * @abstract create root component
  57. **/
  58. - (void)createBody:(NSString*)ref
  59. type:(NSString*)type
  60. styles:(NSDictionary*)styles
  61. attributes:(NSDictionary*)attributes
  62. events:(NSArray*)events
  63. renderObject:(void*)renderObject;
  64. /**
  65. * @abstract add a component to its parent
  66. **/
  67. - (void)addComponent:(NSString*)ref
  68. type:(NSString*)type
  69. parentRef:(NSString*)parentRef
  70. styles:(NSDictionary*)styles
  71. attributes:(NSDictionary*)attributes
  72. events:(NSArray*)events
  73. index:(NSInteger)index
  74. renderObject:(void*)renderObject;
  75. /**
  76. * @abstract move component
  77. **/
  78. - (void)moveComponent:(NSString *)ref toSuper:(NSString *)superRef atIndex:(NSInteger)index;
  79. /**
  80. * @abstract remove component
  81. **/
  82. - (void)removeComponent:(NSString *)ref;
  83. /**
  84. * @abstract notify that a component tree is built and trigger layout,
  85. may be called several times rendering a page.
  86. **/
  87. - (void)appendTreeCreateFinish:(NSString*)ref;
  88. /**
  89. * @abstract return component for specific ref, must be called on component thread by calling WXPerformBlockOnComponentThread
  90. */
  91. - (WXComponent *)componentForRef:(NSString *)ref;
  92. /**
  93. * @abstract return root component
  94. */
  95. - (WXComponent *)componentForRoot;
  96. /**
  97. * @abstract number of components created, must be called on component thread by calling WXPerformBlockOnComponentThread
  98. */
  99. - (NSUInteger)numberOfComponents;
  100. /**
  101. * @abstract add an existing component to references look-up map
  102. */
  103. - (void)addComponent:(WXComponent *)component toIndexDictForRef:(NSString *)ref;
  104. ///--------------------------------------
  105. /// @name Updating
  106. ///--------------------------------------
  107. /**
  108. * @abstract update styles
  109. **/
  110. - (void)updateStyles:(NSDictionary *)styles forComponent:(NSString *)ref;
  111. /**
  112. * @abstract update pseudo class styles
  113. **/
  114. - (void)updatePseudoClassStyles:(NSDictionary *)styles forComponent:(NSString *)ref;
  115. /**
  116. * @abstract update attributes
  117. **/
  118. - (void)updateAttributes:(NSDictionary *)attributes forComponent:(NSString *)ref;
  119. /**
  120. * @abstract quick check that if a component has non transition properties
  121. **/
  122. - (BOOL)isTransitionNoneOfComponent:(NSString*)ref; // for quick access
  123. /**
  124. * @abstract check if component with @ref has any style in @styles which is animated
  125. **/
  126. - (BOOL)hasTransitionPropertyInStyles:(NSDictionary*)styles forComponent:(NSString*)ref;
  127. /**
  128. * @abstract layout a component with frame output by weex core layout engine
  129. **/
  130. - (void)layoutComponent:(WXComponent*)component frame:(CGRect)frame isRTL:(BOOL)isRTL innerMainSize:(CGFloat)innerMainSize;
  131. /**
  132. * @abstract layout a component on platform side
  133. **/
  134. - (void)layoutComponent:(WXComponent*)component;
  135. /**
  136. * @abstract add event
  137. **/
  138. - (void)addEvent:(NSString *)event toComponent:(NSString *)ref;
  139. /**
  140. * @abstract remove event
  141. **/
  142. - (void)removeEvent:(NSString *)event fromComponent:(NSString *)ref;
  143. /**
  144. * @abstract scroll to specific component
  145. **/
  146. - (void)scrollToComponent:(NSString *)ref options:(NSDictionary *)options;
  147. ///--------------------------------------
  148. /// @name Life Cycle
  149. ///--------------------------------------
  150. /**
  151. * @abstract called when all doms are created
  152. **/
  153. - (void)createFinish;
  154. /**
  155. * @abstract called when all doms are refreshed
  156. **/
  157. - (void)refreshFinish;
  158. /**
  159. * @abstract called when all doms are updated
  160. **/
  161. - (void)updateFinish;
  162. /**
  163. * @abstract called when all doms are created and layout finished
  164. **/
  165. - (void)renderFinish;
  166. /**
  167. * @abstract called when render failed
  168. **/
  169. - (void)renderFailed:(NSError *)error;
  170. /**
  171. * @abstract unload
  172. **/
  173. - (void)unload;
  174. /**
  175. * @abstract invalidate component management, this can be called on main thread.
  176. **/
  177. - (void)invalidate;
  178. ///--------------------------------------
  179. /// @name Fixed
  180. ///--------------------------------------
  181. /**
  182. * @abstract add a component which has a fixed position
  183. *
  184. * @param fixComponent the fixed component to add
  185. */
  186. - (void)addFixedComponent:(WXComponent *)fixComponent;
  187. /**
  188. * @abstract remove a component which has a fixed position
  189. *
  190. * @param fixComponent the fixed component to remove
  191. */
  192. - (void)removeFixedComponent:(WXComponent *)fixComponent;
  193. /**
  194. * @abstract add a task to UI thread
  195. **/
  196. - (void)_addUITask:(void (^)(void))block;
  197. /**
  198. * @abstract execute a task to UI thread
  199. **/
  200. - (void)executePrerenderUITask:(NSString *)url;
  201. /**
  202. * @param styles a NSDictionary value, styles which will resolve
  203. * @param component a WXComponent value, the target which you want to resolve
  204. * @param isUpdateStyles a BOOL value, YES will udpate the component style property, NO will notifiy the lifeStyle of compoenent to handle, default value is NO.
  205. * @abstract handleStyle will be add to a queue to be executed every frame, but handleStyleOnMainThread will switch to main thread and execute imediately, you can call this for your execution time sequence.
  206. */
  207. - (void)handleStyleOnMainThread:(NSDictionary*)styles forComponent:(WXComponent *)component isUpdateStyles:(BOOL)isUpdateStyles;
  208. ///--------------------------------------
  209. /// @name Enumerating
  210. ///--------------------------------------
  211. /**
  212. * Enumerate components using breadth-first search algorithm,
  213. must be called on component thread by calling WXPerformBlockOnComponentThread
  214. */
  215. - (void)enumerateComponentsUsingBlock:(void (^)(WXComponent *, BOOL *stop))block;
  216. #pragma mark batch mark
  217. /**
  218. a start native batch tag for a group of UI operations, company with performBatchEnd
  219. @see performBatchEnd
  220. */
  221. - (void)performBatchBegin;
  222. /**
  223. an end native batch tag for a group of UI operations, company with performBatchBegin
  224. @see performBatchBegin
  225. */
  226. - (void)performBatchEnd;
  227. @end