ASDisplayNode+Beta.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // ASDisplayNode+Beta.h
  3. // AsyncDisplayKit
  4. //
  5. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  6. // This source code is licensed under the BSD-style license found in the
  7. // LICENSE file in the root directory of this source tree. An additional grant
  8. // of patent rights can be found in the PATENTS file in the same directory.
  9. //
  10. #import <AsyncDisplayKit/ASAvailability.h>
  11. #import <AsyncDisplayKit/ASDisplayNode.h>
  12. #import <AsyncDisplayKit/ASLayoutRangeType.h>
  13. #import <AsyncDisplayKit/ASEventLog.h>
  14. #if YOGA
  15. #import <Yoga/Yoga.h>
  16. #endif
  17. NS_ASSUME_NONNULL_BEGIN
  18. ASDISPLAYNODE_EXTERN_C_BEGIN
  19. void ASPerformBlockOnMainThread(void (^block)());
  20. void ASPerformBlockOnBackgroundThread(void (^block)()); // DISPATCH_QUEUE_PRIORITY_DEFAULT
  21. ASDISPLAYNODE_EXTERN_C_END
  22. #if ASEVENTLOG_ENABLE
  23. #define ASDisplayNodeLogEvent(node, ...) [node.eventLog logEventWithBacktrace:(AS_SAVE_EVENT_BACKTRACES ? [NSThread callStackSymbols] : nil) format:__VA_ARGS__]
  24. #else
  25. #define ASDisplayNodeLogEvent(node, ...)
  26. #endif
  27. #if ASEVENTLOG_ENABLE
  28. #define ASDisplayNodeGetEventLog(node) node.eventLog
  29. #else
  30. #define ASDisplayNodeGetEventLog(node) nil
  31. #endif
  32. /**
  33. * Bitmask to indicate what performance measurements the cell should record.
  34. */
  35. typedef NS_OPTIONS(NSUInteger, ASDisplayNodePerformanceMeasurementOptions) {
  36. ASDisplayNodePerformanceMeasurementOptionLayoutSpec = 1 << 0,
  37. ASDisplayNodePerformanceMeasurementOptionLayoutComputation = 1 << 1
  38. };
  39. typedef struct {
  40. CFTimeInterval layoutSpecTotalTime;
  41. NSInteger layoutSpecNumberOfPasses;
  42. CFTimeInterval layoutComputationTotalTime;
  43. NSInteger layoutComputationNumberOfPasses;
  44. } ASDisplayNodePerformanceMeasurements;
  45. @interface ASDisplayNode (Beta)
  46. /**
  47. * ASTableView and ASCollectionView now throw exceptions on invalid updates
  48. * like their UIKit counterparts. If YES, these classes will log messages
  49. * on invalid updates rather than throwing exceptions.
  50. *
  51. * Note that even if AsyncDisplayKit's exception is suppressed, the app may still crash
  52. * as it proceeds with an invalid update.
  53. *
  54. * This property defaults to NO. It will be removed in a future release.
  55. */
  56. + (BOOL)suppressesInvalidCollectionUpdateExceptions AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Collection update exceptions are thrown if assertions are enabled.");
  57. + (void)setSuppressesInvalidCollectionUpdateExceptions:(BOOL)suppresses ASDISPLAYNODE_DEPRECATED_MSG("Collection update exceptions are thrown if assertions are enabled.");;
  58. /**
  59. * @abstract Recursively ensures node and all subnodes are displayed.
  60. * @see Full documentation in ASDisplayNode+FrameworkPrivate.h
  61. */
  62. - (void)recursivelyEnsureDisplaySynchronously:(BOOL)synchronously;
  63. /**
  64. * @abstract allow modification of a context before the node's content is drawn
  65. *
  66. * @discussion Set the block to be called after the context has been created and before the node's content is drawn.
  67. * You can override this to modify the context before the content is drawn. You are responsible for saving and
  68. * restoring context if necessary. Restoring can be done in contextDidDisplayNodeContent
  69. * This block can be called from *any* thread and it is unsafe to access any UIKit main thread properties from it.
  70. */
  71. @property (nonatomic, copy, nullable) ASDisplayNodeContextModifier willDisplayNodeContentWithRenderingContext;
  72. /**
  73. * @abstract allow modification of a context after the node's content is drawn
  74. */
  75. @property (nonatomic, copy, nullable) ASDisplayNodeContextModifier didDisplayNodeContentWithRenderingContext;
  76. /**
  77. * @abstract A bitmask representing which actions (layout spec, layout generation) should be measured.
  78. */
  79. @property (nonatomic, assign) ASDisplayNodePerformanceMeasurementOptions measurementOptions;
  80. /**
  81. * @abstract A simple struct representing performance measurements collected.
  82. */
  83. @property (nonatomic, assign, readonly) ASDisplayNodePerformanceMeasurements performanceMeasurements;
  84. #if ASEVENTLOG_ENABLE
  85. /*
  86. * @abstract The primitive event tracing object. You shouldn't directly use it to log event. Use the ASDisplayNodeLogEvent macro instead.
  87. */
  88. @property (nonatomic, strong, readonly) ASEventLog *eventLog;
  89. #endif
  90. /**
  91. * @abstract Currently used by ASNetworkImageNode and ASMultiplexImageNode to allow their placeholders to stay if they are loading an image from the network.
  92. * Otherwise, a display pass is scheduled and completes, but does not actually draw anything - and ASDisplayNode considers the element finished.
  93. */
  94. - (BOOL)placeholderShouldPersist AS_WARN_UNUSED_RESULT;
  95. /**
  96. * @abstract Indicates that the receiver and all subnodes have finished displaying. May be called more than once, for example if the receiver has
  97. * a network image node. This is called after the first display pass even if network image nodes have not downloaded anything (text would be done,
  98. * and other nodes that are ready to do their final display). Each render of every progressive jpeg network node would cause this to be called, so
  99. * this hook could be called up to 1 + (pJPEGcount * pJPEGrenderCount) times. The render count depends on how many times the downloader calls the
  100. * progressImage block.
  101. */
  102. - (void)hierarchyDisplayDidFinish;
  103. /**
  104. * Only ASLayoutRangeModeVisibleOnly or ASLayoutRangeModeLowMemory are recommended. Default is ASLayoutRangeModeVisibleOnly,
  105. * because this is the only way to ensure an application will not have blank / flashing views as the user navigates back after
  106. * a memory warning. Apps that wish to use the more effective / aggressive ASLayoutRangeModeLowMemory may need to take steps
  107. * to mitigate this behavior, including: restoring a larger range mode to the next controller before the user navigates there,
  108. * enabling .neverShowPlaceholders on ASCellNodes so that the navigation operation is blocked on redisplay completing, etc.
  109. */
  110. + (void)setRangeModeForMemoryWarnings:(ASLayoutRangeMode)rangeMode;
  111. /**
  112. * @abstract Whether to draw all descendant nodes' layers/views into this node's layer/view's backing store.
  113. *
  114. * @discussion
  115. * When set to YES, causes all descendant nodes' layers/views to be drawn directly into this node's layer/view's backing
  116. * store. Defaults to NO.
  117. *
  118. * If a node's descendants are static (never animated or never change attributes after creation) then that node is a
  119. * good candidate for rasterization. Rasterizing descendants has two main benefits:
  120. * 1) Backing stores for descendant layers are not created. Instead the layers are drawn directly into the rasterized
  121. * container. This can save a great deal of memory.
  122. * 2) Since the entire subtree is drawn into one backing store, compositing and blending are eliminated in that subtree
  123. * which can help improve animation/scrolling/etc performance.
  124. *
  125. * Rasterization does not currently support descendants with transform, sublayerTransform, or alpha. Those properties
  126. * will be ignored when rasterizing descendants.
  127. *
  128. * Note: this has nothing to do with -[CALayer shouldRasterize], which doesn't work with ASDisplayNode's asynchronous
  129. * rendering model.
  130. */
  131. @property (nonatomic, assign) BOOL shouldRasterizeDescendants ASDISPLAYNODE_DEPRECATED_MSG("Deprecated in version 2.2");
  132. @end
  133. #pragma mark - Yoga Layout Support
  134. #if YOGA
  135. @interface ASDisplayNode (Yoga)
  136. @property (nonatomic, strong) NSArray *yogaChildren;
  137. - (void)addYogaChild:(ASDisplayNode *)child;
  138. - (void)removeYogaChild:(ASDisplayNode *)child;
  139. // This method should not normally be called directly.
  140. - (ASLayout *)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize;
  141. @end
  142. @interface ASLayoutElementStyle (Yoga)
  143. @property (nonatomic, assign, readwrite) ASStackLayoutDirection direction;
  144. @property (nonatomic, assign, readwrite) CGFloat spacing;
  145. @property (nonatomic, assign, readwrite) ASStackLayoutJustifyContent justifyContent;
  146. @property (nonatomic, assign, readwrite) ASStackLayoutAlignItems alignItems;
  147. @property (nonatomic, assign, readwrite) YGPositionType positionType;
  148. @property (nonatomic, assign, readwrite) ASEdgeInsets position;
  149. @property (nonatomic, assign, readwrite) ASEdgeInsets margin;
  150. @property (nonatomic, assign, readwrite) ASEdgeInsets padding;
  151. @property (nonatomic, assign, readwrite) ASEdgeInsets border;
  152. @property (nonatomic, assign, readwrite) CGFloat aspectRatio;
  153. @property (nonatomic, assign, readwrite) YGWrap flexWrap;
  154. @end
  155. #endif
  156. NS_ASSUME_NONNULL_END