mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-10 22:45:16 +00:00
* Initial commit for adding a size constraint to ASLayoutable's * Some more commits * Fix sample projects in extra/ * Remove preferredFrameSize test of ASEditableTextNode * Remove preferredFrameSize from examples_extra * Add deprecation warning to -[ASDisplayNode preferredFrameSize] * Add deprecation warning to -[ASDisplayNode measureWithSizeRange:] * Commit * Commit * Remove ASRelativeSizeRange * Make ASRelativeSize private * Adjust examples * Improve setting of -[ASLayoutable size] with points or fractions * Add ASWrapperLayoutSpec * Improve creation of ASRelativeDimension * Add `preferredFrameSize` back and add deprecated logging * Add `layoutSpecBlock` setter and getter and add locking for it * Add better documentation and fix macros to create ASRelativeDimension * Create new ASSizeRangeMake with just a CGSize as parameter * Update Kitten and Social App Layout example * Add layoutThatFits: and deprecate measure: * Rename ASRelativeDimension to ASDimension * Fix examples for ASDimension renaming * Remove fancy height and width setter * Fix ASDimension helper * Rename -[ASLayout layoutableObject] to -[ASLayout layoutable] * Update layout related methods and more clearer documentation around how to use it * Deprecate old ASLayout class constructors * Don't unnecessary recalculate layout if constrained or parent size did not change * Use shared pointer for ASDisplayNodeLayout * Fix rebase conflicts * Add documentation and move implementation in mm file of ASDisplayNodeLayout * Fix test errors * Rename ASSize to ASLayoutableSize * Address comments * Rename setSizeFromCGSize to setSizeWithCGSize * Improve inline functions in ASDimension * Fix rebase conflicts
159 lines
5.2 KiB
Objective-C
159 lines
5.2 KiB
Objective-C
//
|
|
// ASLayout.h
|
|
// AsyncDisplayKit
|
|
//
|
|
// 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 root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#import <UIKit/UIKit.h>
|
|
#import <AsyncDisplayKit/ASAssert.h>
|
|
#import <AsyncDisplayKit/ASLayoutable.h>
|
|
#import <AsyncDisplayKit/ASDimension.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
ASDISPLAYNODE_EXTERN_C_BEGIN
|
|
|
|
extern CGPoint const CGPointNull;
|
|
|
|
extern BOOL CGPointIsNull(CGPoint point);
|
|
|
|
/**
|
|
* Safely calculates the layout of the given root layoutable by guarding against nil nodes.
|
|
* @param rootLayoutable The root node to calculate the layout for.
|
|
* @param sizeRange The size range to calculate the root layout within.
|
|
*/
|
|
extern ASLayout *ASCalculateRootLayout(id<ASLayoutable> rootLayoutable, const ASSizeRange sizeRange);
|
|
|
|
/**
|
|
* Safely computes the layout of the given node by guarding against nil nodes.
|
|
* @param component The component to calculate the layout for.
|
|
* @param sizeRange The size range to calculate the node layout within.
|
|
* @param parentSize The parent size of the node to calculate the layout for.
|
|
*/
|
|
extern ASLayout *ASCalculateLayout(id<ASLayoutable> layoutable, const ASSizeRange sizeRange, const CGSize parentSize);
|
|
|
|
ASDISPLAYNODE_EXTERN_C_END
|
|
|
|
/**
|
|
* A node in the layout tree that represents the size and position of the object that created it (ASLayoutable).
|
|
*/
|
|
@interface ASLayout : NSObject
|
|
|
|
/**
|
|
* The underlying object described by this layout
|
|
*/
|
|
@property (nonatomic, weak, readonly) id<ASLayoutable> layoutable;
|
|
|
|
/**
|
|
* The type of ASLayoutable that created this layout
|
|
*/
|
|
@property (nonatomic, assign, readonly) ASLayoutableType type;
|
|
|
|
/**
|
|
* Size of the current layout
|
|
*/
|
|
@property (nonatomic, assign, readonly) CGSize size;
|
|
|
|
/**
|
|
* Position in parent. Default to CGPointNull.
|
|
*
|
|
* @discussion When being used as a sublayout, this property must not equal CGPointNull.
|
|
*/
|
|
@property (nonatomic, assign, readwrite) CGPoint position;
|
|
|
|
/**
|
|
* Array of ASLayouts. Each must have a valid non-null position.
|
|
*/
|
|
@property (nonatomic, copy, readonly) NSArray<ASLayout *> *sublayouts;
|
|
|
|
/**
|
|
* @abstract Returns a valid frame for the current layout computed with the size and position.
|
|
* @discussion Clamps the layout's origin or position to 0 if any of the calculated values are infinite.
|
|
*/
|
|
@property (nonatomic, assign, readonly) CGRect frame;
|
|
|
|
/**
|
|
* Designated initializer
|
|
*/
|
|
- (instancetype)initWithLayoutable:(id<ASLayoutable>)layoutable
|
|
size:(CGSize)size
|
|
position:(CGPoint)position
|
|
sublayouts:(nullable NSArray<ASLayout *> *)sublayouts NS_DESIGNATED_INITIALIZER;
|
|
|
|
/**
|
|
* Convenience class initializer for layout construction.
|
|
*
|
|
* @param layoutable The backing ASLayoutable object.
|
|
* @param size The size of this layout.
|
|
* @param position The position of this layout within its parent (if available).
|
|
* @param sublayouts Sublayouts belong to the new layout.
|
|
*/
|
|
+ (instancetype)layoutWithLayoutable:(id<ASLayoutable>)layoutable
|
|
size:(CGSize)size
|
|
position:(CGPoint)position
|
|
sublayouts:(nullable NSArray<ASLayout *> *)sublayouts;
|
|
|
|
/**
|
|
* Convenience initializer that has CGPointNull position.
|
|
* Best used by ASDisplayNode subclasses that are manually creating a layout for -calculateLayoutThatFits:,
|
|
* or for ASLayoutSpec subclasses that are referencing the "self" level in the layout tree,
|
|
* or for creating a sublayout of which the position is yet to be determined.
|
|
*
|
|
* @param layoutable The backing ASLayoutable object.
|
|
* @param size The size of this layout.
|
|
* @param sublayouts Sublayouts belong to the new layout.
|
|
*/
|
|
+ (instancetype)layoutWithLayoutable:(id<ASLayoutable>)layoutable
|
|
size:(CGSize)size
|
|
sublayouts:(nullable NSArray<ASLayout *> *)sublayouts;
|
|
|
|
/**
|
|
* Convenience that has CGPointNull position and no sublayouts.
|
|
* Best used for creating a layout that has no sublayouts, and is either a root one
|
|
* or a sublayout of which the position is yet to be determined.
|
|
*
|
|
* @param layoutable The backing ASLayoutable object.
|
|
* @param size The size of this layout.
|
|
*/
|
|
+ (instancetype)layoutWithLayoutable:(id<ASLayoutable>)layoutable
|
|
size:(CGSize)size;
|
|
/**
|
|
* Convenience initializer that creates a layout based on the values of the given layout, with a new position
|
|
*
|
|
* @param layout The layout to use to create the new layout
|
|
* @param position The position of the new layout
|
|
*/
|
|
+ (instancetype)layoutWithLayout:(ASLayout *)layout position:(CGPoint)position;
|
|
|
|
/**
|
|
* Traverses the existing layout tree and generates a new tree that represents only ASDisplayNode layouts
|
|
*/
|
|
- (ASLayout *)filteredNodeLayoutTree;
|
|
|
|
@end
|
|
|
|
@interface ASLayout (Unavailable)
|
|
|
|
- (instancetype)init __unavailable;
|
|
|
|
@end
|
|
|
|
#pragma mark - Debugging
|
|
|
|
@interface ASLayout (Debugging)
|
|
|
|
/**
|
|
* Recrusively output the description of the layout tree.
|
|
*/
|
|
- (NSString *)recursiveDescription;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|