mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Add improvements
- Remove defaults for ASEnvironmentLayoutOptionsState and ASEnvironmentHierarchyState - Add locking for ASEnvironmentLayoutExtensibilityForwarding - Other smaller improvements
This commit is contained in:
@@ -1704,7 +1704,7 @@ static NSInteger incrementIfFound(NSInteger i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ([newSupernode supportsUpwardPropagation]) {
|
if ([newSupernode supportsUpwardPropagation]) {
|
||||||
ASEnvironmentStatePropagateUp(newSupernode, self.environmentState.layoutOptionsState);
|
ASEnvironmentStatePropagateUp(newSupernode, _environmentState.layoutOptionsState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ typedef struct ASEnvironmentLayoutOptionsState {
|
|||||||
|
|
||||||
ASEnvironmentStateExtensions _extensions;
|
ASEnvironmentStateExtensions _extensions;
|
||||||
} ASEnvironmentLayoutOptionsState;
|
} ASEnvironmentLayoutOptionsState;
|
||||||
extern ASEnvironmentLayoutOptionsState ASEnvironmentLayoutOptionsStateCreate();
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - ASEnvironmentHierarchyState
|
#pragma mark - ASEnvironmentHierarchyState
|
||||||
@@ -59,7 +58,6 @@ typedef struct ASEnvironmentHierarchyState {
|
|||||||
unsigned transitioningSupernodes:1; // = NO
|
unsigned transitioningSupernodes:1; // = NO
|
||||||
unsigned layoutPending:1; // = NO
|
unsigned layoutPending:1; // = NO
|
||||||
} ASEnvironmentHierarchyState;
|
} ASEnvironmentHierarchyState;
|
||||||
extern ASEnvironmentHierarchyState ASEnvironmentHierarchyStateCreate();
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - ASEnvironmentState
|
#pragma mark - ASEnvironmentState
|
||||||
@@ -92,6 +90,7 @@ ASDISPLAYNODE_EXTERN_C_END
|
|||||||
/// Returns all children of an object which class conforms to the ASEnvironment protocol
|
/// Returns all children of an object which class conforms to the ASEnvironment protocol
|
||||||
- (NSArray<id<ASEnvironment>> *)children;
|
- (NSArray<id<ASEnvironment>> *)children;
|
||||||
|
|
||||||
|
/// Classes should implement this method and return YES / NO dependent if upward propagation is enabled or not
|
||||||
- (BOOL)supportsUpwardPropagation;
|
- (BOOL)supportsUpwardPropagation;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -10,32 +10,24 @@
|
|||||||
|
|
||||||
#import "ASEnvironment.h"
|
#import "ASEnvironment.h"
|
||||||
|
|
||||||
ASEnvironmentLayoutOptionsState ASEnvironmentLayoutOptionsStateCreate()
|
ASEnvironmentLayoutOptionsState _ASEnvironmentLayoutOptionsStateCreate()
|
||||||
{
|
{
|
||||||
return (ASEnvironmentLayoutOptionsState) {
|
return (ASEnvironmentLayoutOptionsState) {
|
||||||
.spacingBefore = 0,
|
// Default values can be defined in here
|
||||||
.flexBasis = ASRelativeDimensionUnconstrained,
|
|
||||||
.alignSelf = ASStackLayoutAlignSelfAuto,
|
|
||||||
|
|
||||||
.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMakeWithCGSize(CGSizeZero), ASRelativeSizeMakeWithCGSize(CGSizeZero)),
|
|
||||||
.layoutPosition = CGPointZero
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ASEnvironmentHierarchyState ASEnvironmentHierarchyStateCreate()
|
ASEnvironmentHierarchyState _ASEnvironmentHierarchyStateCreate()
|
||||||
{
|
{
|
||||||
return (ASEnvironmentHierarchyState) {
|
return (ASEnvironmentHierarchyState) {
|
||||||
.rasterized = NO,
|
// Default values can be defined in here
|
||||||
.rangeManaged = NO,
|
|
||||||
.transitioningSupernodes = NO,
|
|
||||||
.layoutPending = NO
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ASEnvironmentState ASEnvironmentStateCreate()
|
ASEnvironmentState ASEnvironmentStateCreate()
|
||||||
{
|
{
|
||||||
return (ASEnvironmentState) {
|
return (ASEnvironmentState) {
|
||||||
.hierarchyState = ASEnvironmentHierarchyStateCreate(),
|
.layoutOptionsState = _ASEnvironmentLayoutOptionsStateCreate(),
|
||||||
.layoutOptionsState = ASEnvironmentLayoutOptionsStateCreate()
|
.hierarchyState = _ASEnvironmentHierarchyStateCreate()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -81,10 +81,8 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
|||||||
|
|
||||||
id<ASLayoutable> finalLayoutable = [child finalLayoutable];
|
id<ASLayoutable> finalLayoutable = [child finalLayoutable];
|
||||||
if (finalLayoutable != child) {
|
if (finalLayoutable != child) {
|
||||||
// Copy layout options
|
// Layout options state of child needs to be copied to final layoutable
|
||||||
ASEnvironmentState environmentState = finalLayoutable.environmentState;
|
finalLayoutable.environmentState.layoutOptionsState = child.environmentState.layoutOptionsState;
|
||||||
environmentState.layoutOptionsState = child.environmentState.layoutOptionsState;
|
|
||||||
finalLayoutable.environmentState = environmentState;
|
|
||||||
return finalLayoutable;
|
return finalLayoutable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,6 +157,9 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
|
|||||||
_environmentState = environmentState;
|
_environmentState = environmentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subclasses can override this method to return NO, because upward propagation is not enabled if a layout
|
||||||
|
// specification has more than one child. Currently ASStackLayoutSpec and ASStaticLayoutSpec are currently
|
||||||
|
// the specifications that are known to have more than one.
|
||||||
- (BOOL)supportsUpwardPropagation
|
- (BOOL)supportsUpwardPropagation
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
// Copyright © 2016 Facebook. All rights reserved.
|
// Copyright © 2016 Facebook. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIGeometry.h>
|
||||||
|
|
||||||
@protocol ASLayoutableExtensibility <NSObject>
|
@protocol ASLayoutableExtensibility <NSObject>
|
||||||
|
|
||||||
|
|||||||
@@ -231,30 +231,39 @@ extern void ASLayoutableClearCurrentContext();
|
|||||||
#define ASEnvironmentLayoutExtensibilityForwarding \
|
#define ASEnvironmentLayoutExtensibilityForwarding \
|
||||||
- (void)setLayoutOptionExtensionBool:(BOOL)value atIndex:(int)idx\
|
- (void)setLayoutOptionExtensionBool:(BOOL)value atIndex:(int)idx\
|
||||||
{\
|
{\
|
||||||
|
_propertyLock.lock();\
|
||||||
_ASEnvironmentLayoutOptionsExtensionSetBoolAtIndex(self, idx, value);\
|
_ASEnvironmentLayoutOptionsExtensionSetBoolAtIndex(self, idx, value);\
|
||||||
|
_propertyLock.unlock();\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
- (BOOL)layoutOptionExtensionBoolAtIndex:(int)idx\
|
- (BOOL)layoutOptionExtensionBoolAtIndex:(int)idx\
|
||||||
{\
|
{\
|
||||||
|
ASDN::MutexLocker l(_propertyLock);\
|
||||||
return _ASEnvironmentLayoutOptionsExtensionGetBoolAtIndex(self, idx);\
|
return _ASEnvironmentLayoutOptionsExtensionGetBoolAtIndex(self, idx);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
- (void)setLayoutOptionExtensionInteger:(NSInteger)value atIndex:(int)idx\
|
- (void)setLayoutOptionExtensionInteger:(NSInteger)value atIndex:(int)idx\
|
||||||
{\
|
{\
|
||||||
|
_propertyLock.lock();\
|
||||||
_ASEnvironmentLayoutOptionsExtensionSetIntegerAtIndex(self, idx, value);\
|
_ASEnvironmentLayoutOptionsExtensionSetIntegerAtIndex(self, idx, value);\
|
||||||
|
_propertyLock.unlock();\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
- (NSInteger)layoutOptionExtensionIntegerAtIndex:(int)idx\
|
- (NSInteger)layoutOptionExtensionIntegerAtIndex:(int)idx\
|
||||||
{\
|
{\
|
||||||
|
ASDN::MutexLocker l(_propertyLock);\
|
||||||
return _ASEnvironmentLayoutOptionsExtensionGetIntegerAtIndex(self, idx);\
|
return _ASEnvironmentLayoutOptionsExtensionGetIntegerAtIndex(self, idx);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
- (void)setLayoutOptionExtensionEdgeInsets:(UIEdgeInsets)value atIndex:(int)idx\
|
- (void)setLayoutOptionExtensionEdgeInsets:(UIEdgeInsets)value atIndex:(int)idx\
|
||||||
{\
|
{\
|
||||||
|
_propertyLock.lock();\
|
||||||
_ASEnvironmentLayoutOptionsExtensionSetEdgeInsetsAtIndex(self, idx, value);\
|
_ASEnvironmentLayoutOptionsExtensionSetEdgeInsetsAtIndex(self, idx, value);\
|
||||||
|
_propertyLock.unlock();\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
- (UIEdgeInsets)layoutOptionExtensionEdgeInsetsAtIndex:(int)idx\
|
- (UIEdgeInsets)layoutOptionExtensionEdgeInsetsAtIndex:(int)idx\
|
||||||
{\
|
{\
|
||||||
|
ASDN::MutexLocker l(_propertyLock);\
|
||||||
return _ASEnvironmentLayoutOptionsExtensionGetEdgeInsetsAtIndex(self, idx);\
|
return _ASEnvironmentLayoutOptionsExtensionGetEdgeInsetsAtIndex(self, idx);\
|
||||||
}\
|
}\
|
||||||
|
|||||||
Reference in New Issue
Block a user