Skip to content

Commit

Permalink
Don't behave like an image node if URL is set. (facebookarchive#2774)
Browse files Browse the repository at this point in the history
After much discussion I think this is the correct behavior. It seems
like it's much more likely to be the expected behavior but still enables
you to use the network image node like an regular image node.
  • Loading branch information
garrettmoon authored and appleguy committed Dec 15, 2016
1 parent e9a3d3f commit dabb69d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 6 additions & 5 deletions AsyncDisplayKit/ASNetworkImageNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ NS_ASSUME_NONNULL_BEGIN
/**
* The image to display.
*
* @discussion By setting an image to the image property the ASNetworkImageNode will act like a plain ASImageNode.
* As soon as the URL is set the ASNetworkImageNode will act like an ASNetworkImageNode and the image property
* will be managed internally. This means the image property will be cleared out and replaced by the placeholder
* (<defaultImage>) image while loading and the final image after the new image data was downloaded and processed.
* If you want to use a placholder image functionality use the defaultImage property instead.
* @discussion Setting an image to the image property of an ASNetworkImageNode will cause it to act like a plain
* ASImageNode if a URL is not set as well. As soon as the URL is set the ASNetworkImageNode will act like an
* ASNetworkImageNode and the image property will be managed internally. This means the image property will be cleared
* out and replaced by the placeholder (<defaultImage>) image while loading and the final image after the new image
* data was downloaded and processed. If you want to use a placholder image, use the defaultImage property
* instead.
*/
@property (nullable, nonatomic, strong) UIImage *image;

Expand Down
8 changes: 2 additions & 6 deletions AsyncDisplayKit/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,12 @@ - (void)dealloc

#pragma mark - Public methods -- must lock

/// Setter for public image property. It has the side effect to set an internal _imageWasSetExternally that prevents setting an image internally. Setting an image internally should happen with the _setImage: method
/// Setter for public image property. It has the side effect of setting an internal _imageWasSetExternally that prevents setting an image internally. Setting an image internally should happen with the _setImage: method
- (void)setImage:(UIImage *)image
{
ASDN::MutexLocker l(__instanceLock__);

_imageWasSetExternally = (image != nil);
if (_imageWasSetExternally) {
[self _cancelDownloadAndClearImage];
_URL = nil;
}
_imageWasSetExternally = (image != nil && _URL != nil);

[self _setImage:image];
}
Expand Down

0 comments on commit dabb69d

Please sign in to comment.