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 @@ -1191,7 +1191,10 @@ - (void)invalidateLayer
_outlineLayer.frame = CGRectInset(
layer.bounds, -_props->outlineOffset - _props->outlineWidth, -_props->outlineOffset - _props->outlineWidth);

if (areBorderRadiiCircular(borderMetrics.borderRadii) && borderMetrics.borderRadii.topLeft.horizontal == 0) {
// Core Animation can only draw solid contours, so dotted and dashed outlines
// have to be drawn with Core Graphics, the same way non-solid borders are.
if (_props->outlineStyle == OutlineStyle::Solid && areBorderRadiiCircular(borderMetrics.borderRadii) &&
borderMetrics.borderRadii.topLeft.horizontal == 0) {
UIColor *outlineColor = RCTUIColorFromSharedColor(_props->outlineColor);
_outlineLayer.borderWidth = _props->outlineWidth;
_outlineLayer.borderColor = outlineColor.CGColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <XCTest/XCTest.h>
#import <react/renderer/components/view/ViewProps.h>
#import <react/renderer/components/view/ViewShadowNode.h>
#import <react/renderer/graphics/Color.h>

using namespace facebook::react;

Expand Down Expand Up @@ -237,4 +238,47 @@ - (void)testViewWithoutRoleIsNotKeyboardFocusable
XCTAssertFalse(view.canBecomeFocused);
}

#pragma mark - outline style on square corners (#57841)

static RCTViewComponentView *makeViewWithOutlineStyle(OutlineStyle outlineStyle)
{
RCTViewComponentView *view = [RCTViewComponentView new];
view.frame = CGRectMake(0, 0, 100, 100);

auto props = std::make_shared<ViewProps>();
props->outlineWidth = 8;
props->outlineColor = colorFromRGBA(255, 165, 0, 255);
props->outlineStyle = outlineStyle;

[view updateProps:props oldProps:ViewShadowNode::defaultSharedProps()];
[view finalizeUpdates:RNComponentViewUpdateMaskProps];

return view;
}

- (void)testSquareSolidOutlineUsesCoreAnimationBorder
{
// Solid outlines keep the cheaper Core Animation path.
RCTViewComponentView *view = makeViewWithOutlineStyle(OutlineStyle::Solid);
CALayer *outlineLayer = [view valueForKey:@"_outlineLayer"];

XCTAssertNotNil(outlineLayer);
XCTAssertEqualWithAccuracy(outlineLayer.borderWidth, 8.0, 0.001);
XCTAssertNil(outlineLayer.contents);
}

- (void)testSquareDottedAndDashedOutlinesAreDrawnWithCoreGraphics
{
// A view without border radii used to take the Core Animation path, which can
// only render solid contours, so `outlineStyle` was silently dropped.
for (OutlineStyle outlineStyle : {OutlineStyle::Dotted, OutlineStyle::Dashed}) {
RCTViewComponentView *view = makeViewWithOutlineStyle(outlineStyle);
CALayer *outlineLayer = [view valueForKey:@"_outlineLayer"];

XCTAssertNotNil(outlineLayer);
XCTAssertEqualWithAccuracy(outlineLayer.borderWidth, 0.0, 0.001);
XCTAssertNotNil(outlineLayer.contents);
}
}

@end
57 changes: 57 additions & 0 deletions packages/rn-tester/js/examples/View/ViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,33 @@ function BoxShadowExample(): React.Node {
);
}

function OutlineStyleExample({
outlineStyle,
borderRadius,
label,
}: {
outlineStyle: 'solid' | 'dashed' | 'dotted',
borderRadius: number,
label: string,
}): React.Node {
return (
<View style={{alignItems: 'center', gap: 8}}>
<View
style={{
width: 50,
height: 50,
backgroundColor: 'lightgray',
borderRadius,
outlineWidth: 3,
outlineColor: 'purple',
outlineStyle,
}}
/>
<RNTesterText style={{fontSize: 11}}>{label}</RNTesterText>
</View>
);
}

function OutlineExample(): React.Node {
const defaultStyleSize = {width: 50, height: 50};

Expand Down Expand Up @@ -665,6 +692,36 @@ function OutlineExample(): React.Node {
},
]}
/>
<OutlineStyleExample
outlineStyle="solid"
borderRadius={0}
label="square solid"
/>
<OutlineStyleExample
outlineStyle="dashed"
borderRadius={0}
label="square dashed"
/>
<OutlineStyleExample
outlineStyle="dotted"
borderRadius={0}
label="square dotted"
/>
<OutlineStyleExample
outlineStyle="solid"
borderRadius={12}
label="rounded solid"
/>
<OutlineStyleExample
outlineStyle="dashed"
borderRadius={12}
label="rounded dashed"
/>
<OutlineStyleExample
outlineStyle="dotted"
borderRadius={12}
label="rounded dotted"
/>
</View>
);
}
Expand Down
Loading