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

Re-render Clipping Corners when User Interface Style Changes is broken #2049

Open
Kaelzs opened this issue Dec 6, 2021 · 0 comments
Open

Comments

@Kaelzs
Copy link

Kaelzs commented Dec 6, 2021

I found a pr here Re-render Clipping Corners when User Interface Style Changes to fit the new iOS 13 dark mode, and I found a bug.

here's the minimum re-produce path.

view.backgroundColor = theDynamicColor0

// We set the corner radius first
// So, the clipping corner (layer) should be generated now.
someNode.backgroundColor = theDynamicColor0
someNode.cornerRadius = 10
someNode.cornerRoundingType = .clipping
someNode.frame = CGRect(x: 100, y: 100, width: 100, height: 100)

// Then, the trait collection changed
// And the node ignore it, because the node hasn't been loaded yet.
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
    self.overrideUserInterfaceStyle = .dark
    self.someNode.setPrimitiveTraitCollection(ASPrimitiveTraitCollectionFromUITraitCollection(self.traitCollection))
}

// And we add the node | view (maybe in tableNode)
// The node display the outdated corner.
DispatchQueue.main.asyncAfter(deadline: .now() + 6) {
    self.view.addSubview(self.someNode.view)
}

So when we set cornerRadius or maskedCorners when cornerRoundingType is ASCornerRoundingTypeClipping, the node will re-render the clipping layer in main thread immediately, and it will never synced with the backgroundColor changed. When the global traitCollection did change, the node's asyncTraitCollectionDidChangeWithPreviousTraitCollection callback will judge if node is loaded

if (primitiveTraitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle) {
    if (loaded) {
        ... // re-render the clipping layer
    }
}    

And if the node is not loaded yet (maybe in tableNode, but not in UI hierarchy), it will not change the layer's appearance, and when we display the node, the corner broke.

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

No branches or pull requests

1 participant