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 75fa029
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 4 additions & 2 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 @@ -524,7 +524,9 @@ - (void)setOpaque:(BOOL)newOpaque
BOOL oldOpaque;
oldOpaque = _layer.opaque;
_layer.opaque = newOpaque;

if (!_flags.layerBacked) {
_view.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 75fa029

Please sign in to comment.