mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 11:50: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];
|
return !self.layerBacked && [self.view canPerformAction:action withSender:sender];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id<ASLayoutable>)finalLayoutable {
|
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec
|
||||||
return self;
|
{
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
@interface ASBackgroundLayoutSpec : ASLayoutSpec
|
@interface ASBackgroundLayoutSpec : ASLayoutSpec
|
||||||
|
|
||||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
|
||||||
@property (nonatomic, strong) id<ASLayoutable> background;
|
@property (nonatomic, strong) id<ASLayoutable> background;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -39,7 +39,6 @@ typedef NS_OPTIONS(NSUInteger, ASCenterLayoutSpecSizingOptions) {
|
|||||||
|
|
||||||
@property (nonatomic, assign) ASCenterLayoutSpecCenteringOptions centeringOptions;
|
@property (nonatomic, assign) ASCenterLayoutSpecCenteringOptions centeringOptions;
|
||||||
@property (nonatomic, assign) ASCenterLayoutSpecSizingOptions sizingOptions;
|
@property (nonatomic, assign) ASCenterLayoutSpecSizingOptions sizingOptions;
|
||||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializer.
|
* Initializer.
|
||||||
|
|||||||
@ -29,7 +29,6 @@
|
|||||||
*/
|
*/
|
||||||
@interface ASInsetLayoutSpec : ASLayoutSpec
|
@interface ASInsetLayoutSpec : ASLayoutSpec
|
||||||
|
|
||||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
|
||||||
@property (nonatomic, assign) UIEdgeInsets insets;
|
@property (nonatomic, assign) UIEdgeInsets insets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -16,11 +16,18 @@
|
|||||||
- (ASLayoutOptions *)layoutOptions\
|
- (ASLayoutOptions *)layoutOptions\
|
||||||
{\
|
{\
|
||||||
dispatch_once(&_layoutOptionsInitializeToken, ^{\
|
dispatch_once(&_layoutOptionsInitializeToken, ^{\
|
||||||
|
if (_layoutOptions == nil) {\
|
||||||
_layoutOptions = [[[ASLayoutOptions defaultLayoutOptionsClass] alloc] init];\
|
_layoutOptions = [[[ASLayoutOptions defaultLayoutOptionsClass] alloc] init];\
|
||||||
|
}\
|
||||||
});\
|
});\
|
||||||
return _layoutOptions;\
|
return _layoutOptions;\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
|
- (void)setLayoutOptions:(ASLayoutOptions *)layoutOptions\
|
||||||
|
{\
|
||||||
|
_layoutOptions = layoutOptions;\
|
||||||
|
}\
|
||||||
|
\
|
||||||
- (CGFloat)spacingBefore\
|
- (CGFloat)spacingBefore\
|
||||||
{\
|
{\
|
||||||
return self.layoutOptions.spacingBefore;\
|
return self.layoutOptions.spacingBefore;\
|
||||||
|
|||||||
@ -49,9 +49,9 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
|||||||
return [ASLayout layoutWithLayoutableObject:self size:constrainedSize.min];
|
return [ASLayout layoutWithLayoutableObject:self size:constrainedSize.min];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id<ASLayoutable>)finalLayoutable
|
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec;
|
||||||
{
|
{
|
||||||
return self;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setChild:(id<ASLayoutable>)child;
|
- (void)setChild:(id<ASLayoutable>)child;
|
||||||
@ -61,14 +61,14 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
|||||||
|
|
||||||
- (id<ASLayoutable>)layoutableToAddFromLayoutable:(id<ASLayoutable>)child
|
- (id<ASLayoutable>)layoutableToAddFromLayoutable:(id<ASLayoutable>)child
|
||||||
{
|
{
|
||||||
ASLayoutOptions *layoutOptions = [ASLayoutSpec layoutOptionsForChild:child];
|
ASLayoutOptions *layoutOptions = [child layoutOptions];
|
||||||
id<ASLayoutable> finalLayoutable = [child finalLayoutable];
|
|
||||||
layoutOptions.isMutable = NO;
|
layoutOptions.isMutable = NO;
|
||||||
|
|
||||||
if (finalLayoutable != child) {
|
id<ASLayoutable> finalLayoutable = [child finalLayoutableWithParent:self];
|
||||||
|
if (finalLayoutable) {
|
||||||
ASLayoutOptions *finalLayoutOptions = [layoutOptions copy];
|
ASLayoutOptions *finalLayoutOptions = [layoutOptions copy];
|
||||||
finalLayoutOptions.isMutable = NO;
|
finalLayoutOptions.isMutable = NO;
|
||||||
[ASLayoutSpec associateLayoutOptions:finalLayoutOptions withChild:finalLayoutable];
|
finalLayoutable.layoutOptions = finalLayoutOptions;
|
||||||
return finalLayoutable;
|
return finalLayoutable;
|
||||||
}
|
}
|
||||||
return child;
|
return child;
|
||||||
@ -107,35 +107,5 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
|||||||
return self.layoutChildren[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
|
@end
|
||||||
|
|||||||
@ -14,6 +14,6 @@
|
|||||||
@class ASLayoutOptions;
|
@class ASLayoutOptions;
|
||||||
|
|
||||||
@protocol ASLayoutablePrivate <NSObject>
|
@protocol ASLayoutablePrivate <NSObject>
|
||||||
- (ASLayoutSpec *)finalLayoutable;
|
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec;
|
||||||
@property (nonatomic, strong, readonly) ASLayoutOptions *layoutOptions;
|
@property (nonatomic, strong) ASLayoutOptions *layoutOptions;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
@interface ASOverlayLayoutSpec : ASLayoutSpec
|
@interface ASOverlayLayoutSpec : ASLayoutSpec
|
||||||
|
|
||||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
|
||||||
@property (nonatomic, strong) id<ASLayoutable> overlay;
|
@property (nonatomic, strong) id<ASLayoutable> overlay;
|
||||||
|
|
||||||
+ (instancetype)overlayLayoutSpecWithChild:(id<ASLayoutable>)child overlay:(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 *)measureWithSizeRange:(ASSizeRange)constrainedSize
|
||||||
{
|
{
|
||||||
ASLayout *contentsLayout = [_child measureWithSizeRange:constrainedSize];
|
ASLayout *contentsLayout = [self.child measureWithSizeRange:constrainedSize];
|
||||||
contentsLayout.position = CGPointZero;
|
contentsLayout.position = CGPointZero;
|
||||||
NSMutableArray *sublayouts = [NSMutableArray arrayWithObject:contentsLayout];
|
NSMutableArray *sublayouts = [NSMutableArray arrayWithObject:contentsLayout];
|
||||||
if (self.overlay) {
|
if (self.overlay) {
|
||||||
|
|||||||
@ -31,8 +31,6 @@
|
|||||||
**/
|
**/
|
||||||
@interface ASRatioLayoutSpec : ASLayoutSpec
|
@interface ASRatioLayoutSpec : ASLayoutSpec
|
||||||
|
|
||||||
|
|
||||||
@property (nonatomic, strong) id<ASLayoutable> child;
|
|
||||||
@property (nonatomic, assign) CGFloat ratio;
|
@property (nonatomic, assign) CGFloat ratio;
|
||||||
|
|
||||||
+ (instancetype)ratioLayoutSpecWithRatio:(CGFloat)ratio child:(id<ASLayoutable>)child;
|
+ (instancetype)ratioLayoutSpecWithRatio:(CGFloat)ratio child:(id<ASLayoutable>)child;
|
||||||
|
|||||||
@ -154,8 +154,6 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides) {
|
|||||||
|
|
||||||
@property (nonatomic, assign) CGFloat contentsScaleForDisplay;
|
@property (nonatomic, assign) CGFloat contentsScaleForDisplay;
|
||||||
|
|
||||||
- (id<ASLayoutable>)finalLayoutable;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface UIView (ASDisplayNodeInternal)
|
@interface UIView (ASDisplayNodeInternal)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user