Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pending state type for backgroundColor to UIColor #1593

Merged
merged 1 commit into from
Jul 21, 2019
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
2 changes: 1 addition & 1 deletion Source/Details/UIView+ASConvenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) CGFloat borderWidth;
@property (nonatomic, getter = isOpaque) BOOL opaque;
@property (nonatomic) __attribute__((NSObject)) CGColorRef borderColor;
@property (nonatomic) __attribute__((NSObject)) CGColorRef backgroundColor;
@property (nonatomic) UIColor *backgroundColor;
@property (nonatomic) BOOL allowsGroupOpacity;
@property (nonatomic) BOOL allowsEdgeAntialiasing;
@property (nonatomic) unsigned int edgeAntialiasingMask;
Expand Down
13 changes: 6 additions & 7 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -750,24 +750,23 @@ - (UIColor *)backgroundColor
if (!_flags.layerBacked) {
return _view.backgroundColor;
} else {
return [UIColor colorWithCGColor:_getFromLayer(backgroundColor)];
return [UIColor colorWithCGColor:_layer.backgroundColor];
}
}
return [UIColor colorWithCGColor:ASDisplayNodeGetPendingState(self).backgroundColor];
return ASDisplayNodeGetPendingState(self).backgroundColor;
}

- (void)setBackgroundColor:(UIColor *)newBackgroundColor
{
_bridge_prologue_write;


BOOL shouldApply = ASDisplayNodeShouldApplyBridgedWriteToView(self);
CGColorRef newBackgroundCGColor = newBackgroundColor.CGColor;
CGColorRef newBackgroundCGColor = nil;
if (shouldApply) {
CGColorRef oldBackgroundCGColor = _layer.backgroundColor;

if (_flags.layerBacked) {
_layer.backgroundColor = newBackgroundColor.CGColor;
newBackgroundCGColor = _layer.backgroundColor;
} else {
/*
NOTE: Setting to the view and layer individually is necessary.
Expand All @@ -778,9 +777,9 @@ - (void)setBackgroundColor:(UIColor *)newBackgroundColor

*/
_view.backgroundColor = newBackgroundColor;
_layer.backgroundColor = _view.backgroundColor.CGColor;
// Gather the CGColorRef from the view incase there are any changes it might apply to which CGColorRef is returned for dynamic colors
newBackgroundCGColor = _view.backgroundColor.CGColor;
_layer.backgroundColor = newBackgroundCGColor;
}

if (!CGColorEqualToColor(oldBackgroundCGColor, newBackgroundCGColor)) {
Expand All @@ -790,7 +789,7 @@ - (void)setBackgroundColor:(UIColor *)newBackgroundColor
// NOTE: If we're in the background, we cannot read the current value of bgcolor (if loaded).
// When the pending state is applied to the view on main, we will call `setNeedsDisplay` if
// the new background color doesn't match the one on the layer.
ASDisplayNodeGetPendingState(self).backgroundColor = newBackgroundCGColor;
ASDisplayNodeGetPendingState(self).backgroundColor = newBackgroundColor;
}
}

Expand Down
36 changes: 18 additions & 18 deletions Source/Private/_ASPendingState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASInternalHelpers.h>

#define __shouldSetNeedsDisplay(layer) (flags.needsDisplay \
#define __shouldSetNeedsDisplayForView(view) (flags.needsDisplay \
|| (flags.setOpaque && _flags.opaque != (view).opaque)\
|| (flags.setBackgroundColor && ![backgroundColor isEqual:(view).backgroundColor]))

#define __shouldSetNeedsDisplayForLayer(layer) (flags.needsDisplay \
|| (flags.setOpaque && _flags.opaque != (layer).opaque)\
|| (flags.setBackgroundColor && !CGColorEqualToColor(backgroundColor, (layer).backgroundColor)))
|| (flags.setBackgroundColor && ![backgroundColor isEqual:[UIColor colorWithCGColor:(layer).backgroundColor]]))

typedef struct {
// Properties
Expand Down Expand Up @@ -102,7 +106,7 @@ @implementation _ASPendingState
unsigned int edgeAntialiasingMask;
CGRect frame; // Frame is only to be used for synchronous views wrapped by nodes (see setFrame:)
CGRect bounds;
CGColorRef backgroundColor;
UIColor *backgroundColor;
CGFloat alpha;
CGFloat cornerRadius;
UIViewContentMode contentMode;
Expand Down Expand Up @@ -415,19 +419,17 @@ - (void)setBounds:(CGRect)newBounds
_stateToApplyFlags.setBounds = YES;
}

- (CGColorRef)backgroundColor
- (UIColor *)backgroundColor
{
return backgroundColor;
}

- (void)setBackgroundColor:(CGColorRef)color
- (void)setBackgroundColor:(UIColor *)color
{
if (color == backgroundColor) {
if ([color isEqual:backgroundColor]) {
return;
}

CGColorRelease(backgroundColor);
backgroundColor = CGColorRetain(color);
backgroundColor = color;
_stateToApplyFlags.setBackgroundColor = YES;
}

Expand Down Expand Up @@ -926,7 +928,7 @@ - (void)applyToLayer:(CALayer *)layer
{
ASPendingStateFlags flags = _stateToApplyFlags;

if (__shouldSetNeedsDisplay(layer)) {
if (__shouldSetNeedsDisplayForLayer(layer)) {
[layer setNeedsDisplay];
}

Expand Down Expand Up @@ -964,7 +966,7 @@ - (void)applyToLayer:(CALayer *)layer
layer.masksToBounds = _flags.clipsToBounds;

if (flags.setBackgroundColor)
layer.backgroundColor = backgroundColor;
layer.backgroundColor = backgroundColor.CGColor;

if (flags.setOpaque)
layer.opaque = _flags.opaque;
Expand Down Expand Up @@ -1048,7 +1050,7 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
unowned CALayer *layer = view.layer;

ASPendingStateFlags flags = _stateToApplyFlags;
if (__shouldSetNeedsDisplay(layer)) {
if (__shouldSetNeedsDisplayForView(view)) {
[view setNeedsDisplay];
}

Expand Down Expand Up @@ -1095,8 +1097,8 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
view.clipsToBounds = _flags.clipsToBounds;

if (flags.setBackgroundColor) {
view.backgroundColor = [UIColor colorWithCGColor:backgroundColor];
layer.backgroundColor = backgroundColor;
view.backgroundColor = backgroundColor;
layer.backgroundColor = backgroundColor.CGColor;
}

if (flags.setTintColor)
Expand Down Expand Up @@ -1286,7 +1288,7 @@ + (_ASPendingState *)pendingViewStateFromLayer:(CALayer *)layer
pendingState.contentsScale = layer.contentsScale;
pendingState.rasterizationScale = layer.rasterizationScale;
pendingState.clipsToBounds = layer.masksToBounds;
pendingState.backgroundColor = layer.backgroundColor;
pendingState.backgroundColor = [UIColor colorWithCGColor:layer.backgroundColor];
pendingState.opaque = layer.opaque;
pendingState.hidden = layer.hidden;
pendingState.alpha = layer.opacity;
Expand Down Expand Up @@ -1327,7 +1329,7 @@ + (_ASPendingState *)pendingViewStateFromView:(UIView *)view
pendingState.contentsScale = layer.contentsScale;
pendingState.rasterizationScale = layer.rasterizationScale;
pendingState.clipsToBounds = view.clipsToBounds;
pendingState.backgroundColor = layer.backgroundColor;
pendingState.backgroundColor = [UIColor colorWithCGColor:layer.backgroundColor];
pendingState.tintColor = view.tintColor;
pendingState.opaque = layer.opaque;
pendingState.hidden = view.hidden;
Expand Down Expand Up @@ -1404,8 +1406,6 @@ - (BOOL)hasChanges

- (void)dealloc
{
CGColorRelease(backgroundColor);

if (shadowColor != blackColorRef) {
CGColorRelease(shadowColor);
}
Expand Down