Skip to content

Commit

Permalink
[ASDisplayNode] Fix some gaps in the bridging of new contents* proper…
Browse files Browse the repository at this point in the history
…ties. (TextureGroup#435)

I audited this more carefully and found some gaps in my PR from yesterday.

This also ensures the grouping and ordering of all the contents properties
is consistent across all of the places they appear.

In the future, it would be great to make the #define macros more sophisticated
so that we can add property bridging with fewer lines changed, and for
objects besides ASDisplayNode too!
  • Loading branch information
appleguy authored and bernieperez committed Apr 25, 2018
1 parent 9dfe118 commit d27189e
Showing 1 changed file with 82 additions and 34 deletions.
116 changes: 82 additions & 34 deletions Source/Private/_ASPendingState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
int setBounds:1;
int setBackgroundColor:1;
int setTintColor:1;
int setContents:1;
int setHidden:1;
int setAlpha:1;
int setCornerRadius:1;
Expand All @@ -52,13 +51,14 @@
int setAnchorPoint:1;
int setPosition:1;
int setZPosition:1;
int setTransform:1;
int setSublayerTransform:1;
int setContents:1;
int setContentsGravity:1;
int setContentsRect:1;
int setContentsCenter:1;
int setContentsScale:1;
int setRasterizationScale:1;
int setTransform:1;
int setSublayerTransform:1;
int setUserInteractionEnabled:1;
int setExclusiveTouch:1;
int setShadowColor:1;
Expand Down Expand Up @@ -98,20 +98,20 @@ @implementation _ASPendingState
CGRect frame; // Frame is only to be used for synchronous views wrapped by nodes (see setFrame:)
CGRect bounds;
CGColorRef backgroundColor;
id contents;
CGFloat alpha;
CGFloat cornerRadius;
UIViewContentMode contentMode;
CGPoint anchorPoint;
CGPoint position;
CGFloat zPosition;
CATransform3D transform;
CATransform3D sublayerTransform;
id contents;
NSString *contentsGravity;
CGRect contentsRect;
CGRect contentsCenter;
CGFloat contentsScale;
CGFloat rasterizationScale;
CATransform3D transform;
CATransform3D sublayerTransform;
CGColorRef shadowColor;
CGFloat shadowOpacity;
CGSize shadowOffset;
Expand Down Expand Up @@ -169,7 +169,6 @@ ASDISPLAYNODE_INLINE void ASPendingStateApplyMetricsToLayer(_ASPendingState *sta
@synthesize frame=frame;
@synthesize bounds=bounds;
@synthesize backgroundColor=backgroundColor;
@synthesize contents=contents;
@synthesize hidden=isHidden;
@synthesize needsDisplayOnBoundsChange=needsDisplayOnBoundsChange;
@synthesize allowsGroupOpacity=allowsGroupOpacity;
Expand All @@ -184,13 +183,14 @@ ASDISPLAYNODE_INLINE void ASPendingStateApplyMetricsToLayer(_ASPendingState *sta
@synthesize anchorPoint=anchorPoint;
@synthesize position=position;
@synthesize zPosition=zPosition;
@synthesize transform=transform;
@synthesize sublayerTransform=sublayerTransform;
@synthesize contents=contents;
@synthesize contentsGravity=contentsGravity;
@synthesize contentsRect=contentsRect;
@synthesize contentsCenter=contentsCenter;
@synthesize contentsScale=contentsScale;
@synthesize rasterizationScale=rasterizationScale;
@synthesize transform=transform;
@synthesize sublayerTransform=sublayerTransform;
@synthesize userInteractionEnabled=userInteractionEnabled;
@synthesize exclusiveTouch=exclusiveTouch;
@synthesize shadowColor=shadowColor;
Expand Down Expand Up @@ -242,7 +242,6 @@ - (instancetype)init
bounds = CGRectZero;
backgroundColor = nil;
tintColor = defaultTintColor;
contents = nil;
isHidden = NO;
needsDisplayOnBoundsChange = NO;
allowsGroupOpacity = defaultAllowsGroupOpacity;
Expand All @@ -255,9 +254,14 @@ - (instancetype)init
anchorPoint = CGPointMake(0.5, 0.5);
position = CGPointZero;
zPosition = 0.0;
contentsScale = 1.0f;
transform = CATransform3DIdentity;
sublayerTransform = CATransform3DIdentity;
contents = nil;
contentsGravity = kCAGravityResize;
contentsRect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
contentsCenter = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
contentsScale = 1.0f;
rasterizationScale = 1.0f;
userInteractionEnabled = YES;
shadowColor = blackColorRef;
shadowOpacity = 0.0;
Expand Down Expand Up @@ -388,16 +392,6 @@ - (void)setTintColor:(UIColor *)newTintColor
_flags.setTintColor = YES;
}

- (void)setContents:(id)newContents
{
if (contents == newContents) {
return;
}

contents = newContents;
_flags.setContents = YES;
}

- (void)setHidden:(BOOL)flag
{
isHidden = flag;
Expand Down Expand Up @@ -445,12 +439,6 @@ - (void)setZPosition:(CGFloat)newPosition
_flags.setZPosition = YES;
}

- (void)setContentsScale:(CGFloat)newContentsScale
{
contentsScale = newContentsScale;
_flags.setContentsScale = YES;
}

- (void)setTransform:(CATransform3D)newTransform
{
transform = newTransform;
Expand All @@ -463,6 +451,46 @@ - (void)setSublayerTransform:(CATransform3D)newSublayerTransform
_flags.setSublayerTransform = YES;
}

- (void)setContents:(id)newContents
{
if (contents == newContents) {
return;
}

contents = newContents;
_flags.setContents = YES;
}

- (void)setContentsGravity:(NSString *)newContentsGravity
{
contentsGravity = newContentsGravity;
_flags.setContentsGravity = YES;
}

- (void)setContentsRect:(CGRect)newContentsRect
{
contentsRect = newContentsRect;
_flags.setContentsRect = YES;
}

- (void)setContentsCenter:(CGRect)newContentsCenter
{
contentsCenter = newContentsCenter;
_flags.setContentsCenter = YES;
}

- (void)setContentsScale:(CGFloat)newContentsScale
{
contentsScale = newContentsScale;
_flags.setContentsScale = YES;
}

- (void)setRasterizationScale:(CGFloat)newRasterizationScale
{
rasterizationScale = newRasterizationScale;
_flags.setRasterizationScale = YES;
}

- (void)setUserInteractionEnabled:(BOOL)flag
{
userInteractionEnabled = flag;
Expand Down Expand Up @@ -732,9 +760,6 @@ - (void)applyToLayer:(CALayer *)layer
if (flags.setZPosition)
layer.zPosition = zPosition;

if (flags.setContentsScale)
layer.contentsScale = contentsScale;

if (flags.setTransform)
layer.transform = transform;

Expand All @@ -744,6 +769,21 @@ - (void)applyToLayer:(CALayer *)layer
if (flags.setContents)
layer.contents = contents;

if (flags.setContentsGravity)
layer.contentsGravity = contentsGravity;

if (flags.setContentsRect)
layer.contentsRect = contentsRect;

if (flags.setContentsCenter)
layer.contentsCenter = contentsCenter;

if (flags.setContentsScale)
layer.contentsScale = contentsScale;

if (flags.setRasterizationScale)
layer.rasterizationScale = rasterizationScale;

if (flags.setClipsToBounds)
layer.masksToBounds = clipsToBounds;

Expand Down Expand Up @@ -880,7 +920,7 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
view.tintColor = self.tintColor;

if (flags.setOpaque)
view.layer.opaque = opaque;
layer.opaque = opaque;

if (flags.setHidden)
view.hidden = isHidden;
Expand Down Expand Up @@ -942,7 +982,7 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
view.asyncdisplaykit_asyncTransactionContainer = asyncTransactionContainer;

if (flags.setOpaque)
ASDisplayNodeAssert(view.layer.opaque == opaque, @"Didn't set opaque as desired");
ASDisplayNodeAssert(layer.opaque == opaque, @"Didn't set opaque as desired");

if (flags.setSemanticContentAttribute) {
view.semanticContentAttribute = semanticContentAttribute;
Expand Down Expand Up @@ -1024,10 +1064,14 @@ + (_ASPendingState *)pendingViewStateFromLayer:(CALayer *)layer
pendingState.position = layer.position;
pendingState.zPosition = layer.zPosition;
pendingState.bounds = layer.bounds;
pendingState.contentsScale = layer.contentsScale;
pendingState.transform = layer.transform;
pendingState.sublayerTransform = layer.sublayerTransform;
pendingState.contents = layer.contents;
pendingState.contentsGravity = layer.contentsGravity;
pendingState.contentsRect = layer.contentsRect;
pendingState.contentsCenter = layer.contentsCenter;
pendingState.contentsScale = layer.contentsScale;
pendingState.rasterizationScale = layer.rasterizationScale;
pendingState.clipsToBounds = layer.masksToBounds;
pendingState.backgroundColor = layer.backgroundColor;
pendingState.opaque = layer.opaque;
Expand Down Expand Up @@ -1139,10 +1183,14 @@ - (BOOL)hasChanges
|| flags.setFrame
|| flags.setBounds
|| flags.setPosition
|| flags.setContentsScale
|| flags.setTransform
|| flags.setSublayerTransform
|| flags.setContents
|| flags.setContentsGravity
|| flags.setContentsRect
|| flags.setContentsCenter
|| flags.setContentsScale
|| flags.setRasterizationScale
|| flags.setClipsToBounds
|| flags.setBackgroundColor
|| flags.setTintColor
Expand Down

0 comments on commit d27189e

Please sign in to comment.