Updates to expectedImageSize

* renamed property to requestedLayoutSize
* moved property to ASDisplayNode
This commit is contained in:
rcancro 2015-08-03 22:09:50 -07:00
parent eae76d26b7
commit 496cc43337
6 changed files with 57 additions and 60 deletions

View File

@ -185,6 +185,15 @@ typedef CALayer *(^ASDisplayNodeLayerBlock)();
*/ */
@property (nonatomic, readonly, assign) ASSizeRange constrainedSizeForCalculatedLayout; @property (nonatomic, readonly, assign) ASSizeRange constrainedSizeForCalculatedLayout;
/**
* @abstract Used by some implementations of measureWithSizeRange: to provide an intrisic content size
* to a node when one cannot be computed from its subnodes
*
* @return The requested size of this node
*/
@property (atomic, assign, readwrite) CGSize requestedLayoutSize;
/** @name Managing the nodes hierarchy */ /** @name Managing the nodes hierarchy */

View File

@ -47,6 +47,7 @@
@synthesize flexShrink = _flexShrink; @synthesize flexShrink = _flexShrink;
@synthesize flexBasis = _flexBasis; @synthesize flexBasis = _flexBasis;
@synthesize alignSelf = _alignSelf; @synthesize alignSelf = _alignSelf;
@synthesize requestedLayoutSize = _requestedLayoutSize;
BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector) BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector)
{ {
@ -135,6 +136,7 @@ void ASDisplayNodePerformBlockOnMainThread(void (^block)())
_methodOverrides = overrides; _methodOverrides = overrides;
_flexBasis = ASRelativeDimensionUnconstrained; _flexBasis = ASRelativeDimensionUnconstrained;
_requestedLayoutSize = CGSizeZero;
} }
- (id)init - (id)init
@ -1333,6 +1335,18 @@ static NSInteger incrementIfFound(NSInteger i) {
return _constrainedSize; return _constrainedSize;
} }
-(void)setRequestedLayoutSize:(CGSize)requestedLayoutSize
{
ASDN::MutexLocker l(_propertyLock);
_requestedLayoutSize = requestedLayoutSize;
}
- (CGSize)requestedLayoutSize
{
ASDN::MutexLocker l(_propertyLock);
return _requestedLayoutSize;
}
- (UIImage *)placeholderImage - (UIImage *)placeholderImage
{ {
return nil; return nil;

View File

@ -111,7 +111,9 @@
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize - (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{ {
ASDN::MutexLocker l(_imageLock); ASDN::MutexLocker l(_imageLock);
if (_image) if (CGSizeEqualToSize(self.requestedLayoutSize, CGSizeZero) == NO)
return CGSizeMake(MIN(constrainedSize.width, self.requestedLayoutSize.width), MIN(constrainedSize.height, self.requestedLayoutSize.height));
else if (_image)
return _image.size; return _image.size;
else else
return CGSizeZero; return CGSizeZero;

View File

@ -51,11 +51,6 @@
*/ */
@property (atomic, strong, readwrite) UIImage *defaultImage; @property (atomic, strong, readwrite) UIImage *defaultImage;
/**
* The expected size of the image that will download
*/
@property (atomic, assign, readwrite) CGSize expectedImageSize;
/** /**
* The URL of a new image to download and display. * The URL of a new image to download and display.
* *

View File

@ -24,7 +24,6 @@
NSURL *_URL; NSURL *_URL;
UIImage *_defaultImage; UIImage *_defaultImage;
CGSize _expectedImageSize;
NSUUID *_cacheUUID; NSUUID *_cacheUUID;
id _imageDownload; id _imageDownload;
@ -45,7 +44,6 @@
_cache = cache; _cache = cache;
_downloader = downloader; _downloader = downloader;
_shouldCacheImage = YES; _shouldCacheImage = YES;
_expectedImageSize = CGSizeZero;
return self; return self;
} }
@ -113,18 +111,6 @@
return _defaultImage; return _defaultImage;
} }
-(void)setExpectedImageSize:(CGSize)expectedImageSize
{
ASDN::MutexLocker l(_lock);
_expectedImageSize = expectedImageSize;
}
- (CGSize)expectedImageSize
{
ASDN::MutexLocker l(_lock);
return _expectedImageSize;
}
- (void)setDelegate:(id<ASNetworkImageNodeDelegate>)delegate - (void)setDelegate:(id<ASNetworkImageNodeDelegate>)delegate
{ {
ASDN::MutexLocker l(_lock); ASDN::MutexLocker l(_lock);
@ -167,15 +153,6 @@
} }
} }
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
ASDN::MutexLocker l(_lock);
if (CGSizeEqualToSize(CGSizeZero, _expectedImageSize))
return [super calculateSizeThatFits:constrainedSize];
else
return _expectedImageSize;
}
#pragma mark - Private methods -- only call with lock. #pragma mark - Private methods -- only call with lock.
- (void)_cancelImageDownload - (void)_cancelImageDownload

View File

@ -83,7 +83,7 @@ static const CGFloat kInnerPadding = 10.0f;
_imageNode.URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://placekitten.com/%zd/%zd", _imageNode.URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://placekitten.com/%zd/%zd",
(NSInteger)roundl(_kittenSize.width), (NSInteger)roundl(_kittenSize.width),
(NSInteger)roundl(_kittenSize.height)]]; (NSInteger)roundl(_kittenSize.height)]];
_imageNode.expectedImageSize = CGSizeMake(kImageSize, kImageSize); _imageNode.requestedLayoutSize = CGSizeMake(kImageSize, kImageSize);
// _imageNode.contentMode = UIViewContentModeCenter; // _imageNode.contentMode = UIViewContentModeCenter;
[self addSubnode:_imageNode]; [self addSubnode:_imageNode];