mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Added method to ASLayoutable to allow a layoutable to override how it will be added to the layoutSpec.
Also moved ASStaticLayoutSpec to act more like the other layouts.
This commit is contained in:
@@ -23,9 +23,6 @@
|
||||
#import "ASThread.h"
|
||||
|
||||
@implementation ASStackLayoutSpec
|
||||
{
|
||||
std::vector<id<ASStackLayoutable>> _children;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
@@ -47,26 +44,10 @@
|
||||
_spacing = spacing;
|
||||
_justifyContent = justifyContent;
|
||||
|
||||
_children = std::vector<id<ASStackLayoutable>>();
|
||||
for (id<ASStackLayoutable> child in children) {
|
||||
_children.push_back(child);
|
||||
}
|
||||
[self setChildren:children];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)addChild:(id<ASStackLayoutable>)child
|
||||
{
|
||||
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
|
||||
_children.push_back(child);
|
||||
}
|
||||
|
||||
- (void)addChildren:(NSArray *)children
|
||||
{
|
||||
for (id<ASStackLayoutable> child in children) {
|
||||
[self addChild:child];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setDirection:(ASStackLayoutDirection)direction
|
||||
{
|
||||
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
|
||||
@@ -91,10 +72,32 @@
|
||||
_spacing = spacing;
|
||||
}
|
||||
|
||||
- (void)setChildren:(NSArray *)children
|
||||
{
|
||||
[super setChildren:children];
|
||||
|
||||
#if DEBUG
|
||||
for (id<ASStackLayoutable> child in children) {
|
||||
ASDisplayNodeAssert(([child finalLayoutable] == child && [child conformsToProtocol:@protocol(ASStackLayoutable)]) || ([child finalLayoutable] != child && [[child finalLayoutable] conformsToProtocol:@protocol(ASStackLayoutable)]), @"child must conform to ASBaselineLayoutable");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)setChild:(id<ASLayoutable>)child forIdentifier:(NSString *)identifier
|
||||
{
|
||||
ASDisplayNodeAssert(NO, @"ASStackLayoutSpec only supports setChildren");
|
||||
}
|
||||
|
||||
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = _direction, .spacing = _spacing, .justifyContent = _justifyContent, .alignItems = _alignItems};
|
||||
const auto unpositionedLayout = ASStackUnpositionedLayout::compute(_children, style, constrainedSize);
|
||||
std::vector<id<ASStackLayoutable>> stackChildren = std::vector<id<ASStackLayoutable>>();
|
||||
for (id<ASStackLayoutable> child in self.children) {
|
||||
NSAssert([child conformsToProtocol:@protocol(ASStackLayoutable)], @"Child must implement ASStackLayoutable");
|
||||
stackChildren.push_back(child);
|
||||
}
|
||||
|
||||
const auto unpositionedLayout = ASStackUnpositionedLayout::compute(stackChildren, style, constrainedSize);
|
||||
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()];
|
||||
|
||||
Reference in New Issue
Block a user