mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Add preferredSize as getter to ASLayoutElementStyle (#2427)
This commit is contained in:
committed by
Adlai Holler
parent
67489492ee
commit
4b914f8e15
@@ -251,9 +251,10 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty;
|
||||
* for nodes that either have no intrinsic content size or
|
||||
* should be laid out at a different size than its intrinsic content size. For example, this property could be
|
||||
* set on an ASImageNode to display at a size different from the underlying image size.
|
||||
*
|
||||
* @warning Calling the getter when the size's width or height are relative will cause an assert.
|
||||
*/
|
||||
@property (nonatomic, assign) CGSize preferredSize;
|
||||
- (CGSize)preferredSize UNAVAILABLE_ATTRIBUTE;
|
||||
|
||||
/**
|
||||
* @abstract An optional property that provides a minimum size bound for a layout element. If provided, this restriction will
|
||||
|
||||
@@ -254,6 +254,22 @@ do {\
|
||||
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleHeightProperty);
|
||||
}
|
||||
|
||||
- (CGSize)preferredSize
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
if (_size.width.unit != ASDimensionUnitPoints) {
|
||||
NSCAssert(NO, @"Cannot get preferredSize of element with fractional width. Width: %@.", NSStringFromASDimension(_size.width));
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
if (_size.height.unit != ASDimensionUnitPoints) {
|
||||
NSCAssert(NO, @"Cannot get preferredSize of element with fractional height. Height: %@.", NSStringFromASDimension(_size.height));
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
return CGSizeMake(_size.width.value, _size.height.value);
|
||||
}
|
||||
|
||||
- (void)setMinSize:(CGSize)minSize
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "ASXCTExtensions.h"
|
||||
#import "ASLayoutElement.h"
|
||||
|
||||
#pragma mark - ASLayoutElementStyleTestsDelegate
|
||||
@@ -61,6 +61,7 @@
|
||||
CGSize size = CGSizeMake(100, 100);
|
||||
|
||||
style.preferredSize = size;
|
||||
ASXCTAssertEqualSizes(style.preferredSize, size);
|
||||
XCTAssertTrue(ASDimensionEqualToDimension(style.width, ASDimensionMakeWithPoints(size.width)));
|
||||
XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMakeWithPoints(size.height)));
|
||||
|
||||
@@ -73,6 +74,19 @@
|
||||
XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, ASDimensionMakeWithPoints(size.height)));
|
||||
}
|
||||
|
||||
- (void)testReadingInvalidSizeForPreferredSize
|
||||
{
|
||||
ASLayoutElementStyle *style = [ASLayoutElementStyle new];
|
||||
|
||||
XCTAssertThrows(style.preferredSize);
|
||||
|
||||
style.width = ASDimensionMake(ASDimensionUnitFraction, 0.5);
|
||||
XCTAssertThrows(style.preferredSize);
|
||||
|
||||
style.preferredSize = CGSizeMake(100, 100);
|
||||
XCTAssertNoThrow(style.preferredSize);
|
||||
}
|
||||
|
||||
- (void)testSettingSizeViaLayoutSize
|
||||
{
|
||||
ASLayoutElementStyle *style = [ASLayoutElementStyle new];
|
||||
|
||||
Reference in New Issue
Block a user