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