mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-06 05:02:54 +00:00
Merge branch 'baseline' of github.com:rcancro/AsyncDisplayKit into baseline
This commit is contained in:
@@ -217,6 +217,16 @@
|
||||
509E68651B3AEDC5009B9150 /* CGRect+ASConvenience.h in Headers */ = {isa = PBXBuildFile; fileRef = 205F0E1F1B376416007741D0 /* CGRect+ASConvenience.h */; };
|
||||
509E68661B3AEDD7009B9150 /* CGRect+ASConvenience.m in Sources */ = {isa = PBXBuildFile; fileRef = 205F0E201B376416007741D0 /* CGRect+ASConvenience.m */; };
|
||||
6BDC61F61979037800E50D21 /* AsyncDisplayKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BDC61F51978FEA400E50D21 /* AsyncDisplayKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
9C204A641B86349B00313849 /* ASStackTextPositionedLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C204A621B86349B00313849 /* ASStackTextPositionedLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
9C204A651B86349B00313849 /* ASStackTextPositionedLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C204A621B86349B00313849 /* ASStackTextPositionedLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
9C204A661B86349B00313849 /* ASStackTextPositionedLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9C204A631B86349B00313849 /* ASStackTextPositionedLayout.mm */; };
|
||||
9C204A671B86349B00313849 /* ASStackTextPositionedLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9C204A631B86349B00313849 /* ASStackTextPositionedLayout.mm */; };
|
||||
9C3061061B857EC400D0530B /* ASStackTextLayoutSpec.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C3061041B857EC400D0530B /* ASStackTextLayoutSpec.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
9C3061071B857EC400D0530B /* ASStackTextLayoutSpec.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C3061041B857EC400D0530B /* ASStackTextLayoutSpec.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
9C3061081B857EC400D0530B /* ASStackTextLayoutSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9C3061051B857EC400D0530B /* ASStackTextLayoutSpec.mm */; };
|
||||
9C3061091B857EC400D0530B /* ASStackTextLayoutSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9C3061051B857EC400D0530B /* ASStackTextLayoutSpec.mm */; };
|
||||
9C49C36F1B853957000B0DD5 /* ASStackLayoutable.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C49C36E1B853957000B0DD5 /* ASStackLayoutable.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
9C49C3701B853961000B0DD5 /* ASStackLayoutable.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C49C36E1B853957000B0DD5 /* ASStackLayoutable.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
9F06E5CD1B4CAF4200F015D8 /* ASCollectionViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F06E5CC1B4CAF4200F015D8 /* ASCollectionViewTests.m */; };
|
||||
AC21EC101B3D0BF600C8B19A /* ASStackLayoutDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
AC3C4A511A1139C100143C57 /* ASCollectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = AC3C4A4F1A1139C100143C57 /* ASCollectionView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -445,7 +455,7 @@
|
||||
058D09D5195D050800B7D73C /* ASControlNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASControlNode.h; sourceTree = "<group>"; };
|
||||
058D09D6195D050800B7D73C /* ASControlNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASControlNode.m; sourceTree = "<group>"; };
|
||||
058D09D7195D050800B7D73C /* ASControlNode+Subclasses.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ASControlNode+Subclasses.h"; sourceTree = "<group>"; };
|
||||
058D09D8195D050800B7D73C /* ASDisplayNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ASDisplayNode.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
058D09D8195D050800B7D73C /* ASDisplayNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ASDisplayNode.h; sourceTree = "<group>"; };
|
||||
058D09D9195D050800B7D73C /* ASDisplayNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = ASDisplayNode.mm; sourceTree = "<group>"; };
|
||||
058D09DA195D050800B7D73C /* ASDisplayNode+Subclasses.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "ASDisplayNode+Subclasses.h"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
058D09DB195D050800B7D73C /* ASDisplayNodeExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASDisplayNodeExtras.h; sourceTree = "<group>"; };
|
||||
@@ -556,6 +566,11 @@
|
||||
4640521E1A3F83C40061C0BA /* ASMultidimensionalArrayUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASMultidimensionalArrayUtils.h; sourceTree = "<group>"; };
|
||||
4640521F1A3F83C40061C0BA /* ASMultidimensionalArrayUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASMultidimensionalArrayUtils.mm; sourceTree = "<group>"; };
|
||||
6BDC61F51978FEA400E50D21 /* AsyncDisplayKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AsyncDisplayKit.h; sourceTree = "<group>"; };
|
||||
9C204A621B86349B00313849 /* ASStackTextPositionedLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASStackTextPositionedLayout.h; sourceTree = "<group>"; };
|
||||
9C204A631B86349B00313849 /* ASStackTextPositionedLayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASStackTextPositionedLayout.mm; sourceTree = "<group>"; };
|
||||
9C3061041B857EC400D0530B /* ASStackTextLayoutSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASStackTextLayoutSpec.h; path = AsyncDisplayKit/Layout/ASStackTextLayoutSpec.h; sourceTree = "<group>"; };
|
||||
9C3061051B857EC400D0530B /* ASStackTextLayoutSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASStackTextLayoutSpec.mm; path = AsyncDisplayKit/Layout/ASStackTextLayoutSpec.mm; sourceTree = "<group>"; };
|
||||
9C49C36E1B853957000B0DD5 /* ASStackLayoutable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASStackLayoutable.h; path = AsyncDisplayKit/Layout/ASStackLayoutable.h; sourceTree = "<group>"; };
|
||||
9F06E5CC1B4CAF4200F015D8 /* ASCollectionViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCollectionViewTests.m; sourceTree = "<group>"; };
|
||||
AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASStackLayoutDefines.h; path = AsyncDisplayKit/Layout/ASStackLayoutDefines.h; sourceTree = "<group>"; };
|
||||
AC3C4A4F1A1139C100143C57 /* ASCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCollectionView.h; sourceTree = "<group>"; };
|
||||
@@ -687,7 +702,9 @@
|
||||
058D09AD195D04C000B7D73C /* Products */,
|
||||
FD40E2760492F0CAAEAD552D /* Pods */,
|
||||
);
|
||||
indentWidth = 2;
|
||||
sourceTree = "<group>";
|
||||
tabWidth = 2;
|
||||
};
|
||||
058D09AD195D04C000B7D73C /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
@@ -919,6 +936,8 @@
|
||||
ACF6ED481B17847A00DA7C62 /* ASStackPositionedLayout.mm */,
|
||||
ACF6ED491B17847A00DA7C62 /* ASStackUnpositionedLayout.h */,
|
||||
ACF6ED4A1B17847A00DA7C62 /* ASStackUnpositionedLayout.mm */,
|
||||
9C204A621B86349B00313849 /* ASStackTextPositionedLayout.h */,
|
||||
9C204A631B86349B00313849 /* ASStackTextPositionedLayout.mm */,
|
||||
);
|
||||
path = Private;
|
||||
sourceTree = "<group>";
|
||||
@@ -958,11 +977,14 @@
|
||||
ACF6ED131B17843500DA7C62 /* ASOverlayLayoutSpec.mm */,
|
||||
ACF6ED141B17843500DA7C62 /* ASRatioLayoutSpec.h */,
|
||||
ACF6ED151B17843500DA7C62 /* ASRatioLayoutSpec.mm */,
|
||||
9C49C36E1B853957000B0DD5 /* ASStackLayoutable.h */,
|
||||
AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */,
|
||||
ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */,
|
||||
ACF6ED171B17843500DA7C62 /* ASStackLayoutSpec.mm */,
|
||||
ACF6ED181B17843500DA7C62 /* ASStaticLayoutSpec.h */,
|
||||
ACF6ED191B17843500DA7C62 /* ASStaticLayoutSpec.mm */,
|
||||
9C3061041B857EC400D0530B /* ASStackTextLayoutSpec.h */,
|
||||
9C3061051B857EC400D0530B /* ASStackTextLayoutSpec.mm */,
|
||||
);
|
||||
name = Layout;
|
||||
path = ..;
|
||||
@@ -1004,6 +1026,7 @@
|
||||
files = (
|
||||
AC21EC101B3D0BF600C8B19A /* ASStackLayoutDefines.h in Headers */,
|
||||
AC47D9451B3BB41900AAEE9D /* ASRelativeSize.h in Headers */,
|
||||
9C49C36F1B853957000B0DD5 /* ASStackLayoutable.h in Headers */,
|
||||
ACF6ED511B17847A00DA7C62 /* ASStackUnpositionedLayout.h in Headers */,
|
||||
ACF6ED2D1B17843500DA7C62 /* ASRatioLayoutSpec.h in Headers */,
|
||||
ACF6ED261B17843500DA7C62 /* ASLayoutSpec.h in Headers */,
|
||||
@@ -1043,6 +1066,7 @@
|
||||
0574D5E219C110940097DC25 /* ASTableViewProtocols.h in Headers */,
|
||||
055F1A3C19ABD43F004DAFF1 /* ASCellNode.h in Headers */,
|
||||
058D0A53195D05DC00B7D73C /* _ASDisplayLayer.h in Headers */,
|
||||
9C204A641B86349B00313849 /* ASStackTextPositionedLayout.h in Headers */,
|
||||
058D0A54195D05DC00B7D73C /* _ASDisplayLayer.mm in Headers */,
|
||||
058D0A55195D05DC00B7D73C /* _ASDisplayView.h in Headers */,
|
||||
058D0A56195D05DC00B7D73C /* _ASDisplayView.mm in Headers */,
|
||||
@@ -1069,6 +1093,7 @@
|
||||
058D0A67195D05DC00B7D73C /* NSMutableAttributedString+TextKitAdditions.m in Headers */,
|
||||
058D0A68195D05EC00B7D73C /* _ASAsyncTransaction.h in Headers */,
|
||||
205F0E0F1B371875007741D0 /* UICollectionViewLayout+ASConvenience.h in Headers */,
|
||||
9C3061061B857EC400D0530B /* ASStackTextLayoutSpec.h in Headers */,
|
||||
058D0A69195D05EC00B7D73C /* _ASAsyncTransaction.m in Headers */,
|
||||
058D0A6A195D05EC00B7D73C /* _ASAsyncTransactionContainer+Private.h in Headers */,
|
||||
058D0A6B195D05EC00B7D73C /* _ASAsyncTransactionContainer.h in Headers */,
|
||||
@@ -1134,6 +1159,7 @@
|
||||
B35061FA1B010EFD0018CF92 /* ASControlNode+Subclasses.h in Headers */,
|
||||
B35062371B010EFD0018CF92 /* ASTextNodeWordKerner.h in Headers */,
|
||||
B35062261B010EFD0018CF92 /* ASRangeController.h in Headers */,
|
||||
9C204A651B86349B00313849 /* ASStackTextPositionedLayout.h in Headers */,
|
||||
B35062111B010EFD0018CF92 /* _ASDisplayView.h in Headers */,
|
||||
B35061F81B010EFD0018CF92 /* ASControlNode.h in Headers */,
|
||||
430E7C901B4C23F100697A4C /* ASIndexPath.h in Headers */,
|
||||
@@ -1143,6 +1169,7 @@
|
||||
B35061F31B010EFD0018CF92 /* ASCellNode.h in Headers */,
|
||||
34EFC76C1B701CED00AD841F /* ASOverlayLayoutSpec.h in Headers */,
|
||||
B35062201B010EFD0018CF92 /* ASLayoutController.h in Headers */,
|
||||
9C3061071B857EC400D0530B /* ASStackTextLayoutSpec.h in Headers */,
|
||||
B35062571B010F070018CF92 /* ASAssert.h in Headers */,
|
||||
B35062411B010EFD0018CF92 /* _ASAsyncTransactionGroup.h in Headers */,
|
||||
B350623C1B010EFD0018CF92 /* _ASAsyncTransaction.h in Headers */,
|
||||
@@ -1170,6 +1197,7 @@
|
||||
B350620C1B010EFD0018CF92 /* ASTableViewProtocols.h in Headers */,
|
||||
B35062481B010EFD0018CF92 /* _AS-objc-internal.h in Headers */,
|
||||
B350623F1B010EFD0018CF92 /* _ASAsyncTransactionContainer.h in Headers */,
|
||||
9C49C3701B853961000B0DD5 /* ASStackLayoutable.h in Headers */,
|
||||
34EFC7731B701D0700AD841F /* ASStaticLayoutSpec.h in Headers */,
|
||||
B35062081B010EFD0018CF92 /* ASScrollNode.h in Headers */,
|
||||
B35061F51B010EFD0018CF92 /* ASCollectionView.h in Headers */,
|
||||
@@ -1407,6 +1435,7 @@
|
||||
058D0A26195D050800B7D73C /* _ASCoreAnimationExtras.mm in Sources */,
|
||||
058D0A23195D050800B7D73C /* _ASAsyncTransactionContainer.m in Sources */,
|
||||
058D0A1E195D050800B7D73C /* ASTextNodeShadower.m in Sources */,
|
||||
9C204A661B86349B00313849 /* ASStackTextPositionedLayout.mm in Sources */,
|
||||
ACF6ED2E1B17843500DA7C62 /* ASRatioLayoutSpec.mm in Sources */,
|
||||
058D0A18195D050800B7D73C /* _ASDisplayLayer.mm in Sources */,
|
||||
ACF6ED321B17843500DA7C62 /* ASStaticLayoutSpec.mm in Sources */,
|
||||
@@ -1445,6 +1474,7 @@
|
||||
0549634A1A1EA066000F8E56 /* ASBasicImageDownloader.mm in Sources */,
|
||||
058D0A14195D050800B7D73C /* ASDisplayNode.mm in Sources */,
|
||||
058D0A1B195D050800B7D73C /* ASMutableAttributedStringBuilder.m in Sources */,
|
||||
9C3061081B857EC400D0530B /* ASStackTextLayoutSpec.mm in Sources */,
|
||||
058D0A2B195D050800B7D73C /* ASImageNode+CGExtras.m in Sources */,
|
||||
058D0A24195D050800B7D73C /* _ASAsyncTransactionGroup.m in Sources */,
|
||||
058D0A1C195D050800B7D73C /* ASTextNodeCoreTextAdditions.m in Sources */,
|
||||
@@ -1506,8 +1536,10 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9C3061091B857EC400D0530B /* ASStackTextLayoutSpec.mm in Sources */,
|
||||
34EFC7641B701CC600AD841F /* ASCenterLayoutSpec.mm in Sources */,
|
||||
B350623B1B010EFD0018CF92 /* NSMutableAttributedString+TextKitAdditions.m in Sources */,
|
||||
9C204A671B86349B00313849 /* ASStackTextPositionedLayout.mm in Sources */,
|
||||
B35062401B010EFD0018CF92 /* _ASAsyncTransactionContainer.m in Sources */,
|
||||
B35062311B010EFD0018CF92 /* ASTextNodeRenderer.mm in Sources */,
|
||||
B35062051B010EFD0018CF92 /* ASMultiplexImageNode.mm in Sources */,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#import <AsyncDisplayKit/ASDealloc2MainObject.h>
|
||||
#import <AsyncDisplayKit/ASDimension.h>
|
||||
|
||||
#import <AsyncDisplayKit/ASLayoutable.h>
|
||||
#import <AsyncDisplayKit/ASStackLayoutable.h>
|
||||
|
||||
/**
|
||||
* UIView creation block. Used to create the backing view of a new display node.
|
||||
@@ -40,7 +40,7 @@ typedef CALayer *(^ASDisplayNodeLayerBlock)();
|
||||
*
|
||||
*/
|
||||
|
||||
@interface ASDisplayNode : ASDealloc2MainObject <ASLayoutable>
|
||||
@interface ASDisplayNode : ASDealloc2MainObject <ASStackLayoutable>
|
||||
|
||||
|
||||
/** @name Initializing a node object */
|
||||
|
||||
@@ -453,6 +453,11 @@ void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block)
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (CGFloat)distanceToBaseline:(ASStackLayoutAlignItems)baselineAlignmentType
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (CGSize)measure:(CGSize)constrainedSize
|
||||
{
|
||||
return [self measureWithSizeRange:ASSizeRangeMake(CGSizeZero, constrainedSize)].size;
|
||||
|
||||
@@ -30,7 +30,7 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) {
|
||||
@abstract Draws interactive rich text.
|
||||
@discussion Backed by TextKit.
|
||||
*/
|
||||
@interface ASTextNode : ASControlNode
|
||||
@interface ASTextNode : ASControlNode <ASStackTextLayoutable>
|
||||
|
||||
/**
|
||||
@abstract The attributed string to show.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#import <AsyncDisplayKit/ASTextNodeTextKitHelpers.h>
|
||||
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
|
||||
|
||||
#import "ASInternalHelpers.h"
|
||||
#import "ASTextNodeRenderer.h"
|
||||
#import "ASTextNodeShadower.h"
|
||||
|
||||
@@ -107,6 +108,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
UILongPressGestureRecognizer *_longPressGestureRecognizer;
|
||||
}
|
||||
|
||||
@synthesize ascender = _ascender;
|
||||
@synthesize descender = _descender;
|
||||
|
||||
#pragma mark - NSObject
|
||||
|
||||
- (instancetype)init
|
||||
@@ -355,6 +359,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
self.isAccessibilityElement = YES;
|
||||
}
|
||||
});
|
||||
|
||||
_ascender = round([[attributedString attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL] ascender] * ASScreenScale())/ASScreenScale();
|
||||
_descender = round([[attributedString attribute:NSFontAttributeName atIndex:attributedString.length - 1 effectiveRange:NULL] descender] * ASScreenScale())/ASScreenScale();
|
||||
}
|
||||
|
||||
#pragma mark - Text Layout
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#import <AsyncDisplayKit/ASLayoutable.h>
|
||||
#import <AsyncDisplayKit/ASStackLayoutable.h>
|
||||
|
||||
/** A layout spec is an immutable object that describes a layout, loosely inspired by React. */
|
||||
@interface ASLayoutSpec : NSObject <ASLayoutable>
|
||||
@interface ASLayoutSpec : NSObject <ASStackLayoutable>
|
||||
|
||||
@end
|
||||
|
||||
@@ -20,43 +20,6 @@
|
||||
*/
|
||||
@protocol ASLayoutable <NSObject>
|
||||
|
||||
/**
|
||||
* @abstract Additional space to place before this object in the stacking direction.
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) CGFloat spacingBefore;
|
||||
|
||||
/**
|
||||
* @abstract Additional space to place after this object in the stacking direction.
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) CGFloat spacingAfter;
|
||||
|
||||
/**
|
||||
* @abstract If the sum of childrens' stack dimensions is less than the minimum size, should this object grow?
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) BOOL flexGrow;
|
||||
|
||||
/**
|
||||
* @abstract If the sum of childrens' stack dimensions is greater than the maximum size, should this object shrink?
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) BOOL flexShrink;
|
||||
|
||||
/**
|
||||
* @abstract Specifies the initial size in the stack dimension for this object.
|
||||
* Default to ASRelativeDimensionUnconstrained.
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) ASRelativeDimension flexBasis;
|
||||
|
||||
/**
|
||||
* @abstract Orientation of the object along cross axis, overriding alignItems
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) ASStackLayoutAlignSelf alignSelf;
|
||||
|
||||
/**
|
||||
* @abstract Calculate a layout based on given size range.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,45 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/** The direction children are stacked in */
|
||||
typedef NS_ENUM(NSUInteger, ASStackLayoutDirection) {
|
||||
/** Children are stacked vertically */
|
||||
ASStackLayoutDirectionVertical,
|
||||
/** Children are stacked horizontally */
|
||||
ASStackLayoutDirectionHorizontal,
|
||||
};
|
||||
|
||||
/** If no children are flexible, how should this spec justify its children in the available space? */
|
||||
typedef NS_ENUM(NSUInteger, ASStackLayoutJustifyContent) {
|
||||
/**
|
||||
On overflow, children overflow out of this spec's bounds on the right/bottom side.
|
||||
On underflow, children are left/top-aligned within this spec's bounds.
|
||||
*/
|
||||
ASStackLayoutJustifyContentStart,
|
||||
/**
|
||||
On overflow, children are centered and overflow on both sides.
|
||||
On underflow, children are centered within this spec's bounds in the stacking direction.
|
||||
*/
|
||||
ASStackLayoutJustifyContentCenter,
|
||||
/**
|
||||
On overflow, children overflow out of this spec's bounds on the left/top side.
|
||||
On underflow, children are right/bottom-aligned within this spec's bounds.
|
||||
*/
|
||||
ASStackLayoutJustifyContentEnd,
|
||||
};
|
||||
|
||||
/** Orientation of children along cross axis */
|
||||
typedef NS_ENUM(NSUInteger, ASStackLayoutAlignItems) {
|
||||
/** Align children to start of cross axis */
|
||||
ASStackLayoutAlignItemsStart,
|
||||
/** Align children with end of cross axis */
|
||||
ASStackLayoutAlignItemsEnd,
|
||||
/** Center children on cross axis */
|
||||
ASStackLayoutAlignItemsCenter,
|
||||
/** Expand children to fill cross axis */
|
||||
ASStackLayoutAlignItemsStretch
|
||||
};
|
||||
|
||||
/**
|
||||
Each child may override their parent stack's cross axis alignment.
|
||||
@see ASStackLayoutAlignItems
|
||||
|
||||
@@ -9,45 +9,7 @@
|
||||
*/
|
||||
|
||||
#import <AsyncDisplayKit/ASLayoutSpec.h>
|
||||
|
||||
/** The direction children are stacked in */
|
||||
typedef NS_ENUM(NSUInteger, ASStackLayoutDirection) {
|
||||
/** Children are stacked vertically */
|
||||
ASStackLayoutDirectionVertical,
|
||||
/** Children are stacked horizontally */
|
||||
ASStackLayoutDirectionHorizontal,
|
||||
};
|
||||
|
||||
/** If no children are flexible, how should this spec justify its children in the available space? */
|
||||
typedef NS_ENUM(NSUInteger, ASStackLayoutJustifyContent) {
|
||||
/**
|
||||
On overflow, children overflow out of this spec's bounds on the right/bottom side.
|
||||
On underflow, children are left/top-aligned within this spec's bounds.
|
||||
*/
|
||||
ASStackLayoutJustifyContentStart,
|
||||
/**
|
||||
On overflow, children are centered and overflow on both sides.
|
||||
On underflow, children are centered within this spec's bounds in the stacking direction.
|
||||
*/
|
||||
ASStackLayoutJustifyContentCenter,
|
||||
/**
|
||||
On overflow, children overflow out of this spec's bounds on the left/top side.
|
||||
On underflow, children are right/bottom-aligned within this spec's bounds.
|
||||
*/
|
||||
ASStackLayoutJustifyContentEnd,
|
||||
};
|
||||
|
||||
/** Orientation of children along cross axis */
|
||||
typedef NS_ENUM(NSUInteger, ASStackLayoutAlignItems) {
|
||||
/** Align children to start of cross axis */
|
||||
ASStackLayoutAlignItemsStart,
|
||||
/** Align children with end of cross axis */
|
||||
ASStackLayoutAlignItemsEnd,
|
||||
/** Center children on cross axis */
|
||||
ASStackLayoutAlignItemsCenter,
|
||||
/** Expand children to fill cross axis */
|
||||
ASStackLayoutAlignItemsStretch,
|
||||
};
|
||||
#import <AsyncDisplayKit/ASStackLayoutDefines.h>
|
||||
|
||||
typedef struct {
|
||||
/** Specifies the direction children are stacked in. */
|
||||
@@ -58,6 +20,10 @@ typedef struct {
|
||||
ASStackLayoutJustifyContent justifyContent;
|
||||
/** Orientation of children along cross axis */
|
||||
ASStackLayoutAlignItems alignItems;
|
||||
/**
|
||||
If YES the vertical spacing between two views is measured from the last baseline of the
|
||||
top view to the top of the bottom view*/
|
||||
BOOL baselineRelativeArrangement;
|
||||
} ASStackLayoutSpecStyle;
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,11 +20,12 @@
|
||||
#import "ASStackLayoutSpecUtilities.h"
|
||||
#import "ASStackPositionedLayout.h"
|
||||
#import "ASStackUnpositionedLayout.h"
|
||||
#import "ASThread.h"
|
||||
|
||||
@implementation ASStackLayoutSpec
|
||||
{
|
||||
ASStackLayoutSpecStyle _style;
|
||||
std::vector<id<ASLayoutable>> _children;
|
||||
std::vector<id<ASStackLayoutable>> _children;
|
||||
}
|
||||
|
||||
+ (instancetype)newWithStyle:(ASStackLayoutSpecStyle)style children:(NSArray *)children
|
||||
@@ -32,8 +33,10 @@
|
||||
ASStackLayoutSpec *spec = [super new];
|
||||
if (spec) {
|
||||
spec->_style = style;
|
||||
spec->_children = std::vector<id<ASLayoutable>>();
|
||||
for (id<ASLayoutable> child in children) {
|
||||
spec->_children = std::vector<id<ASStackLayoutable>>();
|
||||
for (id<ASStackLayoutable> child in children) {
|
||||
ASDisplayNodeAssert([child conformsToProtocol:@protocol(ASStackLayoutable)], @"child must conform to ASStackLayoutable");
|
||||
|
||||
spec->_children.push_back(child);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +54,7 @@
|
||||
const auto positionedLayout = ASStackPositionedLayout::compute(unpositionedLayout, _style, constrainedSize);
|
||||
const CGSize finalSize = directionSize(_style.direction, unpositionedLayout.stackDimensionSum, positionedLayout.crossSize);
|
||||
NSArray *sublayouts = [NSArray arrayWithObjects:&positionedLayout.sublayouts[0] count:positionedLayout.sublayouts.size()];
|
||||
|
||||
return [ASLayout newWithLayoutableObject:self
|
||||
size:ASSizeRangeClamp(constrainedSize, finalSize)
|
||||
sublayouts:sublayouts];
|
||||
|
||||
59
AsyncDisplayKit/Layout/ASStackLayoutable.h
Normal file
59
AsyncDisplayKit/Layout/ASStackLayoutable.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#import <AsyncDisplayKit/ASLayoutable.h>
|
||||
|
||||
@protocol ASStackLayoutable <ASLayoutable>
|
||||
|
||||
/**
|
||||
* @abstract Additional space to place before this object in the stacking direction.
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) CGFloat spacingBefore;
|
||||
|
||||
/**
|
||||
* @abstract Additional space to place after this object in the stacking direction.
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) CGFloat spacingAfter;
|
||||
|
||||
/**
|
||||
* @abstract If the sum of childrens' stack dimensions is less than the minimum size, should this object grow?
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) BOOL flexGrow;
|
||||
|
||||
/**
|
||||
* @abstract If the sum of childrens' stack dimensions is greater than the maximum size, should this object shrink?
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) BOOL flexShrink;
|
||||
|
||||
/**
|
||||
* @abstract Specifies the initial size in the stack dimension for this object.
|
||||
* Default to ASRelativeDimensionUnconstrained.
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) ASRelativeDimension flexBasis;
|
||||
|
||||
/**
|
||||
* @abstract Orientation of the object along cross axis, overriding alignItems
|
||||
* Used when attached to a stack layout.
|
||||
*/
|
||||
@property (nonatomic, readwrite) ASStackLayoutAlignSelf alignSelf;
|
||||
|
||||
@end
|
||||
|
||||
@protocol ASStackTextLayoutable <ASStackLayoutable>
|
||||
|
||||
@property (nonatomic, readwrite) CGFloat ascender;
|
||||
@property (nonatomic, readwrite) CGFloat descender;
|
||||
|
||||
@end
|
||||
49
AsyncDisplayKit/Layout/ASStackTextLayoutSpec.h
Normal file
49
AsyncDisplayKit/Layout/ASStackTextLayoutSpec.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#import <AsyncDisplayKit/ASStackLayoutSpec.h>
|
||||
|
||||
typedef NS_ENUM(NSUInteger, ASStackTextLayoutBaselineAlignment) {
|
||||
/** No baseline alignment. This is only valid for a vertical stack */
|
||||
ASStackTextLayoutBaselineAlignmentNone,
|
||||
/** Align all children to the first baseline. This is only valid for a horizontal stack */
|
||||
ASStackTextLayoutBaselineAlignmentFirst,
|
||||
/** Align all children to the last baseline. This is useful when a text node wraps and you want to align
|
||||
to the bottom baseline. This is only valid for a horizontal stack */
|
||||
ASStackTextLayoutBaselineAlignmentLast,
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
/** Describes how the stack will be laid out */
|
||||
ASStackLayoutSpecStyle stackLayoutStyle;
|
||||
|
||||
/** The type of baseline alignment */
|
||||
ASStackTextLayoutBaselineAlignment baselineAlignment;
|
||||
} ASStackTextLayoutSpecStyle;
|
||||
|
||||
|
||||
/**
|
||||
A specialized version of a stack layout that aligns its children on a baseline. This spec only works with
|
||||
ASStackTextLayoutable children.
|
||||
|
||||
If the spec is created with a horizontal direction, the children will be laid on a common baseline.
|
||||
If the spec is created with a vertical direction, a child's vertical spacing will be measured from its
|
||||
baseline instead of from the child's bounding box.
|
||||
*/
|
||||
@interface ASStackTextLayoutSpec : ASLayoutSpec <ASStackTextLayoutable>
|
||||
|
||||
/**
|
||||
@param style Specifies how children are laid out.
|
||||
@param children ASTextLayoutable children to be positioned.
|
||||
*/
|
||||
+ (instancetype)newWithStyle:(ASStackTextLayoutSpecStyle)style children:(NSArray *)children;
|
||||
|
||||
@end
|
||||
81
AsyncDisplayKit/Layout/ASStackTextLayoutSpec.mm
Normal file
81
AsyncDisplayKit/Layout/ASStackTextLayoutSpec.mm
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#import "ASStackTextLayoutSpec.h"
|
||||
#import "ASStackLayoutable.h"
|
||||
|
||||
#import <numeric>
|
||||
#import <vector>
|
||||
|
||||
#import "ASBaseDefines.h"
|
||||
#import "ASInternalHelpers.h"
|
||||
|
||||
#import "ASLayoutSpecUtilities.h"
|
||||
#import "ASStackLayoutSpecUtilities.h"
|
||||
#import "ASStackPositionedLayout.h"
|
||||
#import "ASStackUnpositionedLayout.h"
|
||||
#import "ASStackTextPositionedLayout.h"
|
||||
#import "ASThread.h"
|
||||
|
||||
|
||||
@implementation ASStackTextLayoutSpec
|
||||
{
|
||||
ASStackTextLayoutSpecStyle _textStyle;
|
||||
std::vector<id<ASStackLayoutable>> _stackChildren;
|
||||
ASDN::RecursiveMutex _propertyLock;
|
||||
}
|
||||
|
||||
@synthesize ascender = _ascender;
|
||||
@synthesize descender = _descender;
|
||||
|
||||
+ (instancetype)newWithStyle:(ASStackTextLayoutSpecStyle)style children:(NSArray *)children
|
||||
{
|
||||
ASDisplayNodeAssert((style.stackLayoutStyle.direction == ASStackLayoutDirectionHorizontal && style.baselineAlignment != ASStackTextLayoutBaselineAlignmentNone) || style.stackLayoutStyle.direction == ASStackLayoutDirectionVertical, @"baselineAlignment is set to none. If you don't need baseline alignment please use ASStackLayoutSpec");
|
||||
|
||||
ASStackTextLayoutSpec *spec = [super new];
|
||||
if (spec) {
|
||||
spec->_textStyle = style;
|
||||
spec->_stackChildren = std::vector<id<ASStackLayoutable>>();
|
||||
for (id<ASStackTextLayoutable> child in children) {
|
||||
ASDisplayNodeAssert([child conformsToProtocol:@protocol(ASStackTextLayoutable)], @"child must conform to ASStackLayoutable");
|
||||
|
||||
spec->_stackChildren.push_back(child);
|
||||
}
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
+ (instancetype)new
|
||||
{
|
||||
ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER();
|
||||
}
|
||||
|
||||
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASStackLayoutSpecStyle stackStyle = _textStyle.stackLayoutStyle;
|
||||
|
||||
const auto unpositionedLayout = ASStackUnpositionedLayout::compute(_stackChildren, stackStyle, constrainedSize);
|
||||
const auto positionedLayout = ASStackPositionedLayout::compute(unpositionedLayout, stackStyle, constrainedSize);
|
||||
const auto baselinePositionedLayout = ASStackTextPositionedLayout::compute(positionedLayout, _textStyle, constrainedSize);
|
||||
|
||||
const CGSize finalSize = directionSize(stackStyle.direction, unpositionedLayout.stackDimensionSum, baselinePositionedLayout.crossSize);
|
||||
|
||||
NSArray *sublayouts = [NSArray arrayWithObjects:&baselinePositionedLayout.sublayouts[0] count:baselinePositionedLayout.sublayouts.size()];
|
||||
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_ascender = baselinePositionedLayout.ascender;
|
||||
_descender = baselinePositionedLayout.descender;
|
||||
|
||||
|
||||
return [ASLayout newWithLayoutableObject:self
|
||||
size:ASSizeRangeClamp(constrainedSize, finalSize)
|
||||
sublayouts:sublayouts];
|
||||
}
|
||||
@end
|
||||
@@ -27,9 +27,12 @@ static CGFloat crossOffset(const ASStackLayoutSpecStyle &style,
|
||||
case ASStackLayoutAlignItemsStart:
|
||||
case ASStackLayoutAlignItemsStretch:
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static ASStackPositionedLayout stackedLayout(const ASStackLayoutSpecStyle &style,
|
||||
const CGFloat offset,
|
||||
const ASStackUnpositionedLayout &unpositionedLayout,
|
||||
@@ -44,7 +47,7 @@ static ASStackPositionedLayout stackedLayout(const ASStackLayoutSpecStyle &style
|
||||
const auto minCrossSize = crossDimension(style.direction, constrainedSize.min);
|
||||
const auto maxCrossSize = crossDimension(style.direction, constrainedSize.max);
|
||||
const CGFloat crossSize = MIN(MAX(minCrossSize, largestChildCrossSize), maxCrossSize);
|
||||
|
||||
|
||||
CGPoint p = directionPoint(style.direction, offset, 0);
|
||||
BOOL first = YES;
|
||||
auto stackedChildren = AS::map(unpositionedLayout.items, [&](const ASStackUnpositionedItem &l) -> ASLayout *{
|
||||
@@ -54,6 +57,7 @@ static ASStackPositionedLayout stackedLayout(const ASStackLayoutSpecStyle &style
|
||||
}
|
||||
first = NO;
|
||||
l.layout.position = p + directionPoint(style.direction, 0, crossOffset(style, l, crossSize));
|
||||
|
||||
p = p + directionPoint(style.direction, stackDimension(style.direction, l.layout.size) + l.child.spacingAfter, 0);
|
||||
return l.layout;
|
||||
});
|
||||
|
||||
26
AsyncDisplayKit/Private/ASStackTextPositionedLayout.h
Normal file
26
AsyncDisplayKit/Private/ASStackTextPositionedLayout.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#import "ASLayout.h"
|
||||
#import "ASDimension.h"
|
||||
#import "ASStackTextLayoutSpec.h"
|
||||
#import "ASStackPositionedLayout.h"
|
||||
|
||||
struct ASStackTextPositionedLayout {
|
||||
const std::vector<ASLayout *> sublayouts;
|
||||
const CGFloat crossSize;
|
||||
const CGFloat ascender;
|
||||
const CGFloat descender;
|
||||
|
||||
/** Given a positioned layout, computes each child position using baseline alignment. */
|
||||
static ASStackTextPositionedLayout compute(const ASStackPositionedLayout &positionedLayout,
|
||||
const ASStackTextLayoutSpecStyle &textStyle,
|
||||
const ASSizeRange &constrainedSize);
|
||||
};
|
||||
118
AsyncDisplayKit/Private/ASStackTextPositionedLayout.mm
Normal file
118
AsyncDisplayKit/Private/ASStackTextPositionedLayout.mm
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#import "ASStackTextPositionedLayout.h"
|
||||
|
||||
#import "ASLayoutSpecUtilities.h"
|
||||
#import "ASStackLayoutSpecUtilities.h"
|
||||
|
||||
static CGFloat baselineForItem(const ASStackTextLayoutSpecStyle &style,
|
||||
const ASLayout *layout) {
|
||||
|
||||
__weak id<ASStackTextLayoutable> textChild = (id<ASStackTextLayoutable>) layout.layoutableObject;
|
||||
switch (style.baselineAlignment) {
|
||||
case ASStackTextLayoutBaselineAlignmentNone:
|
||||
return 0;
|
||||
case ASStackTextLayoutBaselineAlignmentFirst:
|
||||
return textChild.ascender;
|
||||
case ASStackTextLayoutBaselineAlignmentLast:
|
||||
return layout.size.height + textChild.descender;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static CGFloat baselineOffset(const ASStackTextLayoutSpecStyle &style,
|
||||
const ASLayout *l,
|
||||
const CGFloat maxAscender,
|
||||
const CGFloat maxBaseline)
|
||||
{
|
||||
if (style.stackLayoutStyle.direction == ASStackLayoutDirectionHorizontal) {
|
||||
__weak id<ASStackTextLayoutable> textChild = (id<ASStackTextLayoutable>)l.layoutableObject;
|
||||
switch (style.baselineAlignment) {
|
||||
case ASStackTextLayoutBaselineAlignmentFirst:
|
||||
return maxAscender - textChild.ascender;
|
||||
case ASStackTextLayoutBaselineAlignmentLast:
|
||||
return maxBaseline + textChild.descender - textChild.ascender;
|
||||
case ASStackTextLayoutBaselineAlignmentNone:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static CGFloat maxDimensionForLayout(const ASLayout *l,
|
||||
const ASStackLayoutSpecStyle &style)
|
||||
{
|
||||
CGFloat maxDimension = crossDimension(style.direction, l.size);
|
||||
style.direction == ASStackLayoutDirectionVertical ? maxDimension += l.position.x : maxDimension += l.position.y;
|
||||
return maxDimension;
|
||||
}
|
||||
|
||||
ASStackTextPositionedLayout ASStackTextPositionedLayout::compute(const ASStackPositionedLayout &positionedLayout,
|
||||
const ASStackTextLayoutSpecStyle &textStyle,
|
||||
const ASSizeRange &constrainedSize)
|
||||
{
|
||||
ASStackLayoutSpecStyle stackStyle = textStyle.stackLayoutStyle;
|
||||
|
||||
|
||||
// Get the largest distance from the top of the stack to a baseline. This is the baseline we will align to.
|
||||
const auto baselineIt = std::max_element(positionedLayout.sublayouts.begin(), positionedLayout.sublayouts.end(), [&](const ASLayout *a, const ASLayout *b){
|
||||
return baselineForItem(textStyle, a) < baselineForItem(textStyle, b);
|
||||
});
|
||||
const CGFloat maxBaseline = baselineIt == positionedLayout.sublayouts.end() ? 0 : baselineForItem(textStyle, *baselineIt);
|
||||
|
||||
// find the largest ascender for all children. This value will be used in offset computation as well as sent back to the ASStackTextLayoutSpec as its ascender.
|
||||
const auto ascenderIt = std::max_element(positionedLayout.sublayouts.begin(), positionedLayout.sublayouts.end(), [&](const ASLayout *a, const ASLayout *b){
|
||||
return ((id<ASStackTextLayoutable>)a.layoutableObject).ascender < ((id<ASStackTextLayoutable>)b.layoutableObject).ascender;
|
||||
});
|
||||
const CGFloat maxAscender = baselineIt == positionedLayout.sublayouts.end() ? 0 : ((id<ASStackTextLayoutable>)(*ascenderIt).layoutableObject).ascender;
|
||||
|
||||
CGPoint p = CGPointZero;
|
||||
BOOL first = YES;
|
||||
auto stackedChildren = AS::map(positionedLayout.sublayouts, [&](ASLayout *l) -> ASLayout *{
|
||||
__weak id<ASStackTextLayoutable> textChild = (id<ASStackTextLayoutable>) l.layoutableObject;
|
||||
p = p + directionPoint(stackStyle.direction, textChild.spacingBefore, 0);
|
||||
if (first) {
|
||||
// if this is the first item use the previously computed start point
|
||||
p = l.position;
|
||||
} else {
|
||||
// otherwise add the stack spacing
|
||||
p = p + directionPoint(stackStyle.direction, stackStyle.spacing, 0);
|
||||
}
|
||||
first = NO;
|
||||
|
||||
// add the baseline offset. baselineOffset is only valid in the horizontal direction, so we always add to y
|
||||
l.position = p + CGPointMake(0, baselineOffset(textStyle, l, maxAscender, maxBaseline));
|
||||
|
||||
// If we are a vertical stack, add the minDescender (it is negative) to the spacing after. This will alter the stack spacing to be on baselines instead of bounding boxes
|
||||
CGFloat spacingAfterBaseline = (stackStyle.direction == ASStackLayoutDirectionVertical) ? textChild.descender : 0;
|
||||
p = p + directionPoint(stackStyle.direction, stackDimension(stackStyle.direction, l.size) + textChild.spacingAfter + spacingAfterBaseline, 0);
|
||||
|
||||
return l;
|
||||
});
|
||||
|
||||
// The cross dimension is the max of the childrens' cross dimensions (clamped to our constraint below).
|
||||
const auto it = std::max_element(stackedChildren.begin(), stackedChildren.end(),
|
||||
[&](ASLayout *a, ASLayout *b) {
|
||||
return maxDimensionForLayout(a, stackStyle) < maxDimensionForLayout(b, stackStyle);
|
||||
});
|
||||
const auto largestChildCrossSize = it == stackedChildren.end() ? 0 : maxDimensionForLayout(*it, stackStyle);
|
||||
const auto minCrossSize = crossDimension(stackStyle.direction, constrainedSize.min);
|
||||
const auto maxCrossSize = crossDimension(stackStyle.direction, constrainedSize.max);
|
||||
const CGFloat crossSize = MIN(MAX(minCrossSize, largestChildCrossSize), maxCrossSize);
|
||||
|
||||
// find the child with the largest height. Use that child's descender as the descender to pass back to the ASStackTextLayoutSpec.
|
||||
const auto descenderIt = std::max_element(stackedChildren.begin(), stackedChildren.end(), [&](const ASLayout *a, const ASLayout *b){
|
||||
return a.position.y + a.size.height < b.position.y + b.size.height;
|
||||
});
|
||||
const CGFloat minDescender = descenderIt == stackedChildren.end() ? 0 : ((id<ASStackTextLayoutable>)(*descenderIt).layoutableObject).descender;
|
||||
|
||||
return {stackedChildren, crossSize, maxAscender, minDescender};
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
struct ASStackUnpositionedItem {
|
||||
/** The original source child. */
|
||||
id<ASLayoutable> child;
|
||||
id<ASStackLayoutable> child;
|
||||
/** The proposed layout. */
|
||||
ASLayout *layout;
|
||||
};
|
||||
@@ -30,7 +30,7 @@ struct ASStackUnpositionedLayout {
|
||||
const CGFloat violation;
|
||||
|
||||
/** Given a set of children, computes the unpositioned layouts for those children. */
|
||||
static ASStackUnpositionedLayout compute(const std::vector<id<ASLayoutable>> &children,
|
||||
static ASStackUnpositionedLayout compute(const std::vector<id<ASStackLayoutable>> &children,
|
||||
const ASStackLayoutSpecStyle &style,
|
||||
const ASSizeRange &sizeRange);
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
/**
|
||||
Sizes the child given the parameters specified, and returns the computed layout.
|
||||
*/
|
||||
static ASLayout *crossChildLayout(const id<ASLayoutable> child,
|
||||
static ASLayout *crossChildLayout(const id<ASStackLayoutable> child,
|
||||
const ASStackLayoutSpecStyle style,
|
||||
const CGFloat stackMin,
|
||||
const CGFloat stackMax,
|
||||
@@ -186,7 +186,7 @@ static std::function<BOOL(const ASStackUnpositionedItem &)> isFlexibleInViolatio
|
||||
}
|
||||
}
|
||||
|
||||
ASDISPLAYNODE_INLINE BOOL isFlexibleInBothDirections(id<ASLayoutable> child)
|
||||
ASDISPLAYNODE_INLINE BOOL isFlexibleInBothDirections(id<ASStackLayoutable> child)
|
||||
{
|
||||
return child.flexGrow && child.flexShrink;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ ASDISPLAYNODE_INLINE BOOL isFlexibleInBothDirections(id<ASLayoutable> child)
|
||||
If we have a single flexible (both shrinkable and growable) child, and our allowed size range is set to a specific
|
||||
number then we may avoid the first "intrinsic" size calculation.
|
||||
*/
|
||||
ASDISPLAYNODE_INLINE BOOL useOptimizedFlexing(const std::vector<id<ASLayoutable>> &children,
|
||||
ASDISPLAYNODE_INLINE BOOL useOptimizedFlexing(const std::vector<id<ASStackLayoutable>> &children,
|
||||
const ASStackLayoutSpecStyle &style,
|
||||
const ASSizeRange &sizeRange)
|
||||
{
|
||||
@@ -283,7 +283,7 @@ static void flexChildrenAlongStackDimension(std::vector<ASStackUnpositionedItem>
|
||||
Performs the first unconstrained layout of the children, generating the unpositioned items that are then flexed and
|
||||
stretched.
|
||||
*/
|
||||
static std::vector<ASStackUnpositionedItem> layoutChildrenAlongUnconstrainedStackDimension(const std::vector<id<ASLayoutable>> &children,
|
||||
static std::vector<ASStackUnpositionedItem> layoutChildrenAlongUnconstrainedStackDimension(const std::vector<id<ASStackLayoutable>> &children,
|
||||
const ASStackLayoutSpecStyle &style,
|
||||
const ASSizeRange &sizeRange,
|
||||
const CGSize size,
|
||||
@@ -292,7 +292,7 @@ static std::vector<ASStackUnpositionedItem> layoutChildrenAlongUnconstrainedStac
|
||||
const CGFloat minCrossDimension = crossDimension(style.direction, sizeRange.min);
|
||||
const CGFloat maxCrossDimension = crossDimension(style.direction, sizeRange.max);
|
||||
|
||||
return AS::map(children, [&](id<ASLayoutable> child) -> ASStackUnpositionedItem {
|
||||
return AS::map(children, [&](id<ASStackLayoutable> child) -> ASStackUnpositionedItem {
|
||||
const BOOL isUnconstrainedFlexBasis = ASRelativeDimensionEqualToRelativeDimension(ASRelativeDimensionUnconstrained, child.flexBasis);
|
||||
const CGFloat exactStackDimension = ASRelativeDimensionResolve(child.flexBasis, stackDimension(style.direction, size));
|
||||
|
||||
@@ -312,7 +312,7 @@ static std::vector<ASStackUnpositionedItem> layoutChildrenAlongUnconstrainedStac
|
||||
});
|
||||
}
|
||||
|
||||
ASStackUnpositionedLayout ASStackUnpositionedLayout::compute(const std::vector<id<ASLayoutable>> &children,
|
||||
ASStackUnpositionedLayout ASStackUnpositionedLayout::compute(const std::vector<id<ASStackLayoutable>> &children,
|
||||
const ASStackLayoutSpecStyle &style,
|
||||
const ASSizeRange &sizeRange)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user