From 3d2d5d41e8e5e78826e1badfce3b5a2e3218274b Mon Sep 17 00:00:00 2001 From: Rahul Malik Date: Thu, 18 Jul 2019 20:07:57 -0700 Subject: [PATCH] Fix strange issue where setting UIView backgroundColor sets the layer to opaque to false --- Podfile.lock | 2 +- Source/Private/ASDisplayNode+UIViewBridge.mm | 9 +++++---- Source/Private/_ASPendingState.mm | 4 +++- Tests/ASDisplayNodeTests.mm | 16 +++++++++++++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index a0cfa42e7..df3c6fcb8 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -52,4 +52,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 445046ac151568c694ff286684322273f0b597d6 -COCOAPODS: 1.6.1 +COCOAPODS: 1.6.0 diff --git a/Source/Private/ASDisplayNode+UIViewBridge.mm b/Source/Private/ASDisplayNode+UIViewBridge.mm index d8de7106c..9ca13464d 100644 --- a/Source/Private/ASDisplayNode+UIViewBridge.mm +++ b/Source/Private/ASDisplayNode+UIViewBridge.mm @@ -511,7 +511,7 @@ - (void)layoutIfNeeded - (BOOL)isOpaque { _bridge_prologue_read; - return _getFromLayer(opaque); + return _getFromViewOrLayer(opaque, opaque); } @@ -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]; } diff --git a/Source/Private/_ASPendingState.mm b/Source/Private/_ASPendingState.mm index 403c33c55..2663955a5 100644 --- a/Source/Private/_ASPendingState.mm +++ b/Source/Private/_ASPendingState.mm @@ -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; diff --git a/Tests/ASDisplayNodeTests.mm b/Tests/ASDisplayNodeTests.mm index b0adace25..761072f87 100644 --- a/Tests/ASDisplayNodeTests.mm +++ b/Tests/ASDisplayNodeTests.mm @@ -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