[ASDisplayNode] Clarify logic around calling setNeedsDisplay (#2094)

This commit is contained in:
Adlai Holler
2016-08-18 09:45:43 -07:00
committed by GitHub
parent 4baffea8f6
commit 00af76226d
2 changed files with 14 additions and 16 deletions

View File

@@ -284,7 +284,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
_defaultLayoutTransitionOptions = UIViewAnimationOptionBeginFromCurrentState; _defaultLayoutTransitionOptions = UIViewAnimationOptionBeginFromCurrentState;
_flags.canClearContentsOfLayer = YES; _flags.canClearContentsOfLayer = YES;
_flags.canCallNeedsDisplayOfLayer = NO; _flags.canCallSetNeedsDisplayOfLayer = YES;
} }
- (instancetype)init - (instancetype)init
@@ -454,12 +454,9 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
} }
// Update flags related to special handling of UIImageView layers. More details on the flags // Update flags related to special handling of UIImageView layers. More details on the flags
if (_flags.synchronous) { if (_flags.synchronous && [_viewClass isSubclassOfClass:[UIImageView class]]) {
if ([view isKindOfClass:[UIImageView class]]) { _flags.canClearContentsOfLayer = NO;
_flags.canClearContentsOfLayer = NO; _flags.canCallSetNeedsDisplayOfLayer = NO;
} else {
_flags.canCallNeedsDisplayOfLayer = YES;
}
} }
return view; return view;
@@ -2056,11 +2053,11 @@ static NSInteger incrementIfFound(NSInteger i) {
_flags.implementsInstanceDrawRect || _flags.implementsInstanceImageDisplay; _flags.implementsInstanceDrawRect || _flags.implementsInstanceImageDisplay;
} }
// Helper method to determine if it's save to call setNeedsDisplay on a layer without throwing away the content. // Helper method to determine if it's safe to call setNeedsDisplay on a layer without throwing away the content.
// For details look at the comment on the canCallNeedsDisplayOfLayer flag // For details look at the comment on the canCallSetNeedsDisplayOfLayer flag
- (BOOL)__canCallNeedsDisplayOfLayer - (BOOL)__canCallSetNeedsDisplayOfLayer
{ {
return _flags.canCallNeedsDisplayOfLayer; return _flags.canCallSetNeedsDisplayOfLayer;
} }
- (BOOL)placeholderShouldPersist - (BOOL)placeholderShouldPersist
@@ -2111,9 +2108,10 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
ASDisplayNode *node = [layer asyncdisplaykit_node]; ASDisplayNode *node = [layer asyncdisplaykit_node];
if ([node __canCallNeedsDisplayOfLayer]) { if (node.isSynchronous && [node __canCallSetNeedsDisplayOfLayer]) {
// Layers for UIKit components that are wrapped wtihin a node needs to be set to be displayed as the contents of // Layers for UIKit components that are wrapped within a node needs to be set to be displayed as the contents of
// the layer get's cleared and would not be recreated otherwise // the layer get's cleared and would not be recreated otherwise.
// We do not call this for _ASDisplayLayer as an optimization.
[layer setNeedsDisplay]; [layer setNeedsDisplay];
} }

View File

@@ -83,10 +83,10 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
// Prevent calling setNeedsDisplay on a layer that backs a UIImageView. Usually calling setNeedsDisplay on a CALayer // Prevent calling setNeedsDisplay on a layer that backs a UIImageView. Usually calling setNeedsDisplay on a CALayer
// triggers a recreation of the contents of layer unfortunately calling it on a CALayer that backs a UIImageView // triggers a recreation of the contents of layer unfortunately calling it on a CALayer that backs a UIImageView
// it goes trough the normal flow to assign the contents to a layer via the CALayerDelegate methods. Unfortunately // it goes through the normal flow to assign the contents to a layer via the CALayerDelegate methods. Unfortunately
// UIImageView does not do recreate the layer contents the usual way, it actually does not implement some of the // UIImageView does not do recreate the layer contents the usual way, it actually does not implement some of the
// methods at all instead it throws away the contents of the layer and nothing will show up. // methods at all instead it throws away the contents of the layer and nothing will show up.
unsigned canCallNeedsDisplayOfLayer:1; unsigned canCallSetNeedsDisplayOfLayer:1;
// whether custom drawing is enabled // whether custom drawing is enabled
unsigned implementsInstanceDrawRect:1; unsigned implementsInstanceDrawRect:1;