mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-05 20:22:15 +00:00
* [Yoga] Rewrite YOGA_TREE_CONTIGUOUS mode with support for mixing with ASLayoutSpec. After experimentation with the ASYogaLayoutSpec (or non-contiguous) approach to integrating Yoga, test results and feedback from the authors of Yoga have shown that this approach can't be made completely correct, There are issues with some of the features required to represent Web-style flexbox; in particular: padding, margins, and border handling have varience. This diff is a first step towards a truly correct and elegant implementation of Yoga integration with Texture. In addition to reducing the footprint of the integration, which is an explicit goal of work at this stage, these changes already support improved behavior - including mixing between ASLayoutSpecs even as subnodes of Yoga layout-driven nodes, in addition to above them. Yoga may be used for any set of nodes. Because Yoga usage is limited at this time, it's safe to merge this diff and further improvements will be refinements in this direction. * [ASDKgram] Add Yoga layout implementation for PhotoCellNode. * [Yoga] Final fixes for the upgraded implementation of the Contiguous layout mode. * [Yoga] Add CHANGELOG.md entry and fix for Yoga rounding to screen scale. * [Yoga] Minor cleanup to remove old comments and generalize utility methods.
213 lines
9.1 KiB
Objective-C
213 lines
9.1 KiB
Objective-C
//
|
|
// ASDisplayNode+Beta.h
|
|
// Texture
|
|
//
|
|
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the /ASDK-Licenses directory of this source tree. An additional
|
|
// grant of patent rights can be found in the PATENTS file in the same directory.
|
|
//
|
|
// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present,
|
|
// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
|
|
#import <AsyncDisplayKit/ASAvailability.h>
|
|
#import <AsyncDisplayKit/ASDisplayNode.h>
|
|
#import <AsyncDisplayKit/ASLayoutRangeType.h>
|
|
#import <AsyncDisplayKit/ASEventLog.h>
|
|
|
|
#if YOGA
|
|
#import YOGA_HEADER_PATH
|
|
#import <AsyncDisplayKit/ASYogaUtilities.h>
|
|
#endif
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
ASDISPLAYNODE_EXTERN_C_BEGIN
|
|
void ASPerformBlockOnMainThread(void (^block)());
|
|
void ASPerformBlockOnBackgroundThread(void (^block)()); // DISPATCH_QUEUE_PRIORITY_DEFAULT
|
|
ASDISPLAYNODE_EXTERN_C_END
|
|
|
|
#if ASEVENTLOG_ENABLE
|
|
#define ASDisplayNodeLogEvent(node, ...) [node.eventLog logEventWithBacktrace:(AS_SAVE_EVENT_BACKTRACES ? [NSThread callStackSymbols] : nil) format:__VA_ARGS__]
|
|
#else
|
|
#define ASDisplayNodeLogEvent(node, ...)
|
|
#endif
|
|
|
|
#if ASEVENTLOG_ENABLE
|
|
#define ASDisplayNodeGetEventLog(node) node.eventLog
|
|
#else
|
|
#define ASDisplayNodeGetEventLog(node) nil
|
|
#endif
|
|
|
|
/**
|
|
* Bitmask to indicate what performance measurements the cell should record.
|
|
*/
|
|
typedef NS_OPTIONS(NSUInteger, ASDisplayNodePerformanceMeasurementOptions) {
|
|
ASDisplayNodePerformanceMeasurementOptionLayoutSpec = 1 << 0,
|
|
ASDisplayNodePerformanceMeasurementOptionLayoutComputation = 1 << 1
|
|
};
|
|
|
|
typedef struct {
|
|
CFTimeInterval layoutSpecTotalTime;
|
|
NSInteger layoutSpecNumberOfPasses;
|
|
CFTimeInterval layoutComputationTotalTime;
|
|
NSInteger layoutComputationNumberOfPasses;
|
|
} ASDisplayNodePerformanceMeasurements;
|
|
|
|
@interface ASDisplayNode (Beta)
|
|
|
|
/**
|
|
* ASTableView and ASCollectionView now throw exceptions on invalid updates
|
|
* like their UIKit counterparts. If YES, these classes will log messages
|
|
* on invalid updates rather than throwing exceptions.
|
|
*
|
|
* Note that even if AsyncDisplayKit's exception is suppressed, the app may still crash
|
|
* as it proceeds with an invalid update.
|
|
*
|
|
* This property defaults to NO. It will be removed in a future release.
|
|
*/
|
|
+ (BOOL)suppressesInvalidCollectionUpdateExceptions AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Collection update exceptions are thrown if assertions are enabled.");
|
|
+ (void)setSuppressesInvalidCollectionUpdateExceptions:(BOOL)suppresses ASDISPLAYNODE_DEPRECATED_MSG("Collection update exceptions are thrown if assertions are enabled.");
|
|
|
|
/**
|
|
* @abstract Recursively ensures node and all subnodes are displayed.
|
|
* @see Full documentation in ASDisplayNode+FrameworkPrivate.h
|
|
*/
|
|
- (void)recursivelyEnsureDisplaySynchronously:(BOOL)synchronously;
|
|
|
|
/**
|
|
* @abstract allow modification of a context before the node's content is drawn
|
|
*
|
|
* @discussion Set the block to be called after the context has been created and before the node's content is drawn.
|
|
* You can override this to modify the context before the content is drawn. You are responsible for saving and
|
|
* restoring context if necessary. Restoring can be done in contextDidDisplayNodeContent
|
|
* This block can be called from *any* thread and it is unsafe to access any UIKit main thread properties from it.
|
|
*/
|
|
@property (nonatomic, copy, nullable) ASDisplayNodeContextModifier willDisplayNodeContentWithRenderingContext;
|
|
|
|
/**
|
|
* @abstract allow modification of a context after the node's content is drawn
|
|
*/
|
|
@property (nonatomic, copy, nullable) ASDisplayNodeContextModifier didDisplayNodeContentWithRenderingContext;
|
|
|
|
/**
|
|
* @abstract A bitmask representing which actions (layout spec, layout generation) should be measured.
|
|
*/
|
|
@property (nonatomic, assign) ASDisplayNodePerformanceMeasurementOptions measurementOptions;
|
|
|
|
/**
|
|
* @abstract A simple struct representing performance measurements collected.
|
|
*/
|
|
@property (nonatomic, assign, readonly) ASDisplayNodePerformanceMeasurements performanceMeasurements;
|
|
|
|
#if ASEVENTLOG_ENABLE
|
|
/*
|
|
* @abstract The primitive event tracing object. You shouldn't directly use it to log event. Use the ASDisplayNodeLogEvent macro instead.
|
|
*/
|
|
@property (nonatomic, strong, readonly) ASEventLog *eventLog;
|
|
#endif
|
|
|
|
/**
|
|
* @abstract Currently used by ASNetworkImageNode and ASMultiplexImageNode to allow their placeholders to stay if they are loading an image from the network.
|
|
* Otherwise, a display pass is scheduled and completes, but does not actually draw anything - and ASDisplayNode considers the element finished.
|
|
*/
|
|
- (BOOL)placeholderShouldPersist AS_WARN_UNUSED_RESULT;
|
|
|
|
/**
|
|
* @abstract Indicates that the receiver and all subnodes have finished displaying. May be called more than once, for example if the receiver has
|
|
* 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,
|
|
* 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
|
|
* this hook could be called up to 1 + (pJPEGcount * pJPEGrenderCount) times. The render count depends on how many times the downloader calls the
|
|
* progressImage block.
|
|
*/
|
|
- (void)hierarchyDisplayDidFinish;
|
|
|
|
/**
|
|
* Only ASLayoutRangeModeVisibleOnly or ASLayoutRangeModeLowMemory are recommended. Default is ASLayoutRangeModeVisibleOnly,
|
|
* because this is the only way to ensure an application will not have blank / flashing views as the user navigates back after
|
|
* a memory warning. Apps that wish to use the more effective / aggressive ASLayoutRangeModeLowMemory may need to take steps
|
|
* to mitigate this behavior, including: restoring a larger range mode to the next controller before the user navigates there,
|
|
* enabling .neverShowPlaceholders on ASCellNodes so that the navigation operation is blocked on redisplay completing, etc.
|
|
*/
|
|
+ (void)setRangeModeForMemoryWarnings:(ASLayoutRangeMode)rangeMode;
|
|
|
|
/**
|
|
* @abstract Whether to draw all descendent nodes' contents into this node's layer's backing store.
|
|
*
|
|
* @discussion
|
|
* When called, causes all descendent nodes' contents to be drawn directly into this node's layer's backing
|
|
* store.
|
|
*
|
|
* If a node's descendants are static (never animated or never change attributes after creation) then that node is a
|
|
* good candidate for rasterization. Rasterizing descendants has two main benefits:
|
|
* 1) Backing stores for descendant layers are not created. Instead the layers are drawn directly into the rasterized
|
|
* container. This can save a great deal of memory.
|
|
* 2) Since the entire subtree is drawn into one backing store, compositing and blending are eliminated in that subtree
|
|
* which can help improve animation/scrolling/etc performance.
|
|
*
|
|
* Rasterization does not currently support descendants with transform, sublayerTransform, or alpha. Those properties
|
|
* will be ignored when rasterizing descendants.
|
|
*
|
|
* Note: this has nothing to do with -[CALayer shouldRasterize], which doesn't work with ASDisplayNode's asynchronous
|
|
* rendering model.
|
|
*
|
|
* Note: You cannot add subnodes whose layers/views are already loaded to a rasterized node.
|
|
* Note: You cannot call this method after the receiver's layer/view is loaded.
|
|
*/
|
|
- (void)enableSubtreeRasterization;
|
|
|
|
@end
|
|
|
|
#pragma mark - Yoga Layout Support
|
|
|
|
#if YOGA
|
|
|
|
extern void ASDisplayNodePerformBlockOnEveryYogaChild(ASDisplayNode * _Nullable node, void(^block)(ASDisplayNode *node));
|
|
|
|
@interface ASDisplayNode (Yoga)
|
|
|
|
@property (nonatomic, strong, nullable) NSArray *yogaChildren;
|
|
|
|
- (void)addYogaChild:(ASDisplayNode *)child;
|
|
- (void)removeYogaChild:(ASDisplayNode *)child;
|
|
|
|
- (void)semanticContentAttributeDidChange:(UISemanticContentAttribute)attribute;
|
|
|
|
#if YOGA_TREE_CONTIGUOUS
|
|
@property (nonatomic, assign) BOOL yogaLayoutInProgress;
|
|
@property (nonatomic, strong, nullable) ASLayout *yogaCalculatedLayout;
|
|
// These methods should not normally be called directly.
|
|
- (void)invalidateCalculatedYogaLayout;
|
|
- (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize;
|
|
#endif
|
|
|
|
@end
|
|
|
|
@interface ASLayoutElementStyle (Yoga)
|
|
|
|
- (YGNodeRef)yogaNodeCreateIfNeeded;
|
|
@property (nonatomic, assign, readonly) YGNodeRef yogaNode;
|
|
|
|
@property (nonatomic, assign, readwrite) ASStackLayoutDirection flexDirection;
|
|
@property (nonatomic, assign, readwrite) YGDirection direction;
|
|
@property (nonatomic, assign, readwrite) ASStackLayoutJustifyContent justifyContent;
|
|
@property (nonatomic, assign, readwrite) ASStackLayoutAlignItems alignItems;
|
|
@property (nonatomic, assign, readwrite) YGPositionType positionType;
|
|
@property (nonatomic, assign, readwrite) ASEdgeInsets position;
|
|
@property (nonatomic, assign, readwrite) ASEdgeInsets margin;
|
|
@property (nonatomic, assign, readwrite) ASEdgeInsets padding;
|
|
@property (nonatomic, assign, readwrite) ASEdgeInsets border;
|
|
@property (nonatomic, assign, readwrite) CGFloat aspectRatio;
|
|
@property (nonatomic, assign, readwrite) YGWrap flexWrap;
|
|
|
|
@end
|
|
|
|
#endif
|
|
|
|
NS_ASSUME_NONNULL_END
|