Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions AsyncDisplayKit/ASDisplayNode+Subclasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ NS_ASSUME_NONNULL_BEGIN
*
* @discussion Subclasses may override this method to be notified when display (asynchronous or synchronous) is
* about to begin.
*
* @note Called on the main thread only
*/
- (void)displayWillStart ASDISPLAYNODE_REQUIRES_SUPER;

Expand All @@ -214,6 +216,8 @@ NS_ASSUME_NONNULL_BEGIN
*
* @discussion Subclasses may override this method to be notified when display (asynchronous or synchronous) has
* completed.
*
* @note Called on the main thread only
*/
- (void)displayDidFinish ASDISPLAYNODE_REQUIRES_SUPER;

Expand All @@ -227,6 +231,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfaceState)oldState ASDISPLAYNODE_REQUIRES_SUPER;

/**
* @abstract Called whenever the visiblity of the node changed.
*
* @discussion Subclasses may use this to monitor when they become visible.
*/
- (void)visibilityDidChange:(BOOL)isVisible ASDISPLAYNODE_REQUIRES_SUPER;

/**
Expand Down
50 changes: 28 additions & 22 deletions AsyncDisplayKit/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ - (void)__setSupernode:(ASDisplayNode *)newSupernode
// The node sending the message should usually be passed as the parameter, similar to the delegation pattern.
- (void)_pendingNodeWillDisplay:(ASDisplayNode *)node
{
ASDN::MutexLocker l(_propertyLock);
ASDisplayNodeAssertMainThread();

if (!_pendingDisplayNodes) {
_pendingDisplayNodes = [[NSMutableSet alloc] init];
Expand All @@ -1670,27 +1670,25 @@ - (void)_pendingNodeWillDisplay:(ASDisplayNode *)node
// The node sending the message should usually be passed as the parameter, similar to the delegation pattern.
- (void)_pendingNodeDidDisplay:(ASDisplayNode *)node
{
ASDN::MutexLocker l(_propertyLock);
ASDisplayNodeAssertMainThread();

[_pendingDisplayNodes removeObject:node];

// only trampoline if there is a placeholder and nodes are done displaying
if ([self _pendingDisplayNodesHaveFinished] && _placeholderLayer.superlayer) {
dispatch_async(dispatch_get_main_queue(), ^{
void (^cleanupBlock)() = ^{
[self _tearDownPlaceholderLayer];
};

if (_placeholderFadeDuration > 0.0 && ASInterfaceStateIncludesVisible(self.interfaceState)) {
[CATransaction begin];
[CATransaction setCompletionBlock:cleanupBlock];
[CATransaction setAnimationDuration:_placeholderFadeDuration];
_placeholderLayer.opacity = 0.0;
[CATransaction commit];
} else {
cleanupBlock();
}
});
void (^cleanupBlock)() = ^{
[self _tearDownPlaceholderLayer];
};

if (_placeholderFadeDuration > 0.0 && ASInterfaceStateIncludesVisible(self.interfaceState)) {
[CATransaction begin];
[CATransaction setCompletionBlock:cleanupBlock];
[CATransaction setAnimationDuration:_placeholderFadeDuration];
_placeholderLayer.opacity = 0.0;
[CATransaction commit];
} else {
cleanupBlock();
}
}
}

Expand Down Expand Up @@ -1984,6 +1982,7 @@ - (void)recursivelyClearFetchedData

- (void)visibilityDidChange:(BOOL)isVisible
{
// subclass override
}

/**
Expand Down Expand Up @@ -2260,6 +2259,8 @@ - (void)__layoutSublayouts

- (void)displayWillStart
{
ASDisplayNodeAssertMainThread();

// in case current node takes longer to display than it's subnodes, treat it as a dependent node
[self _pendingNodeWillDisplay:self];

Expand Down Expand Up @@ -2288,6 +2289,8 @@ - (void)_setupPlaceholderLayerContents

- (void)displayDidFinish
{
ASDisplayNodeAssertMainThread();

[self _pendingNodeDidDisplay:self];

[_supernode subnodeDisplayDidFinish:self];
Expand Down Expand Up @@ -2494,11 +2497,14 @@ - (void)setDisplaySuspended:(BOOL)flag
self.asyncLayer.displaySuspended = flag;

if ([self __implementsDisplay]) {
if (flag) {
[_supernode subnodeDisplayDidFinish:self];
} else {
[_supernode subnodeDisplayWillStart:self];
}
// Display start and finish methods needs to happen on the main thread
ASPerformBlockOnMainThread(^{
if (flag) {
[_supernode subnodeDisplayDidFinish:self];
} else {
[_supernode subnodeDisplayWillStart:self];
}
});
}
}

Expand Down