Ensure that the uncommon __unloadNode codepath does not unintentionally trigger node removal.

This commit is contained in:
Scott Goodson
2015-12-29 23:11:33 -08:00
parent 95e28d6c11
commit df3ce787f7
4 changed files with 31 additions and 3 deletions

View File

@@ -352,6 +352,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
- (void)__unloadNode
{
ASDisplayNodeAssertThreadAffinity(self);
ASDisplayNodeAssert([self isNodeLoaded], @"Implementation shouldn't call __unloadNode if not loaded: %@", self);
ASDN::MutexLocker l(_propertyLock);
if (_flags.layerBacked)

View File

@@ -151,8 +151,11 @@
needsSupernodeRemoval = YES;
}
} else {
// If supernode is loaded but our superview is nil, the user manually removed us, so disconnect supernode.
needsSupernodeRemoval = supernodeLoaded;
// If supernode is loaded but our superview is nil, the user likely manually removed us, so disconnect supernode.
// The unlikely alternative: we are in __unloadNode, with shouldRasterizeSubnodes just having been turned on.
// In the latter case, we don't want to disassemble the node hierarchy because all views are intentionally being destroyed.
BOOL nodeIsRasterized = ((_node.hierarchyState & ASHierarchyStateRasterized) == ASHierarchyStateRasterized);
needsSupernodeRemoval = (supernodeLoaded && !nodeIsRasterized);
}
if (needsSupernodeRemoval) {

View File

@@ -798,8 +798,13 @@ static UIColor *defaultTintColor = nil;
view.accessibilityIdentifier = accessibilityIdentifier;
}
// FIXME: Make this more efficient by tracking which properties are set rather than reading everything.
+ (_ASPendingState *)pendingViewStateFromLayer:(CALayer *)layer
{
if (!layer) {
return nil;
}
_ASPendingState *pendingState = [[_ASPendingState alloc] init];
pendingState.anchorPoint = layer.anchorPoint;
@@ -877,8 +882,13 @@ static UIColor *defaultTintColor = nil;
return pendingState;
}
// FIXME: Make this more efficient by tracking which properties are set rather than reading everything.
+ (_ASPendingState *)pendingViewStateFromView:(UIView *)view
{
if (!view) {
return nil;
}
_ASPendingState *pendingState = [[_ASPendingState alloc] init];
CALayer *layer = view.layer;

View File

@@ -134,4 +134,18 @@
return _socialAppDataSource.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PostNode *postNode = (PostNode *)[_tableView nodeForRowAtIndexPath:indexPath];
Post *post = _socialAppDataSource[indexPath.row];
BOOL shouldRasterize = postNode.shouldRasterizeDescendants;
shouldRasterize = !shouldRasterize;
postNode.shouldRasterizeDescendants = shouldRasterize;
NSLog(@"%@ rasterization for %@'s post: %@", shouldRasterize ? @"Enabling" : @"Disabling", post.name, postNode);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end