-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
#1673 - Re-render Clipping Corners when User Interface Style Changes #1674
#1673 - Re-render Clipping Corners when User Interface Style Changes #1674
Conversation
if (!CGColorEqualToColor(_layer.backgroundColor, cgBackgroundColor)) { | ||
_layer.backgroundColor = cgBackgroundColor; | ||
BOOL needsClippingCornerUpdate = NO; | ||
CGFloat cornerRadius = _cornerRadius; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capturing these values up here so they're behind the lock, but in scope when we call _updateClipCornerLayerContentsWithRadius
on line 466
@@ -61,18 +61,50 @@ - (void)testPrecompositedCornerRounding | |||
|
|||
- (void)testClippingCornerRounding | |||
{ | |||
self.recordMode = YES; | |||
#if AS_AT_LEAST_IOS13 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking for feedback on this inline approach. Should I delete the reference images for older Xcode/iOS versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think this is fine for now. I'm assuming you tested both with & without iOS13?
BOOL needsClippingCornerUpdate = NO; | ||
CGFloat cornerRadius = _cornerRadius; | ||
ASCornerRoundingType cornerRoundingType = _cornerRoundingType; | ||
UIColor *backgroundColor = self.backgroundColor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason we're using self.backgroundColor
vs _backgroundColor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.backgroundColor
has a getter that pulls from the layer or the view. _backgroundColor
should only be used if layer backed.
Source/ASDisplayNode.mm
Outdated
// 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 | ||
// and apply any changes here when trait collection updates occur. | ||
CGColorRef cgBackgroundColor = _backgroundColor.CGColor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use should use the new local variable here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
node.maskedCorners = c; | ||
node.cornerRadius = 15; | ||
// A layout pass is required, because that's where we lay out the clip layers. | ||
[node.layer layoutIfNeeded]; | ||
|
||
#if AS_AT_LEAST_IOS13 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably write a macro for light/dark testing if we're doing this a lot
…clipping corner layer doesn't get re-rendered when going from a dark to light user interface style. The fix is to add code in the `-asyncTraitCollectionDidChangeWithPreviousTraitCollection:` method that calls through to `-_updateClipCornerLayerContentsWithRadius:backgroundColor:` if the user interface style changes. I've also added snapshot tests to verify that using clipping corners with a dynamic background color updates when the user interface style changes. Turn off record mode, remove errant newline This PR addresses an issue I raised with TextureGroup#1673 where the clipping corner layer doesn't get re-rendered when going from a dark to light user interface style. The fix is to add code in the `-asyncTraitCollectionDidChangeWithPreviousTraitCollection:` method that calls through to `-_updateClipCornerLayerContentsWithRadius:backgroundColor:` if the user interface style changes. I've also added snapshot tests to verify that using clipping corners with a dynamic background color updates when the user interface style changes. Turn off record mode, remove errant newline
a6167b2
to
a03e077
Compare
…nDidChange traitCollectionDidChange isn't necessarily called on Main, but our self.backgroundColor property access must be done on main once the view is loaded. I originally opted to use self.backgroundColor rather than _backgroundColor in #1674, but I think we should use the ivar here. This could get out-of-sync if someone modified the UIView's background color instead of updating the node, but I think that's unlikely, so we should be safe to use the ivar here.
…nDidChange (#1678) traitCollectionDidChange isn't necessarily called on Main, but our self.backgroundColor property access must be done on main once the view is loaded. I originally opted to use self.backgroundColor rather than _backgroundColor in #1674, but I think we should use the ivar here. This could get out-of-sync if someone modified the UIView's background color instead of updating the node, but I think that's unlikely, so we should be safe to use the ivar here.
This PR addresses an issue I raised with #1673 where the clipping corner layer doesn't get re-rendered when going from a dark to light user interface style. The fix is to add code in the
-asyncTraitCollectionDidChangeWithPreviousTraitCollection:
method that calls through to-_updateClipCornerLayerContentsWithRadius:backgroundColor:
if the user interface style changes.I've also added snapshot tests to verify that using clipping corners with a dynamic background color updates when the user interface style changes.