Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 085c52b

Browse files
maickigarrettmoon
authored andcommitted
Tremendously make the implementation easier
1 parent 8009b9d commit 085c52b

7 files changed

Lines changed: 35 additions & 83 deletions

File tree

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@
204204
6907C2591DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6907C2571DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m */; };
205205
6907C25A1DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6907C2571DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m */; };
206206
69127CFE1DD2B387004BF6E2 /* ASEventLog.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 696F01EA1DD2AF450049FBD5 /* ASEventLog.h */; };
207-
69309D461DF3B1B50089FA48 /* ASImageNode+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 69309D451DF3B1B50089FA48 /* ASImageNode+Private.h */; };
208207
693117CE1DC7C72700DE4784 /* ASDisplayNode+Deprecated.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 683489271D70DE3400327501 /* ASDisplayNode+Deprecated.h */; };
209208
69527B121DC84292004785FB /* ASLayoutElementStylePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 69527B111DC84292004785FB /* ASLayoutElementStylePrivate.h */; };
210209
6959433E1D70815300B0EE1F /* ASDisplayNodeLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6959433C1D70815300B0EE1F /* ASDisplayNodeLayout.mm */; };
@@ -1003,7 +1002,6 @@
10031002
68FC85E81CE29C7D00EDD713 /* ASVisibilityProtocols.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASVisibilityProtocols.m; sourceTree = "<group>"; };
10041003
6907C2561DC4ECFE00374C66 /* ASObjectDescriptionHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASObjectDescriptionHelpers.h; sourceTree = "<group>"; };
10051004
6907C2571DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASObjectDescriptionHelpers.m; sourceTree = "<group>"; };
1006-
69309D451DF3B1B50089FA48 /* ASImageNode+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ASImageNode+Private.h"; sourceTree = "<group>"; };
10071005
69527B111DC84292004785FB /* ASLayoutElementStylePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASLayoutElementStylePrivate.h; path = AsyncDisplayKit/Layout/ASLayoutElementStylePrivate.h; sourceTree = SOURCE_ROOT; };
10081006
6959433C1D70815300B0EE1F /* ASDisplayNodeLayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASDisplayNodeLayout.mm; sourceTree = "<group>"; };
10091007
6959433D1D70815300B0EE1F /* ASDisplayNodeLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASDisplayNodeLayout.h; sourceTree = "<group>"; };
@@ -1611,7 +1609,6 @@
16111609
68B8A4DB1CBD911D007E4543 /* ASImageNode+AnimatedImagePrivate.h */,
16121610
058D0A0D195D050800B7D73C /* ASImageNode+CGExtras.h */,
16131611
058D0A0E195D050800B7D73C /* ASImageNode+CGExtras.m */,
1614-
69309D451DF3B1B50089FA48 /* ASImageNode+Private.h */,
16151612
ACF6ED431B17847A00DA7C62 /* ASInternalHelpers.h */,
16161613
ACF6ED441B17847A00DA7C62 /* ASInternalHelpers.m */,
16171614
69C4CAF51DA3147000B1EC9B /* ASLayoutElementStylePrivate.h */,
@@ -1860,7 +1857,6 @@
18601857
34EFC7631B701CBF00AD841F /* ASCenterLayoutSpec.h in Headers */,
18611858
9C70F20C1CDBE9B6007D6C76 /* ASCollectionDataController.h in Headers */,
18621859
18C2ED7F1B9B7DE800F627B3 /* ASCollectionNode.h in Headers */,
1863-
69309D461DF3B1B50089FA48 /* ASImageNode+Private.h in Headers */,
18641860
9C8898BD1C738BB800D6B02E /* ASTextKitFontSizeAdjuster.h in Headers */,
18651861
B35061F51B010EFD0018CF92 /* ASCollectionView.h in Headers */,
18661862
ACE87A2C1D73696800D7FF06 /* ASSectionContext.h in Headers */,

AsyncDisplayKit/ASImageNode.mm

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ - (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
199199
#pragma mark - Setter / Getter
200200

201201
- (void)setImage:(UIImage *)image
202-
{
203-
[self __setImage:image];
204-
}
205-
206-
- (void)__setImage:(UIImage *)image
207202
{
208203
ASDN::MutexLocker l(__instanceLock__);
209204
if (!ASObjectIsEqual(_image, image)) {

AsyncDisplayKit/ASMultiplexImageNode.mm

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#if TARGET_OS_IOS
1212

1313
#import "ASMultiplexImageNode.h"
14-
#import "ASImageNode+Private.h"
1514
#import <AssetsLibrary/AssetsLibrary.h>
1615

1716
#import "ASAvailability.h"
@@ -234,7 +233,7 @@ - (void)didExitPreloadState
234233

235234
// setting this to nil makes the node fetch images the next time its display starts
236235
_loadedImageIdentifier = nil;
237-
[self __setImage:nil];
236+
[self _setImage:nil];
238237
}
239238

240239
- (void)didEnterPreloadState
@@ -329,7 +328,12 @@ - (void)didExitVisibleState
329328
- (void)setImage:(UIImage *)image
330329
{
331330
ASDisplayNodeAssert(NO, @"Setting the image directly on an ASMultiplexImageNode is unsafe. It will be cleared in didExitPreloadRange and will have no way to restore in didEnterPreloadRange");
332-
[self __setImage:image];
331+
super.image = image;
332+
}
333+
334+
- (void)_setImage:(UIImage *)image
335+
{
336+
super.image = image;
333337
}
334338

335339
- (void)setDelegate:(id <ASMultiplexImageNodeDelegate>)delegate
@@ -527,7 +531,7 @@ - (void)_updateProgressImageBlockOnDownloaderIfNeeded
527531
if (ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
528532
return;
529533
}
530-
[self __setImage:progressImage];
534+
[strongSelf _setImage:progressImage];
531535
};
532536
}
533537
[_downloader setProgressImageBlock:progress callbackQueue:dispatch_get_main_queue() withDownloadIdentifier:_downloadIdentifier];
@@ -545,7 +549,7 @@ - (void)_clearImage
545549
if (shouldReleaseImageOnBackgroundThread) {
546550
ASPerformBackgroundDeallocation(image);
547551
}
548-
[self __setImage:nil];
552+
[self _setImage:nil];
549553
}
550554

551555
#pragma mark -
@@ -874,7 +878,7 @@ - (void)_finishedLoadingImage:(UIImage *)image forIdentifier:(id)imageIdentifier
874878
UIImage *previousImage = self.image;
875879

876880
self.loadedImageIdentifier = imageIdentifier;
877-
[self __setImage:image];
881+
[self _setImage:image];
878882

879883
if (_delegateFlags.updatedImage) {
880884
[_delegate multiplexImageNode:self didUpdateImage:image withIdentifier:imageIdentifier fromImage:previousImage withIdentifier:previousIdentifier];

AsyncDisplayKit/ASNetworkImageNode.mm

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010

1111
#import "ASNetworkImageNode.h"
12-
#import "ASImageNode+Private.h"
1312

1413
#import "ASBasicImageDownloader.h"
1514
#import "ASDisplayNodeInternal.h"
@@ -137,7 +136,12 @@ - (void)setImage:(UIImage *)image
137136
}
138137
__instanceLock__.unlock();
139138

140-
[self __setImage:image];
139+
[self _setImage:image];
140+
}
141+
142+
- (void)_setImage:(UIImage *)image
143+
{
144+
super.image = image;
141145
}
142146

143147
- (void)setURL:(NSURL *)URL
@@ -167,7 +171,7 @@ - (void)setURL:(NSURL *)URL resetToDefault:(BOOL)reset
167171

168172
BOOL hasURL = _URL == nil;
169173
if (reset || hasURL) {
170-
[self __setImage:_defaultImage];
174+
[self _setImage:_defaultImage];
171175
/* We want to maintain the order that currentImageQuality is set regardless of the calling thread,
172176
so always use a dispatch_async to ensure that we queue the operations in the correct order.
173177
(see comment in displayDidFinish) */
@@ -202,7 +206,7 @@ - (void)setDefaultImage:(UIImage *)defaultImage
202206
dispatch_async(dispatch_get_main_queue(), ^{
203207
self.currentImageQuality = hasURL ? 0.0 : 1.0;
204208
});
205-
[self __setImage:defaultImage];
209+
[self _setImage:defaultImage];
206210
}
207211
}
208212

@@ -287,7 +291,7 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously
287291
if (_imageLoaded == NO && _URL && _downloadIdentifier == nil) {
288292
UIImage *result = [[_cache synchronouslyFetchedCachedImageWithURL:_URL] asdk_image];
289293
if (result) {
290-
[self __setImage:result];
294+
[self _setImage:result];
291295
_imageLoaded = YES;
292296
dispatch_async(dispatch_get_main_queue(), ^{
293297
_currentImageQuality = 1.0;
@@ -372,7 +376,7 @@ - (void)handleProgressImage:(UIImage *)progressImage progress:(CGFloat)progress
372376
if (ASObjectIsEqual(_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
373377
return;
374378
}
375-
[self __setImage:progressImage];
379+
[self _setImage:progressImage];
376380
dispatch_async(dispatch_get_main_queue(), ^{
377381
// See comment in -displayDidFinish for why this must be dispatched to main
378382
self.currentImageQuality = progress;
@@ -437,7 +441,7 @@ - (void)_clearImage
437441
ASPerformBackgroundDeallocation(image);
438442
}
439443
self.animatedImage = nil;
440-
[self __setImage:_defaultImage];
444+
[self _setImage:_defaultImage];
441445
_imageLoaded = NO;
442446
// See comment in -displayDidFinish for why this must be dispatched to main
443447
dispatch_async(dispatch_get_main_queue(), ^{
@@ -497,7 +501,7 @@ - (void)_lazilyLoadImageIfNecessary
497501

498502
dispatch_async(dispatch_get_main_queue(), ^{
499503
if (self.shouldCacheImage) {
500-
[self __setImage:[UIImage imageNamed:_URL.path.lastPathComponent]];
504+
[self _setImage:[UIImage imageNamed:_URL.path.lastPathComponent]];
501505
} else {
502506
// First try to load the path directly, for efficiency assuming a developer who
503507
// doesn't want caching is trying to be as minimal as possible.
@@ -527,7 +531,7 @@ - (void)_lazilyLoadImageIfNecessary
527531
if (animatedImage != nil) {
528532
self.animatedImage = animatedImage;
529533
} else {
530-
[self __setImage:nonAnimatedImage];
534+
[self _setImage:nonAnimatedImage];
531535
}
532536
}
533537

@@ -563,7 +567,7 @@ - (void)_lazilyLoadImageIfNecessary
563567
if ([imageContainer asdk_animatedImageData] && _downloaderFlags.downloaderImplementsAnimatedImage) {
564568
strongSelf.animatedImage = [_downloader animatedImageWithData:[imageContainer asdk_animatedImageData]];
565569
} else {
566-
[strongSelf __setImage:[imageContainer asdk_image]];
570+
[strongSelf _setImage:[imageContainer asdk_image]];
567571
}
568572
dispatch_async(dispatch_get_main_queue(), ^{
569573
strongSelf->_currentImageQuality = 1.0;

AsyncDisplayKit/ASVideoNode.mm

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#import "ASEqualityHelpers.h"
1717
#import "ASInternalHelpers.h"
1818
#import "ASDisplayNodeExtras.h"
19-
#import "ASImageNode+Private.h"
2019

2120
static BOOL ASAssetIsEqual(AVAsset *asset1, AVAsset *asset2) {
2221
return ASObjectIsEqual(asset1, asset2)
@@ -90,8 +89,7 @@ @implementation ASVideoNode
9089

9190
// TODO: Support preview images with HTTP Live Streaming videos.
9291

93-
#pragma mark - Lifecycle
94-
92+
#pragma mark - Construction and Layout
9593

9694
- (instancetype)init
9795
{
@@ -229,22 +227,6 @@ - (void) removePlayerObservers:(AVPlayer *)player
229227
}
230228
}
231229

232-
- (void)_fetchDataForVideoNode
233-
{
234-
[self setNeedsPreload];
235-
}
236-
237-
- (void)_clearVideoNode
238-
{
239-
self.videoPlaceholderImage = nil;
240-
self.player = nil;
241-
self.currentItem = nil;
242-
self.playerState = ASVideoNodePlayerStateUnknown;
243-
}
244-
245-
#pragma mark - Layout
246-
247-
248230
- (void)layout
249231
{
250232
[super layout];
@@ -430,7 +412,10 @@ - (void)didExitPreloadState
430412

431413
{
432414
ASDN::MutexLocker l(__instanceLock__);
433-
[self _clearVideoNode];
415+
416+
self.player = nil;
417+
self.currentItem = nil;
418+
self.playerState = ASVideoNodePlayerStateUnknown;
434419
}
435420
}
436421

@@ -521,15 +506,11 @@ - (AVAsset *)asset
521506

522507
- (void)_setAndFetchAsset:(AVAsset *)asset url:(NSURL *)assetURL
523508
{
524-
[self _clearVideoNode];
525-
526-
{
527-
ASDN::MutexLocker l(__instanceLock__);
528-
_asset = asset;
529-
_assetURL = assetURL;
530-
}
531-
532-
[self _fetchDataForVideoNode];
509+
[self setVideoPlaceholderImage:nil];
510+
[self didExitPreloadState];
511+
_asset = asset;
512+
_assetURL = assetURL;
513+
[self setNeedsPreload];
533514
}
534515

535516
- (void)setVideoComposition:(AVVideoComposition *)videoComposition
@@ -638,7 +619,7 @@ - (void)play
638619
}
639620

640621
if (_player == nil) {
641-
[self _fetchDataForVideoNode];
622+
[self setNeedsPreload];
642623
}
643624

644625
if (_playerNode == nil) {

AsyncDisplayKit/Private/ASImageNode+Private.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

AsyncDisplayKitTests/ASVideoNodeTests.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ - (void)testClearingPreloadedContentShouldClearAssetData
410410
[_videoNode didExitPreloadState];
411411
XCTAssertNil(_videoNode.player);
412412
XCTAssertNil(_videoNode.currentItem);
413-
XCTAssertNil(_videoNode.image);
414413
}
415414

416415
- (void)testDelegateProperlySetForClassHierarchy

0 commit comments

Comments
 (0)