-
Notifications
You must be signed in to change notification settings - Fork 24.2k
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
fix(iOS): displaying irregular borders on iOS Fabric #45973
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -662,7 +662,7 @@ - (void)invalidateLayer | |
borderMetrics.borderWidths.left == 0 || self.clipsToBounds || | ||
(colorComponentsFromColor(borderMetrics.borderColors.left).alpha == 0 && | ||
(*borderMetrics.borderColors.left).getUIColor() != nullptr)); | ||
|
||
CGColorRef backgroundColor = [_backgroundColor resolvedColorWithTraitCollection:self.traitCollection].CGColor; | ||
|
||
if (useCoreAnimationBorderRendering) { | ||
|
@@ -681,7 +681,7 @@ - (void)invalidateLayer | |
} else { | ||
if (!_borderLayer) { | ||
CALayer *borderLayer = [CALayer new]; | ||
borderLayer.zPosition = -1024.0f; | ||
borderLayer.zPosition = 1024.0f; | ||
borderLayer.frame = layer.bounds; | ||
borderLayer.magnificationFilter = kCAFilterNearest; | ||
[layer addSublayer:borderLayer]; | ||
|
@@ -694,14 +694,16 @@ - (void)invalidateLayer | |
layer.cornerRadius = 0; | ||
|
||
RCTBorderColors borderColors = RCTCreateRCTBorderColorsFromBorderColors(borderMetrics.borderColors); | ||
|
||
UIColor *transparentColor = [UIColor clearColor]; | ||
CGColorRef transparentBackgroundColor = [transparentColor resolvedColorWithTraitCollection:self.traitCollection].CGColor; | ||
|
||
UIImage *image = RCTGetBorderImage( | ||
RCTBorderStyleFromBorderStyle(borderMetrics.borderStyles.left), | ||
layer.bounds.size, | ||
RCTCornerRadiiFromBorderRadii(borderMetrics.borderRadii), | ||
RCTUIEdgeInsetsFromEdgeInsets(borderMetrics.borderWidths), | ||
borderColors, | ||
backgroundColor, | ||
transparentBackgroundColor, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feedback @joevilches on this line:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if we can get rid of the background here. If we set the background in the |
||
self.clipsToBounds); | ||
|
||
RCTReleaseRCTBorderColors(borderColors); | ||
|
@@ -714,7 +716,7 @@ - (void)invalidateLayer | |
CGRect contentsCenter = CGRect{ | ||
CGPoint{imageCapInsets.left / imageSize.width, imageCapInsets.top / imageSize.height}, | ||
CGSize{(CGFloat)1.0 / imageSize.width, (CGFloat)1.0 / imageSize.height}}; | ||
|
||
_borderLayer.contents = (id)image.CGImage; | ||
_borderLayer.contentsScale = image.scale; | ||
|
||
|
@@ -751,6 +753,7 @@ - (void)invalidateLayer | |
} | ||
|
||
layer.cornerRadius = cornerRadius; | ||
layer.backgroundColor = backgroundColor; | ||
layer.mask = maskLayer; | ||
} | ||
|
||
|
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.
Hi, maybe you can check the code history, and it introduce borderLayer is because CSS draws the border behind the content :) .
https://github.com/facebook/react-native/pull/45973/files#diff-fce237eeca8733cbef40d994a0c0a154026be79e681b103b4afde567dd42330bL659-L661
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.
Yeah, css draws a border behind the component's children. In the provided solution, the border is still drawn behind the inner content of the element. I think that layer's
zPosition
applies only within a layer, so it shouldn't have an impact outside of that. The above problem looks like this after the changes on Fabric: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.
Emm,
zPosition
also affects theview
orlayer
for the same hierarchy, For example like below, setting border layer'szPosition
to 1024 can cover the content of SubView1 I think.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.
BTW, I'm trying to refactor the Text to support border, you can try #45972 and applied your code, you can see border is cover the text like below: :)
We hope to see this:
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.
Unfortunately, the iOS docs are not too descriptive about how the
zPosition
works 😕 I will try to think about other solution.