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