Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ @implementation RCTViewComponentView {
CALayer *_backgroundColorLayer;
__weak CALayer *_borderLayer;
CALayer *_outlineLayer;
CALayer *_boxShadowLayer;
NSMutableArray<CALayer *> *_boxShadowLayers;
CALayer *_filterLayer;
NSMutableArray<CALayer *> *_backgroundImageLayers;
BOOL _needsInvalidateLayer;
Expand Down Expand Up @@ -828,7 +828,7 @@ - (void)invalidateLayer
// If view has a solid background color, calculate shadow path from border.
const RCTCornerInsets cornerInsets =
RCTGetCornerInsets(RCTCornerRadiiFromBorderRadii(borderMetrics.borderRadii), UIEdgeInsetsZero);
CGPathRef shadowPath = RCTPathCreateWithRoundedRect(self.bounds, cornerInsets, nil);
CGPathRef shadowPath = RCTPathCreateWithRoundedRect(self.bounds, cornerInsets, nil, NO);
layer.shadowPath = shadowPath;
CGPathRelease(shadowPath);
} else {
Expand All @@ -852,9 +852,9 @@ - (void)invalidateLayer
// rendering incorrectly on iOS, iOS apps in compatibility mode on visionOS, but not on visionOS.
// To work around this, for iOS, we can calculate the border path based on `view.frame` (the
// superview's coordinate space) instead of view.bounds.
CGPathRef borderPath = RCTPathCreateWithRoundedRect(self.frame, cornerInsets, NULL);
CGPathRef borderPath = RCTPathCreateWithRoundedRect(self.frame, cornerInsets, NULL, NO);
#else // TARGET_OS_VISION
CGPathRef borderPath = RCTPathCreateWithRoundedRect(self.bounds, cornerInsets, NULL);
CGPathRef borderPath = RCTPathCreateWithRoundedRect(self.bounds, cornerInsets, NULL, NO);
#endif
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithCGPath:borderPath];
CGPathRelease(borderPath);
Expand Down Expand Up @@ -1016,21 +1016,24 @@ - (void)invalidateLayer
}

// box shadow
[_boxShadowLayer removeFromSuperlayer];
_boxShadowLayer = nil;
for (CALayer *boxShadowLayer in _boxShadowLayers) {
[boxShadowLayer removeFromSuperlayer];
}
[_boxShadowLayers removeAllObjects];
if (!_props->boxShadow.empty()) {
_boxShadowLayer = [CALayer layer];
[self.layer addSublayer:_boxShadowLayer];
_boxShadowLayer.zPosition = _borderLayer.zPosition;
_boxShadowLayer.frame = RCTGetBoundingRect(_props->boxShadow, self.layer.bounds.size);

UIImage *boxShadowImage = RCTGetBoxShadowImage(
_props->boxShadow,
RCTCornerRadiiFromBorderRadii(borderMetrics.borderRadii),
RCTUIEdgeInsetsFromEdgeInsets(borderMetrics.borderWidths),
self.layer.bounds.size);

_boxShadowLayer.contents = (id)boxShadowImage.CGImage;
if (!_boxShadowLayers) {
_boxShadowLayers = [NSMutableArray new];
}
for (auto it = _props->boxShadow.rbegin(); it != _props->boxShadow.rend(); ++it) {
CALayer *shadowLayer = RCTGetBoxShadowLayer(
*it,
RCTCornerRadiiFromBorderRadii(borderMetrics.borderRadii),
RCTUIEdgeInsetsFromEdgeInsets(borderMetrics.borderWidths),
self.layer.bounds.size);
shadowLayer.zPosition = _borderLayer.zPosition;
[self.layer addSublayer:shadowLayer];
[_boxShadowLayers addObject:shadowLayer];
}
}

// clipping
Expand Down Expand Up @@ -1095,7 +1098,7 @@ - (void)shapeLayerToMatchView:(CALayer *)layer borderMetrics:(BorderMetrics)bord

- (CAShapeLayer *)createMaskLayer:(CGRect)bounds cornerInsets:(RCTCornerInsets)cornerInsets
{
CGPathRef path = RCTPathCreateWithRoundedRect(bounds, cornerInsets, nil);
CGPathRef path = RCTPathCreateWithRoundedRect(bounds, cornerInsets, nil, NO);
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = path;
CGPathRelease(path);
Expand Down
6 changes: 2 additions & 4 deletions packages/react-native/React/Fabric/Utils/RCTBoxShadow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
#import <UIKit/UIKit.h>
#import <react/renderer/graphics/BoxShadow.h>

RCT_EXTERN UIImage *RCTGetBoxShadowImage(
const std::vector<facebook::react::BoxShadow> &shadows,
RCT_EXTERN CALayer *RCTGetBoxShadowLayer(
const facebook::react::BoxShadow &shadow,
RCTCornerRadii cornerRadii,
UIEdgeInsets edgeInsets,
CGSize layerSize);

RCT_EXTERN CGRect RCTGetBoundingRect(const std::vector<facebook::react::BoxShadow> &boxShadows, CGSize layerSize);
Loading
Loading