mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 03:09:56 +00:00
Fixed infinite recursion in finalLayoutable, removed child properties from ASLayoutSpecs
This commit is contained in:
parent
84cd80c41d
commit
5786bc1b5b
@ -1849,8 +1849,9 @@ static void _recursivelySetDisplaySuspended(ASDisplayNode *node, CALayer *layer,
|
||||
return !self.layerBacked && [self.view canPerformAction:action withSender:sender];
|
||||
}
|
||||
|
||||
- (id<ASLayoutable>)finalLayoutable {
|
||||
return self;
|
||||
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
@interface ASBackgroundLayoutSpec : ASLayoutSpec
|
||||
|
||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
||||
@property (nonatomic, strong) id<ASLayoutable> background;
|
||||
|
||||
/**
|
||||
|
||||
@ -39,7 +39,6 @@ typedef NS_OPTIONS(NSUInteger, ASCenterLayoutSpecSizingOptions) {
|
||||
|
||||
@property (nonatomic, assign) ASCenterLayoutSpecCenteringOptions centeringOptions;
|
||||
@property (nonatomic, assign) ASCenterLayoutSpecSizingOptions sizingOptions;
|
||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
||||
|
||||
/**
|
||||
* Initializer.
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
*/
|
||||
@interface ASInsetLayoutSpec : ASLayoutSpec
|
||||
|
||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
||||
@property (nonatomic, assign) UIEdgeInsets insets;
|
||||
|
||||
/**
|
||||
|
||||
@ -16,11 +16,18 @@
|
||||
- (ASLayoutOptions *)layoutOptions\
|
||||
{\
|
||||
dispatch_once(&_layoutOptionsInitializeToken, ^{\
|
||||
if (_layoutOptions == nil) {\
|
||||
_layoutOptions = [[[ASLayoutOptions defaultLayoutOptionsClass] alloc] init];\
|
||||
}\
|
||||
});\
|
||||
return _layoutOptions;\
|
||||
}\
|
||||
\
|
||||
- (void)setLayoutOptions:(ASLayoutOptions *)layoutOptions\
|
||||
{\
|
||||
_layoutOptions = layoutOptions;\
|
||||
}\
|
||||
\
|
||||
- (CGFloat)spacingBefore\
|
||||
{\
|
||||
return self.layoutOptions.spacingBefore;\
|
||||
|
||||
@ -49,9 +49,9 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
||||
return [ASLayout layoutWithLayoutableObject:self size:constrainedSize.min];
|
||||
}
|
||||
|
||||
- (id<ASLayoutable>)finalLayoutable
|
||||
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec;
|
||||
{
|
||||
return self;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setChild:(id<ASLayoutable>)child;
|
||||
@ -61,14 +61,14 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
||||
|
||||
- (id<ASLayoutable>)layoutableToAddFromLayoutable:(id<ASLayoutable>)child
|
||||
{
|
||||
ASLayoutOptions *layoutOptions = [ASLayoutSpec layoutOptionsForChild:child];
|
||||
id<ASLayoutable> finalLayoutable = [child finalLayoutable];
|
||||
ASLayoutOptions *layoutOptions = [child layoutOptions];
|
||||
layoutOptions.isMutable = NO;
|
||||
|
||||
if (finalLayoutable != child) {
|
||||
id<ASLayoutable> finalLayoutable = [child finalLayoutableWithParent:self];
|
||||
if (finalLayoutable) {
|
||||
ASLayoutOptions *finalLayoutOptions = [layoutOptions copy];
|
||||
finalLayoutOptions.isMutable = NO;
|
||||
[ASLayoutSpec associateLayoutOptions:finalLayoutOptions withChild:finalLayoutable];
|
||||
finalLayoutable.layoutOptions = finalLayoutOptions;
|
||||
return finalLayoutable;
|
||||
}
|
||||
return child;
|
||||
@ -107,35 +107,5 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
||||
return self.layoutChildren[kDefaultChildrenKey];
|
||||
}
|
||||
|
||||
static Class gLayoutOptionsClass = [ASLayoutOptions class];
|
||||
+ (void)setLayoutOptionsClass:(Class)layoutOptionsClass
|
||||
{
|
||||
gLayoutOptionsClass = layoutOptionsClass;
|
||||
}
|
||||
|
||||
+ (ASLayoutOptions *)optionsForChild:(id<ASLayoutable>)child
|
||||
{
|
||||
ASLayoutOptions *layoutOptions = [[gLayoutOptionsClass alloc] init];;
|
||||
[layoutOptions setValuesFromLayoutable:child];
|
||||
layoutOptions.isMutable = NO;
|
||||
return layoutOptions;
|
||||
}
|
||||
|
||||
+ (void)associateLayoutOptions:(ASLayoutOptions *)layoutOptions withChild:(id<ASLayoutable>)child
|
||||
{
|
||||
objc_setAssociatedObject(child, @selector(setChild:), layoutOptions, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
+ (ASLayoutOptions *)layoutOptionsForChild:(id<ASLayoutable>)child
|
||||
{
|
||||
ASLayoutOptions *layoutOptions = objc_getAssociatedObject(child, @selector(setChild:));
|
||||
if (layoutOptions == nil) {
|
||||
layoutOptions = [self optionsForChild:child];
|
||||
[self associateLayoutOptions:layoutOptions withChild:child];
|
||||
}
|
||||
return objc_getAssociatedObject(child, @selector(setChild:));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@ -14,6 +14,6 @@
|
||||
@class ASLayoutOptions;
|
||||
|
||||
@protocol ASLayoutablePrivate <NSObject>
|
||||
- (ASLayoutSpec *)finalLayoutable;
|
||||
@property (nonatomic, strong, readonly) ASLayoutOptions *layoutOptions;
|
||||
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec;
|
||||
@property (nonatomic, strong) ASLayoutOptions *layoutOptions;
|
||||
@end
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
@interface ASOverlayLayoutSpec : ASLayoutSpec
|
||||
|
||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
||||
@property (nonatomic, strong) id<ASLayoutable> overlay;
|
||||
|
||||
+ (instancetype)overlayLayoutSpecWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay;
|
||||
|
||||
@ -49,7 +49,7 @@ static NSString * const kOverlayChildKey = @"kOverlayChildKey";
|
||||
*/
|
||||
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASLayout *contentsLayout = [_child measureWithSizeRange:constrainedSize];
|
||||
ASLayout *contentsLayout = [self.child measureWithSizeRange:constrainedSize];
|
||||
contentsLayout.position = CGPointZero;
|
||||
NSMutableArray *sublayouts = [NSMutableArray arrayWithObject:contentsLayout];
|
||||
if (self.overlay) {
|
||||
|
||||
@ -31,8 +31,6 @@
|
||||
**/
|
||||
@interface ASRatioLayoutSpec : ASLayoutSpec
|
||||
|
||||
|
||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
||||
@property (nonatomic, assign) CGFloat ratio;
|
||||
|
||||
+ (instancetype)ratioLayoutSpecWithRatio:(CGFloat)ratio child:(id<ASLayoutable>)child;
|
||||
|
||||
@ -154,8 +154,6 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides) {
|
||||
|
||||
@property (nonatomic, assign) CGFloat contentsScaleForDisplay;
|
||||
|
||||
- (id<ASLayoutable>)finalLayoutable;
|
||||
|
||||
@end
|
||||
|
||||
@interface UIView (ASDisplayNodeInternal)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user