diff --git a/AsyncDisplayKit/ASNetworkImageNode.h b/AsyncDisplayKit/ASNetworkImageNode.h index 125782bc37..0f984eea37 100644 --- a/AsyncDisplayKit/ASNetworkImageNode.h +++ b/AsyncDisplayKit/ASNetworkImageNode.h @@ -51,17 +51,18 @@ NS_ASSUME_NONNULL_BEGIN /** * The image to display. * - * @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 () 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. + * @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 + * () 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. */ @property (nullable, nonatomic, strong) UIImage *image; /** - * A placeholder image to display while the URL is loading. + * A placeholder image to display while the URL is loading. This is slightly different than placeholderImage in the + * ASDisplayNode superclass as defaultImage will *not* be displayed synchronously. If you wish to have the image + * displayed synchronously, use @c placeholderImage. */ @property (nullable, nonatomic, strong, readwrite) UIImage *defaultImage; diff --git a/AsyncDisplayKit/ASNetworkImageNode.mm b/AsyncDisplayKit/ASNetworkImageNode.mm index 8b090d581a..ac6a7ff4a9 100755 --- a/AsyncDisplayKit/ASNetworkImageNode.mm +++ b/AsyncDisplayKit/ASNetworkImageNode.mm @@ -114,7 +114,12 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0}; { ASDN::MutexLocker l(__instanceLock__); - _imageWasSetExternally = (image != nil && _URL == nil); + _imageWasSetExternally = (image != nil); + if (_imageWasSetExternally) { + ASDisplayNodeAssertNil(_URL, @"Directly setting an image on an ASNetworkImageNode causes it to behave like an ASImageNode instead of an ASNetworkImageNode. If this is what you want, set the URL to nil first."); + [self _cancelDownloadAndClearImage]; + _URL = nil; + } [self _setImage:image]; } @@ -134,6 +139,8 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0}; { ASDN::MutexLocker l(__instanceLock__); + ASDisplayNodeAssert(_imageWasSetExternally == NO, @"Setting a URL to an ASNetworkImageNode after setting an image changes its behavior from an ASImageNode to an ASNetworkImageNode. If this is what you want, set the image to nil first."); + _imageWasSetExternally = NO; if (ASObjectIsEqual(URL, _URL)) {