Add method to cancel layout transitions in progress

- Also make sure a transition isn't invalidated right after it passed the validation test and before it proceeds
This commit is contained in:
Huy Nguyen
2016-03-20 23:14:53 -07:00
parent 1a57e2c097
commit 9e76d7b603
2 changed files with 23 additions and 10 deletions

View File

@@ -98,4 +98,9 @@ ASDISPLAYNODE_EXTERN_C_END
*/
- (BOOL)placeholderShouldPersist;
/**
* @abstract Cancels all performing layout transitions. Can be called on any thread.
*/
- (void)cancelLayoutTransitionsInProgress;
@end

View File

@@ -593,14 +593,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
return _layout;
}
if ([self _hasTransitionsInProgress]) {
// Invalidate transition sentinel to cancel transitions in progress
[self _invalidateTransitionSentinel];
// Tell subnodes to exit layout pending state and clear related properties
ASDisplayNodePerformBlockOnEverySubnode(self, ^(ASDisplayNode * _Nonnull node) {
node.hierarchyState &= (~ASHierarchyStateLayoutPending);
});
}
[self cancelLayoutTransitionsInProgress];
ASLayout *previousLayout = _layout;
ASSizeRange previousConstrainedSize = _constrainedSize;
@@ -698,12 +691,14 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
}
ASPerformBlockOnMainThread(^{
// Grab _propertyLock here to make sure this transition isn't invalidated
// right after it passed the validation test and before it proceeds
ASDN::MutexLocker l(_propertyLock);
if ([self _shouldAbortTransitionWithID:transitionID]) {
return;
}
ASDN::MutexLocker l(_propertyLock);
ASLayout *previousLayout = _layout;
ASSizeRange previousConstrainedSize = _constrainedSize;
[self applyLayout:newLayout constrainedSize:constrainedSize layoutContext:nil];
@@ -769,6 +764,19 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
// subclass override
}
- (void)cancelLayoutTransitionsInProgress
{
ASDN::MutexLocker l(_propertyLock);
if ([self _hasTransitionsInProgress]) {
// Invalidate transition sentinel to cancel transitions in progress
[self _invalidateTransitionSentinel];
// Tell subnodes to exit layout pending state and clear related properties
ASDisplayNodePerformBlockOnEverySubnode(self, ^(ASDisplayNode * _Nonnull node) {
node.hierarchyState &= (~ASHierarchyStateLayoutPending);
});
}
}
#pragma mark - Layout Transition
- (BOOL)usesImplicitHierarchyManagement