Skip to content
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

Merged
merged 2 commits into from
Sep 16, 2019

Conversation

shamanskyh
Copy link
Contributor

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.

if (!CGColorEqualToColor(_layer.backgroundColor, cgBackgroundColor)) {
_layer.backgroundColor = cgBackgroundColor;
BOOL needsClippingCornerUpdate = NO;
CGFloat cornerRadius = _cornerRadius;
Copy link
Contributor Author

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
Copy link
Contributor Author

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?

Copy link
Contributor

@bolsinga bolsinga Sep 16, 2019

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;
Copy link
Contributor

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

Copy link
Contributor Author

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.

// 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;
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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
@rahul-malik rahul-malik merged commit 0b02e8b into TextureGroup:master Sep 16, 2019
rahul-malik added a commit that referenced this pull request Sep 18, 2019
…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.
rahul-malik added a commit that referenced this pull request Sep 18, 2019
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants