Skip to content

Commit

Permalink
fix a node background color in non layer baked mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
vovasty committed Oct 1, 2019
1 parent ee18b9c commit ed629d2
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
11 changes: 5 additions & 6 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,13 @@ - (void)asyncTraitCollectionDidChangeWithPreviousTraitCollection:(ASPrimitiveTra
ASCornerRoundingType cornerRoundingType = _cornerRoundingType;
UIColor *backgroundColor = _backgroundColor;
if (_loaded(self)) {
if (self.isLayerBacked) {
CGColorRef cgBackgroundColor = backgroundColor.CGColor;
if (!CGColorEqualToColor(_layer.backgroundColor, cgBackgroundColor)) {
// Background colors do not dynamically update for layer backed nodes since they utilize CGColorRef
// instead of UIColor. We utilize the _backgroundColor instance variable to track the full dynamic color
// instead of UIColor. Non layer backed node also receive color to the layer (see [_ASPendingState -applyToView:withSpecialPropertiesHandling:]).
// We utilize the _backgroundColor instance variable to track the full dynamic color
// and apply any changes here when trait collection updates occur.
CGColorRef cgBackgroundColor = backgroundColor.CGColor;
if (!CGColorEqualToColor(_layer.backgroundColor, cgBackgroundColor)) {
_layer.backgroundColor = cgBackgroundColor;
}
_layer.backgroundColor = cgBackgroundColor;
}
// If we have clipping corners, re-render the clipping corner layer upon user interface style change
if (cornerRoundingType == ASCornerRoundingTypeClipping && cornerRadius > 0.0f) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Private/_ASPendingState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ + (_ASPendingState *)pendingViewStateFromView:(UIView *)view
pendingState.contentsScale = layer.contentsScale;
pendingState.rasterizationScale = layer.rasterizationScale;
pendingState.clipsToBounds = view.clipsToBounds;
pendingState.backgroundColor = [UIColor colorWithCGColor:layer.backgroundColor];
pendingState.backgroundColor = view.backgroundColor;
pendingState.tintColor = view.tintColor;
pendingState.opaque = layer.opaque;
pendingState.hidden = view.hidden;
Expand Down
50 changes: 46 additions & 4 deletions Tests/ASDisplayNodeSnapshotTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ @interface ASDisplayNodeSnapshotTests : ASSnapshotTestCase

@implementation ASDisplayNodeSnapshotTests

- (void)setUp {
[super setUp];
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalTraitCollectionDidChangeWithPreviousCollection;
[ASConfigurationManager test_resetWithConfiguration:config];
}

- (void)testBasicHierarchySnapshotTesting
{
ASDisplayNode *node = [[ASDisplayNode alloc] init];
Expand Down Expand Up @@ -112,10 +119,6 @@ - (void)testClippingCornerRounding
- (void)testUserInterfaceStyleSnapshotTesting
{
if (@available(iOS 13.0, *)) {
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalTraitCollectionDidChangeWithPreviousCollection;
[ASConfigurationManager test_resetWithConfiguration:config];

ASDisplayNode *node = [[ASDisplayNode alloc] init];
[node setLayerBacked:YES];

Expand All @@ -134,6 +137,45 @@ - (void)testUserInterfaceStyleSnapshotTesting
}
}

- (void)testBackgroundDynamicColor {
if (@available(iOS 13.0, *)) {
ASDisplayNode *node = [[ASImageNode alloc] init];
node.backgroundColor = [UIColor systemGray6Color];
auto bounds = CGRectMake(0, 0, 100, 100);
node.frame = bounds;

UITraitCollection *tcLight = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight];
[tcLight performAsCurrentTraitCollection: ^{
ASSnapshotVerifyNode(node, @"light");
}];

UITraitCollection *tcDark = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
[tcDark performAsCurrentTraitCollection: ^{
ASSnapshotVerifyNode(node, @"dark");
}];
}
}

- (void)testBackgroundDynamicColorLayerBacked {
if (@available(iOS 13.0, *)) {
ASDisplayNode *node = [[ASImageNode alloc] init];
node.backgroundColor = [UIColor systemGray6Color];
node.layerBacked = YES;
auto bounds = CGRectMake(0, 0, 100, 100);
node.frame = bounds;

UITraitCollection *tcLight = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight];
[tcLight performAsCurrentTraitCollection: ^{
ASSnapshotVerifyNode(node, @"light");
}];

UITraitCollection *tcDark = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
[tcDark performAsCurrentTraitCollection: ^{
ASSnapshotVerifyNode(node, @"dark");
}];
}
}

#endif // #if AS_AT_LEAST_IOS13

@end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ed629d2

Please sign in to comment.