mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-07 05:25:12 +00:00
Merge pull request #590 from rcancro/master
Add expectedSize to ASNetworkImageNode
This commit is contained in:
@@ -185,6 +185,16 @@ typedef CALayer *(^ASDisplayNodeLayerBlock)();
|
||||
*/
|
||||
@property (nonatomic, readonly, assign) ASSizeRange constrainedSizeForCalculatedLayout;
|
||||
|
||||
/**
|
||||
* @abstract Provides a default intrinsic content size for calculateSizeThatFits:. This is useful when laying out
|
||||
* a node that either has 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.
|
||||
*
|
||||
* @return The preferred frame size of this node
|
||||
*/
|
||||
@property (atomic, assign, readwrite) CGSize preferredFrameSize;
|
||||
|
||||
/** @name Managing the nodes hierarchy */
|
||||
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
@synthesize flexShrink = _flexShrink;
|
||||
@synthesize flexBasis = _flexBasis;
|
||||
@synthesize alignSelf = _alignSelf;
|
||||
@synthesize preferredFrameSize = _preferredFrameSize;
|
||||
|
||||
BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector)
|
||||
{
|
||||
@@ -155,6 +156,7 @@ void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block)
|
||||
_methodOverrides = overrides;
|
||||
|
||||
_flexBasis = ASRelativeDimensionUnconstrained;
|
||||
_preferredFrameSize = CGSizeZero;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
@@ -1350,7 +1352,7 @@ static NSInteger incrementIfFound(NSInteger i) {
|
||||
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
|
||||
{
|
||||
ASDisplayNodeAssertThreadAffinity(self);
|
||||
return CGSizeZero;
|
||||
return _preferredFrameSize;
|
||||
}
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
@@ -1377,6 +1379,17 @@ static NSInteger incrementIfFound(NSInteger i) {
|
||||
return _constrainedSize;
|
||||
}
|
||||
|
||||
- (void)setPreferredFrameSize:(CGSize)preferredFrameSize
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_preferredFrameSize = preferredFrameSize;
|
||||
}
|
||||
|
||||
- (CGSize)preferredFrameSize
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _preferredFrameSize;
|
||||
}
|
||||
- (UIImage *)placeholderImage
|
||||
{
|
||||
return nil;
|
||||
|
||||
@@ -111,7 +111,10 @@
|
||||
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
|
||||
{
|
||||
ASDN::MutexLocker l(_imageLock);
|
||||
if (_image)
|
||||
// if a preferredFrameSize is set, call the superclass to return that instead of using the image size.
|
||||
if (CGSizeEqualToSize(self.preferredFrameSize, CGSizeZero) == NO)
|
||||
return [super calculateSizeThatFits:constrainedSize];
|
||||
else if (_image)
|
||||
return _image.size;
|
||||
else
|
||||
return CGSizeZero;
|
||||
|
||||
@@ -134,9 +134,7 @@ static const CGFloat kInnerPadding = 10.0f;
|
||||
#if UseAutomaticLayout
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASRatioLayoutSpec *imagePlaceholder = [ASRatioLayoutSpec newWithRatio:1.0 child:_imageNode];
|
||||
imagePlaceholder.flexBasis = ASRelativeDimensionMakeWithPoints(kImageSize * (!_isImageEnlarged ? 1 : 2));
|
||||
|
||||
_imageNode.preferredFrameSize = _isImageEnlarged ? CGSizeMake(2.0 * kImageSize, 2.0 * kImageSize) : CGSizeMake(kImageSize, kImageSize);
|
||||
_textNode.flexShrink = YES;
|
||||
|
||||
return
|
||||
@@ -148,7 +146,7 @@ static const CGFloat kInnerPadding = 10.0f;
|
||||
.direction = ASStackLayoutDirectionHorizontal,
|
||||
.spacing = kInnerPadding
|
||||
}
|
||||
children:!_swappedTextAndImage ? @[imagePlaceholder, _textNode] : @[_textNode, imagePlaceholder]]];
|
||||
children:!_swappedTextAndImage ? @[_imageNode, _textNode] : @[_textNode, _imageNode]]];
|
||||
}
|
||||
|
||||
// With box model, you don't need to override this method, unless you want to add custom logic.
|
||||
|
||||
Reference in New Issue
Block a user