mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-07 14:53:35 +00:00
Make layoutOptions readonly
This commit is contained in:
parent
2a8b20b102
commit
fca43a651f
@ -24,6 +24,14 @@
|
|||||||
- (instancetype)initWithLayoutable:(id<ASLayoutable>)layoutable;
|
- (instancetype)initWithLayoutable:(id<ASLayoutable>)layoutable;
|
||||||
- (void)setValuesFromLayoutable:(id<ASLayoutable>)layoutable;
|
- (void)setValuesFromLayoutable:(id<ASLayoutable>)layoutable;
|
||||||
|
|
||||||
|
#pragma mark - Subclasses should implement these!
|
||||||
|
+ (NSSet *)keyPathsForValuesAffectingChangeMonitor;
|
||||||
|
- (void)setupDefaults;
|
||||||
|
- (instancetype)copyWithZone:(NSZone *)zone;
|
||||||
|
- (void)copyIntoOptions:(ASLayoutOptions *)layoutOptions;
|
||||||
|
|
||||||
|
#pragma mark - Mutability checks
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL isMutable;
|
@property (nonatomic, assign) BOOL isMutable;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -49,6 +57,5 @@
|
|||||||
@property (nonatomic, readwrite) ASRelativeSizeRange sizeRange;
|
@property (nonatomic, readwrite) ASRelativeSizeRange sizeRange;
|
||||||
@property (nonatomic, readwrite) CGPoint layoutPosition;
|
@property (nonatomic, readwrite) CGPoint layoutPosition;
|
||||||
|
|
||||||
- (void)setupDefaults;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -13,7 +13,6 @@
|
|||||||
#import <AsyncDisplayKit/ASAssert.h>
|
#import <AsyncDisplayKit/ASAssert.h>
|
||||||
#import <AsyncDisplayKit/ASTextNode.h>
|
#import <AsyncDisplayKit/ASTextNode.h>
|
||||||
#import "ASInternalHelpers.h"
|
#import "ASInternalHelpers.h"
|
||||||
#import <objc/runtime.h>
|
|
||||||
|
|
||||||
@implementation ASLayoutOptions
|
@implementation ASLayoutOptions
|
||||||
|
|
||||||
@ -35,6 +34,10 @@ static Class gDefaultLayoutOptionsClass = nil;
|
|||||||
return gDefaultLayoutOptionsClass;
|
return gDefaultLayoutOptionsClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (instancetype)init
|
||||||
|
{
|
||||||
|
return [self initWithLayoutable:nil];
|
||||||
|
}
|
||||||
|
|
||||||
- (instancetype)initWithLayoutable:(id<ASLayoutable>)layoutable;
|
- (instancetype)initWithLayoutable:(id<ASLayoutable>)layoutable;
|
||||||
{
|
{
|
||||||
@ -42,30 +45,31 @@ static Class gDefaultLayoutOptionsClass = nil;
|
|||||||
if (self) {
|
if (self) {
|
||||||
[self setupDefaults];
|
[self setupDefaults];
|
||||||
[self setValuesFromLayoutable:layoutable];
|
[self setValuesFromLayoutable:layoutable];
|
||||||
|
_isMutable = YES;
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
[self addObserver:self forKeyPath:@"changeMonitor"
|
[self addObserver:self
|
||||||
options:NSKeyValueObservingOptionNew
|
forKeyPath:@"changeMonitor"
|
||||||
context:nil];
|
options:NSKeyValueObservingOptionNew
|
||||||
|
context:nil];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
[self removeObserver:self forKeyPath:@"changeMonitor"];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
+ (NSSet *)keyPathsForValuesAffectingChangeMonitor
|
+ (NSSet *)keyPathsForValuesAffectingChangeMonitor
|
||||||
{
|
{
|
||||||
NSMutableSet *keys = [NSMutableSet set];
|
NSMutableSet *keys = [NSMutableSet set];
|
||||||
unsigned int count;
|
[keys addObjectsFromArray:@[@"spacingBefore", @"spacingAfter", @"flexGrow", @"flexShrink", @"flexBasis", @"alignSelf"]];
|
||||||
|
[keys addObjectsFromArray:@[@"ascender", @"descender"]];
|
||||||
objc_property_t *properties = class_copyPropertyList([self class], &count);
|
[keys addObjectsFromArray:@[@"sizeRange", @"layoutPosition"]];
|
||||||
for (size_t i = 0; i < count; ++i) {
|
|
||||||
NSString *property = [NSString stringWithCString:property_getName(properties[i]) encoding:NSASCIIStringEncoding];
|
|
||||||
|
|
||||||
if ([property isEqualToString: @"observableSelf"] == NO) {
|
|
||||||
[keys addObject: property];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(properties);
|
|
||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
@ -89,7 +93,12 @@ static Class gDefaultLayoutOptionsClass = nil;
|
|||||||
- (id)copyWithZone:(NSZone *)zone
|
- (id)copyWithZone:(NSZone *)zone
|
||||||
{
|
{
|
||||||
ASLayoutOptions *copy = [[[self class] alloc] init];
|
ASLayoutOptions *copy = [[[self class] alloc] init];
|
||||||
|
[self copyIntoOptions:copy];
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)copyIntoOptions:(ASLayoutOptions *)copy
|
||||||
|
{
|
||||||
copy.flexBasis = self.flexBasis;
|
copy.flexBasis = self.flexBasis;
|
||||||
copy.spacingAfter = self.spacingAfter;
|
copy.spacingAfter = self.spacingAfter;
|
||||||
copy.spacingBefore = self.spacingBefore;
|
copy.spacingBefore = self.spacingBefore;
|
||||||
@ -101,10 +110,9 @@ static Class gDefaultLayoutOptionsClass = nil;
|
|||||||
|
|
||||||
copy.sizeRange = self.sizeRange;
|
copy.sizeRange = self.sizeRange;
|
||||||
copy.layoutPosition = self.layoutPosition;
|
copy.layoutPosition = self.layoutPosition;
|
||||||
|
|
||||||
return copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Defaults
|
#pragma mark - Defaults
|
||||||
- (void)setupDefaults
|
- (void)setupDefaults
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,17 +17,12 @@
|
|||||||
{\
|
{\
|
||||||
dispatch_once(&_layoutOptionsInitializeToken, ^{\
|
dispatch_once(&_layoutOptionsInitializeToken, ^{\
|
||||||
if (_layoutOptions == nil) {\
|
if (_layoutOptions == nil) {\
|
||||||
_layoutOptions = [[[ASLayoutOptions defaultLayoutOptionsClass] alloc] init];\
|
_layoutOptions = [[[ASLayoutOptions defaultLayoutOptionsClass] alloc] initWithLayoutable:self];\
|
||||||
}\
|
}\
|
||||||
});\
|
});\
|
||||||
return _layoutOptions;\
|
return _layoutOptions;\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
- (void)setLayoutOptions:(ASLayoutOptions *)layoutOptions\
|
|
||||||
{\
|
|
||||||
_layoutOptions = layoutOptions;\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
- (CGFloat)spacingBefore\
|
- (CGFloat)spacingBefore\
|
||||||
{\
|
{\
|
||||||
return self.layoutOptions.spacingBefore;\
|
return self.layoutOptions.spacingBefore;\
|
||||||
|
|||||||
@ -66,9 +66,8 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
|||||||
|
|
||||||
id<ASLayoutable> finalLayoutable = [child finalLayoutableWithParent:self];
|
id<ASLayoutable> finalLayoutable = [child finalLayoutableWithParent:self];
|
||||||
if (finalLayoutable) {
|
if (finalLayoutable) {
|
||||||
ASLayoutOptions *finalLayoutOptions = [layoutOptions copy];
|
[layoutOptions copyIntoOptions:finalLayoutable.layoutOptions];
|
||||||
finalLayoutOptions.isMutable = NO;
|
finalLayoutable.layoutOptions.isMutable = NO;
|
||||||
finalLayoutable.layoutOptions = finalLayoutOptions;
|
|
||||||
return finalLayoutable;
|
return finalLayoutable;
|
||||||
}
|
}
|
||||||
return child;
|
return child;
|
||||||
|
|||||||
@ -15,5 +15,5 @@
|
|||||||
|
|
||||||
@protocol ASLayoutablePrivate <NSObject>
|
@protocol ASLayoutablePrivate <NSObject>
|
||||||
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec;
|
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec;
|
||||||
@property (nonatomic, strong) ASLayoutOptions *layoutOptions;
|
@property (nonatomic, strong, readonly) ASLayoutOptions *layoutOptions;
|
||||||
@end
|
@end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user