Skip to content

Commit

Permalink
Fix strange issue where setting UIView backgroundColor sets the layer to
Browse files Browse the repository at this point in the history
opaque to false
  • Loading branch information
rahul-malik committed Jul 19, 2019
1 parent f889231 commit 3d2d5d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 445046ac151568c694ff286684322273f0b597d6

COCOAPODS: 1.6.1
COCOAPODS: 1.6.0
9 changes: 5 additions & 4 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ - (void)layoutIfNeeded
- (BOOL)isOpaque
{
_bridge_prologue_read;
return _getFromLayer(opaque);
return _getFromViewOrLayer(opaque, opaque);
}


Expand All @@ -521,10 +521,11 @@ - (void)setOpaque:(BOOL)newOpaque
BOOL shouldApply = ASDisplayNodeShouldApplyBridgedWriteToView(self);

if (shouldApply) {
BOOL oldOpaque;
oldOpaque = _layer.opaque;
BOOL oldOpaque = _layer.opaque;
if (!_flags.layerBacked) {
_view.opaque = newOpaque;
}
_layer.opaque = newOpaque;

if (oldOpaque != newOpaque) {
[self setNeedsDisplay];
}
Expand Down
4 changes: 3 additions & 1 deletion Source/Private/_ASPendingState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,10 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
if (flags.setTintColor)
view.tintColor = self.tintColor;

if (flags.setOpaque)
if (flags.setOpaque) {
view.opaque = _flags.opaque;
layer.opaque = _flags.opaque;
}

if (flags.setHidden)
view.hidden = _flags.hidden;
Expand Down
16 changes: 13 additions & 3 deletions Tests/ASDisplayNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1923,13 +1923,23 @@ - (void)checkBackgroundColorOpaqueRelationshipWithViewLoaded:(BOOL)loaded layerB
}

XCTAssertTrue(node.opaque, @"Node should start opaque");
XCTAssertTrue(node.layer.opaque, @"Node should start opaque");
if (isLayerBacked) {
XCTAssertTrue(node.layer.opaque, @"Set background color should not have made this layer not opaque");
} else {
XCTAssertTrue(node.view.opaque, @"Set background color should not have made this view not opaque");
}

node.backgroundColor = [UIColor blackColor];
node.backgroundColor = [UIColor clearColor];
// [node.view setNeedsDisplay];

// This could be debated, but at the moment we differ from UIView's behavior to change the other property in response
XCTAssertTrue(node.opaque, @"Set background color should not have made this not opaque");
XCTAssertTrue(node.layer.opaque, @"Set background color should not have made this not opaque");
if (isLayerBacked) {
XCTAssertTrue(node.layer.opaque, @"Set background color should not have made this layer not opaque");
} else {
XCTAssertTrue(node.view.opaque, @"Set background color should not have made this view not opaque");
}

}

- (void)testBackgroundColorOpaqueRelationshipView
Expand Down

0 comments on commit 3d2d5d4

Please sign in to comment.