mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
[Layout] Further deprecation steps for preferredFrameSize (#2255)
* Deprecate preferredFrameSize - Remove all support for preferredFrameSize in ASDK - preferredFrameSize setter calls through and sets the width and height of the node - preferredFrameSize getter tries to return a CGSize based on the width and height properties otherwise if this is not possible it throws * Address comments * Return CGSizeZero for preferredFrameSize unless width and height are ASDimensionUnitPoints * Better comment for preferredFrameSize and remove lock in calculateSizeThatFits:
This commit is contained in:
committed by
Adlai Holler
parent
e8f01f082a
commit
f574f2c54e
@@ -511,18 +511,6 @@
|
||||
spec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:contentEdgeInsets child:spec];
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (CGSizeEqualToSize(self.preferredFrameSize, CGSizeZero) == NO) {
|
||||
#if DEBUG
|
||||
NSLog(@"Using -[ASDisplayNde preferredFrameSize] is deprecated.");
|
||||
#endif
|
||||
stack.style.width = ASDimensionMake(ASDimensionUnitPoints, self.preferredFrameSize.width);
|
||||
stack.style.height = ASDimensionMake(ASDimensionUnitPoints, self.preferredFrameSize.height);
|
||||
spec = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[stack]];
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if (_backgroundImageNode.image) {
|
||||
spec = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:spec background:_backgroundImageNode];
|
||||
}
|
||||
|
||||
@@ -827,9 +827,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
* size. For example, this property could be set on an ASImageNode to display at a size different from the underlying
|
||||
* image size.
|
||||
*
|
||||
* @return The preferred frame size of this node
|
||||
* @return Try to create a CGSize for preferredFrameSize of this node from the width and height property of this node. It will return CGSizeZero if widht and height dimensions are not of type ASDimensionUnitPoints.
|
||||
*
|
||||
* @deprecated Deprecated in version 2.0: Use sizing properties instead: height, minHeight, maxHeight, width, minWidth, maxWidth
|
||||
* @deprecated Deprecated in version 2.0: Just calls through to set the height and width property of the node. Convert to use sizing properties instead: height, minHeight, maxHeight, width, minWidth, maxWidth.
|
||||
*/
|
||||
@property (nonatomic, assign, readwrite) CGSize preferredFrameSize ASDISPLAYNODE_DEPRECATED;
|
||||
|
||||
|
||||
@@ -301,7 +301,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
_displaySentinel = [[ASSentinel alloc] init];
|
||||
|
||||
_style = [[ASLayoutableStyle alloc] init];
|
||||
_preferredFrameSize = CGSizeZero;
|
||||
_size = ASLayoutableSizeMake();
|
||||
_environmentState = ASEnvironmentStateMakeDefault();
|
||||
|
||||
_calculatedDisplayNodeLayout = std::make_shared<ASDisplayNodeLayout>();
|
||||
@@ -2456,8 +2456,6 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
|
||||
ASDisplayNodeLogEvent(self, @"computedLayout: %@", layout);
|
||||
return [layout filteredNodeLayoutTree];
|
||||
} else {
|
||||
// If neither -layoutSpecThatFits: nor -calculateSizeThatFits: is overridden by subclassses, preferredFrameSize should be used,
|
||||
// assume that the default implementation of -calculateSizeThatFits: returns it.
|
||||
CGSize size = [self calculateSizeThatFits:constrainedSize.max];
|
||||
ASDisplayNodeLogEvent(self, @"calculatedSize: %@", NSStringFromCGSize(size));
|
||||
return [ASLayout layoutWithLayoutable:self size:ASSizeRangeClamp(constrainedSize, size) sublayouts:nil];
|
||||
@@ -2468,13 +2466,6 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
|
||||
{
|
||||
__ASDisplayNodeCheckForLayoutMethodOverrides;
|
||||
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
// Handle deprecated preferred frame size.
|
||||
if (CGSizeEqualToSize(_preferredFrameSize, CGSizeZero) == NO) {
|
||||
return _preferredFrameSize;
|
||||
}
|
||||
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
@@ -2549,25 +2540,6 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
|
||||
return _pendingTransitionID;
|
||||
}
|
||||
|
||||
- (void)setPreferredFrameSize:(CGSize)preferredFrameSize
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
if (! CGSizeEqualToSize(_preferredFrameSize, preferredFrameSize)) {
|
||||
_preferredFrameSize = preferredFrameSize;
|
||||
|
||||
self.style.width = ASDimensionMake(preferredFrameSize.width);
|
||||
self.style.height = ASDimensionMake(preferredFrameSize.height);
|
||||
|
||||
[self invalidateCalculatedLayout];
|
||||
}
|
||||
}
|
||||
|
||||
- (CGSize)preferredFrameSize
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
return _preferredFrameSize;
|
||||
}
|
||||
|
||||
- (CGRect)threadSafeBounds
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
@@ -3501,6 +3473,27 @@ ASEnvironmentLayoutExtensibilityForwarding
|
||||
return [self layoutThatFits:constrainedSize parentSize:constrainedSize.max];
|
||||
}
|
||||
|
||||
- (void)setPreferredFrameSize:(CGSize)preferredFrameSize
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
// Deprecated preferredFrameSize just calls through to set width and height
|
||||
_style.width = ASDimensionMake(preferredFrameSize.width);
|
||||
_style.height = ASDimensionMake(preferredFrameSize.height);
|
||||
[self invalidateCalculatedLayout];
|
||||
}
|
||||
|
||||
- (CGSize)preferredFrameSize
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
if (_style.width.unit == ASDimensionUnitPoints && _style.height.unit == ASDimensionUnitPoints) {
|
||||
return CGSizeMake(_style.width.value, _style.height.value);
|
||||
}
|
||||
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ASDisplayNode (Debugging)
|
||||
|
||||
@@ -189,17 +189,6 @@ struct ASImageNodeDrawParameters {
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// If a preferredFrameSize is set, call the superclass to return that instead of using the image size.
|
||||
if (CGSizeEqualToSize(self.preferredFrameSize, CGSizeZero) == NO) {
|
||||
#if DEBUG
|
||||
NSLog(@"Using -[ASDisplayNode preferredFrameSize] is deprecated.");
|
||||
#endif
|
||||
return self.preferredFrameSize;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if (_image == nil) {
|
||||
return constrainedSize;
|
||||
}
|
||||
|
||||
@@ -243,17 +243,6 @@ static NSString * const kRate = @"rate";
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
CGSize calculatedSize = constrainedSize;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// if a preferredFrameSize is set, call the superclass to return that instead of using the image size.
|
||||
if (CGSizeEqualToSize(self.preferredFrameSize, CGSizeZero) == NO) {
|
||||
#if DEBUG
|
||||
NSLog(@"Using -[ASDisplayNde preferredFrameSize] is deprecated.");
|
||||
#endif
|
||||
calculatedSize = self.preferredFrameSize;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// Prevent crashes through if infinite width or height
|
||||
if (isinf(calculatedSize.width) || isinf(calculatedSize.height)) {
|
||||
ASDisplayNodeAssert(NO, @"Infinite width or height in ASVideoNode");
|
||||
|
||||
@@ -107,7 +107,7 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
|
||||
ASDisplayNode * __weak _supernode;
|
||||
|
||||
ASLayoutableStyle *_style;
|
||||
CGSize _preferredFrameSize;
|
||||
ASLayoutableSize _size;
|
||||
|
||||
ASSentinel *_displaySentinel;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#import "ASXCTExtensions.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "_ASDisplayLayer.h"
|
||||
@@ -2048,4 +2049,25 @@ static bool stringContainsPointer(NSString *description, id p) {
|
||||
XCTAssertEqualObjects(calls, expected);
|
||||
}
|
||||
|
||||
- (void)testPreferredFrameSizeDeprecated
|
||||
{
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
ASDisplayNode *node = [ASDisplayNode new];
|
||||
|
||||
// Default auto preferred frame size will be CGSizeZero
|
||||
XCTAssert(CGSizeEqualToSize(node.preferredFrameSize, CGSizeZero));
|
||||
|
||||
// Set a specific preferredFrameSize
|
||||
node.preferredFrameSize = CGSizeMake(100, 100);
|
||||
ASXCTAssertEqualSizes(node.preferredFrameSize, CGSizeMake(100, 100));
|
||||
|
||||
// CGSizeZero should be returned if width or height is not of unit type points
|
||||
node.style.width = ASDimensionMakeWithFraction(0.5);
|
||||
ASXCTAssertEqualSizes(node.preferredFrameSize, CGSizeZero);
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user