1212
1313using namespace facebook ::react;
1414
15- float computeMargin (const facebook::yoga::Style &yogaStyle, facebook::yoga::Edge edge) {
16- auto value = yogaStyle.margin (edge).value ();
17- if (value.isDefined ()) {
18- return value.unwrap ();
19- }
20-
21- auto isHorizontal = edge == facebook::yoga::Edge::Left || edge == facebook::yoga::Edge::Right;
22- value = yogaStyle.margin (isHorizontal ? facebook::yoga::Edge::Horizontal : facebook::yoga::Edge::Vertical).value ();
23- if (value.isDefined ()) {
24- return value.unwrap ();
25- }
26-
27- return yogaStyle.margin (facebook::yoga::Edge::All).value ().unwrapOrDefault (0 .0f );
28- }
29-
3015@implementation RCTClipPathUtils
3116
3217+ (RCTCornerRadii)adjustCornerRadiiForGeometryBox : (GeometryBox)geometryBox
3318 cornerRadii : (RCTCornerRadii)cornerRadii
3419 layoutMetrics : (const LayoutMetrics &)layoutMetrics
3520 yogaStyle : (const facebook::yoga::Style &)yogaStyle
36- {
37- auto marginLeft = computeMargin (yogaStyle, facebook::yoga::Edge::Left);
38- auto marginRight = computeMargin (yogaStyle, facebook::yoga::Edge::Right);
39- auto marginTop = computeMargin (yogaStyle, facebook::yoga::Edge::Top);
40- auto marginBottom = computeMargin (yogaStyle, facebook::yoga::Edge::Bottom);
41-
21+ {
4222 RCTCornerRadii adjustedRadii = cornerRadii;
4323
4424 switch (geometryBox) {
4525 case GeometryBox::MarginBox: {
46- // margin -box: extend border-radius by margin amount
47- adjustedRadii.topLeftHorizontal += marginLeft ;
48- adjustedRadii.topLeftVertical += marginTop ;
49- adjustedRadii.topRightHorizontal += marginRight ;
50- adjustedRadii.topRightVertical += marginTop ;
51- adjustedRadii.bottomLeftHorizontal += marginLeft ;
52- adjustedRadii.bottomLeftVertical += marginBottom ;
53- adjustedRadii.bottomRightHorizontal += marginRight ;
54- adjustedRadii.bottomRightVertical += marginBottom ;
26+ // Margin -box: extend border-radius by margin amount
27+ adjustedRadii.topLeftHorizontal += layoutMetrics. marginInsets . left ;
28+ adjustedRadii.topLeftVertical += layoutMetrics. marginInsets . top ;
29+ adjustedRadii.topRightHorizontal += layoutMetrics. marginInsets . right ;
30+ adjustedRadii.topRightVertical += layoutMetrics. marginInsets . top ;
31+ adjustedRadii.bottomLeftHorizontal += layoutMetrics. marginInsets . left ;
32+ adjustedRadii.bottomLeftVertical += layoutMetrics. marginInsets . bottom ;
33+ adjustedRadii.bottomRightHorizontal += layoutMetrics. marginInsets . right ;
34+ adjustedRadii.bottomRightVertical += layoutMetrics. marginInsets . bottom ;
5535 break ;
5636 }
5737 case GeometryBox::BorderBox:
5838 case GeometryBox::StrokeBox:
5939 case GeometryBox::ViewBox:
60- // border -box: use border-radius as-is (this is the reference)
40+ // Border -box: use border-radius as-is (this is the reference)
6141 break ;
6242
6343 case GeometryBox::PaddingBox: {
64- // padding-box: reduce border-radius by border width
65- // Formula: max(0, border-radius - border-width)
44+ // Padding-box: reduce border-radius by border width
6645 adjustedRadii.topLeftHorizontal = MAX (0 .0f , cornerRadii.topLeftHorizontal - layoutMetrics.borderWidth .left );
6746 adjustedRadii.topLeftVertical = MAX (0 .0f , cornerRadii.topLeftVertical - layoutMetrics.borderWidth .top );
6847 adjustedRadii.topRightHorizontal = MAX (0 .0f , cornerRadii.topRightHorizontal - layoutMetrics.borderWidth .right );
@@ -75,16 +54,15 @@ + (RCTCornerRadii)adjustCornerRadiiForGeometryBox:(GeometryBox)geometryBox
7554 }
7655 case GeometryBox::ContentBox:
7756 case GeometryBox::FillBox: {
78- // content-box: reduce border-radius by border width + padding
79- // contentInsets = border + padding, so we reduce by full contentInsets
80- adjustedRadii.topLeftHorizontal = MAX (0 .0f , cornerRadii.topLeftHorizontal - layoutMetrics.contentInsets .left );
81- adjustedRadii.topLeftVertical = MAX (0 .0f , cornerRadii.topLeftVertical - layoutMetrics.contentInsets .top );
82- adjustedRadii.topRightHorizontal = MAX (0 .0f , cornerRadii.topRightHorizontal - layoutMetrics.contentInsets .right );
83- adjustedRadii.topRightVertical = MAX (0 .0f , cornerRadii.topRightVertical - layoutMetrics.contentInsets .top );
84- adjustedRadii.bottomLeftHorizontal = MAX (0 .0f , cornerRadii.bottomLeftHorizontal - layoutMetrics.contentInsets .left );
85- adjustedRadii.bottomLeftVertical = MAX (0 .0f , cornerRadii.bottomLeftVertical - layoutMetrics.contentInsets .bottom );
86- adjustedRadii.bottomRightHorizontal = MAX (0 .0f , cornerRadii.bottomRightHorizontal - layoutMetrics.contentInsets .right );
87- adjustedRadii.bottomRightVertical = MAX (0 .0f , cornerRadii.bottomRightVertical - layoutMetrics.contentInsets .bottom );
57+ // Content-box: reduce border-radius by border width + padding
58+ adjustedRadii.topLeftHorizontal = MAX (0 .0f , cornerRadii.topLeftHorizontal - layoutMetrics.borderWidth .left - layoutMetrics.paddingInsets .left );
59+ adjustedRadii.topLeftVertical = MAX (0 .0f , cornerRadii.topLeftVertical - layoutMetrics.borderWidth .top - layoutMetrics.paddingInsets .top );
60+ adjustedRadii.topRightHorizontal = MAX (0 .0f , cornerRadii.topRightHorizontal - layoutMetrics.borderWidth .right - layoutMetrics.paddingInsets .right );
61+ adjustedRadii.topRightVertical = MAX (0 .0f , cornerRadii.topRightVertical - layoutMetrics.borderWidth .top - layoutMetrics.paddingInsets .top );
62+ adjustedRadii.bottomLeftHorizontal = MAX (0 .0f , cornerRadii.bottomLeftHorizontal - layoutMetrics.borderWidth .left - layoutMetrics.paddingInsets .left );
63+ adjustedRadii.bottomLeftVertical = MAX (0 .0f , cornerRadii.bottomLeftVertical - layoutMetrics.borderWidth .bottom - layoutMetrics.paddingInsets .bottom );
64+ adjustedRadii.bottomRightHorizontal = MAX (0 .0f , cornerRadii.bottomRightHorizontal - layoutMetrics.borderWidth .right - layoutMetrics.paddingInsets .right );
65+ adjustedRadii.bottomRightVertical = MAX (0 .0f , cornerRadii.bottomRightVertical - layoutMetrics.borderWidth .bottom - layoutMetrics.paddingInsets .bottom );
8866 break ;
8967 }
9068 }
@@ -97,11 +75,6 @@ + (CGRect)getGeometryBoxRect:(GeometryBox)geometryBox
9775 yogaStyle : (const facebook::yoga::Style &)yogaStyle
9876 bounds : (CGRect)bounds
9977{
100- auto marginLeft = computeMargin (yogaStyle, facebook::yoga::Edge::Left);
101- auto marginRight = computeMargin (yogaStyle, facebook::yoga::Edge::Right);
102- auto marginTop = computeMargin (yogaStyle, facebook::yoga::Edge::Top);
103- auto marginBottom = computeMargin (yogaStyle, facebook::yoga::Edge::Bottom);
104-
10578 switch (geometryBox) {
10679 case GeometryBox::ContentBox:
10780 case GeometryBox::FillBox:
@@ -114,10 +87,10 @@ + (CGRect)getGeometryBoxRect:(GeometryBox)geometryBox
11487 return bounds;
11588 case GeometryBox::MarginBox:
11689 return CGRectMake (
117- bounds.origin .x - marginLeft ,
118- bounds.origin .y - marginTop ,
119- bounds.size .width + marginLeft + marginRight ,
120- bounds.size .height + marginTop + marginBottom
90+ bounds.origin .x - layoutMetrics. marginInsets . left ,
91+ bounds.origin .y - layoutMetrics. marginInsets . top ,
92+ bounds.size .width + layoutMetrics. marginInsets . left + layoutMetrics. marginInsets . right ,
93+ bounds.size .height + layoutMetrics. marginInsets . top + layoutMetrics. marginInsets . bottom
12194 );
12295 }
12396
0 commit comments