react-native-windows 0.75.8 → 0.75.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/Microsoft.ReactNative/CompositionComponentView.idl +2 -1
  2. package/Microsoft.ReactNative/Fabric/AbiComponentDescriptor.cpp +4 -1
  3. package/Microsoft.ReactNative/Fabric/AbiViewComponentDescriptor.cpp +1 -1
  4. package/Microsoft.ReactNative/Fabric/AbiViewProps.cpp +7 -0
  5. package/Microsoft.ReactNative/Fabric/AbiViewProps.h +2 -0
  6. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +19 -4
  7. package/Microsoft.ReactNative/Fabric/ComponentView.h +8 -3
  8. package/Microsoft.ReactNative/Fabric/Composition/BorderPrimitive.cpp +931 -0
  9. package/Microsoft.ReactNative/Fabric/Composition/BorderPrimitive.h +80 -0
  10. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +31 -13
  11. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +27 -3
  12. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +3 -1
  13. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp +8 -32
  14. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +302 -895
  15. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +26 -26
  16. package/Microsoft.ReactNative/Fabric/Composition/DebuggingOverlayComponentView.cpp +1 -1
  17. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +130 -122
  18. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.h +14 -8
  19. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.cpp +34 -20
  20. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +5 -3
  21. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +63 -2
  22. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +12 -0
  23. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +51 -3
  24. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +3 -0
  25. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +18 -8
  26. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h +3 -0
  27. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +46 -4
  28. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +5 -0
  29. package/Microsoft.ReactNative/Fabric/Composition/Theme.cpp +9 -3
  30. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +11 -0
  31. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +2 -0
  32. package/Microsoft.ReactNative/Fabric/Composition/UnimplementedNativeViewComponentView.cpp +1 -1
  33. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +1 -0
  34. package/Microsoft.ReactNative/IReactViewComponentBuilder.idl +1 -1
  35. package/Microsoft.ReactNative/ReactNativeAppBuilder.cpp +25 -129
  36. package/Microsoft.ReactNative/ReactNativeAppBuilder.h +5 -13
  37. package/Microsoft.ReactNative/ReactNativeAppBuilder.idl +13 -34
  38. package/Microsoft.ReactNative/ReactNativeIsland.idl +3 -2
  39. package/Microsoft.ReactNative/ReactNativeWin32App.cpp +129 -18
  40. package/Microsoft.ReactNative/ReactNativeWin32App.h +14 -5
  41. package/Microsoft.ReactNative/ViewProps.idl +2 -0
  42. package/Microsoft.ReactNative.Cxx/ComponentView.Experimental.interop.h +14 -0
  43. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  44. package/Shared/Shared.vcxitems +3 -10
  45. package/Shared/Shared.vcxitems.filters +1 -0
  46. package/package.json +4 -4
  47. package/templates/cpp-app/windows/MyApp/MyApp.cpp +46 -130
  48. package/Microsoft.ReactNative/ReactInstanceSettingsBuilder.cpp +0 -59
  49. package/Microsoft.ReactNative/ReactInstanceSettingsBuilder.h +0 -23
@@ -0,0 +1,931 @@
1
+
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ #include "BorderPrimitive.h"
6
+
7
+ #include <AutoDraw.h>
8
+ #include "CompositionViewComponentView.h"
9
+
10
+ namespace winrt::Microsoft::ReactNative::Composition::implementation {
11
+
12
+ // Ideally isColorMeaningful would be sufficient here. But it appears to detect platformColors as not meaningful
13
+ // https://github.com/microsoft/react-native-windows/issues/14006
14
+ bool isColorMeaningful(
15
+ const facebook::react::SharedColor &color,
16
+ winrt::Microsoft::ReactNative::Composition::implementation::Theme *theme) noexcept {
17
+ if (!color) {
18
+ return false;
19
+ }
20
+
21
+ return theme->Color(*color).A > 0;
22
+ }
23
+
24
+ // We don't want half pixel borders, or border radii - they lead to blurry borders
25
+ // Also apply scale factor to the radii at this point
26
+ void pixelRoundBorderRadii(facebook::react::BorderRadii &borderRadii, float scaleFactor) noexcept {
27
+ // Always round radii down to avoid spikey circles
28
+ borderRadii.topLeft = std::floor(borderRadii.topLeft * scaleFactor);
29
+ borderRadii.topRight = std::floor(borderRadii.topRight * scaleFactor);
30
+ borderRadii.bottomLeft = std::floor(borderRadii.bottomLeft * scaleFactor);
31
+ borderRadii.bottomRight = std::floor(borderRadii.bottomRight * scaleFactor);
32
+ }
33
+
34
+ void scaleAndPixelRoundBorderWidths(
35
+ facebook::react::LayoutMetrics const &layoutMetrics,
36
+ facebook::react::BorderMetrics &borderMetrics,
37
+ float scaleFactor) noexcept {
38
+ borderMetrics.borderWidths.left = (borderMetrics.borderWidths.left == 0)
39
+ ? 0.f
40
+ : std::max(1.f, std::round(borderMetrics.borderWidths.left * scaleFactor));
41
+ borderMetrics.borderWidths.top = (borderMetrics.borderWidths.top == 0)
42
+ ? 0.f
43
+ : std::max(1.f, std::round(borderMetrics.borderWidths.top * scaleFactor));
44
+ borderMetrics.borderWidths.right = (borderMetrics.borderWidths.right == 0)
45
+ ? 0.f
46
+ : std::max(1.f, std::round(borderMetrics.borderWidths.right * scaleFactor));
47
+ borderMetrics.borderWidths.bottom = (borderMetrics.borderWidths.bottom == 0)
48
+ ? 0.f
49
+ : std::max(1.f, std::round(borderMetrics.borderWidths.bottom * scaleFactor));
50
+
51
+ // If we rounded both sides of the borderWidths up, we may have made the borderWidths larger than the total
52
+ if (layoutMetrics.frame.size.width * scaleFactor <
53
+ (borderMetrics.borderWidths.left + borderMetrics.borderWidths.right)) {
54
+ borderMetrics.borderWidths.right--;
55
+ }
56
+ if (layoutMetrics.frame.size.height * scaleFactor <
57
+ (borderMetrics.borderWidths.top + borderMetrics.borderWidths.bottom)) {
58
+ borderMetrics.borderWidths.bottom--;
59
+ }
60
+ }
61
+
62
+ // react-native uses black as a default color when none is specified.
63
+ void assignDefaultBlackBorders(facebook::react::BorderMetrics &borderMetrics) noexcept {
64
+ if (!borderMetrics.borderColors.left) {
65
+ borderMetrics.borderColors.left = facebook::react::blackColor();
66
+ }
67
+ if (!borderMetrics.borderColors.top) {
68
+ borderMetrics.borderColors.top = facebook::react::blackColor();
69
+ }
70
+ if (!borderMetrics.borderColors.right) {
71
+ borderMetrics.borderColors.right = facebook::react::blackColor();
72
+ }
73
+ if (!borderMetrics.borderColors.bottom) {
74
+ borderMetrics.borderColors.bottom = facebook::react::blackColor();
75
+ }
76
+ }
77
+
78
+ facebook::react::BorderMetrics BorderPrimitive::resolveAndAlignBorderMetrics(
79
+ facebook::react::LayoutMetrics const &layoutMetrics,
80
+ const facebook::react::ViewProps &viewProps) noexcept {
81
+ auto borderMetrics = viewProps.resolveBorderMetrics(layoutMetrics);
82
+
83
+ pixelRoundBorderRadii(borderMetrics.borderRadii, layoutMetrics.pointScaleFactor);
84
+ scaleAndPixelRoundBorderWidths(layoutMetrics, borderMetrics, layoutMetrics.pointScaleFactor);
85
+ assignDefaultBlackBorders(borderMetrics);
86
+ return borderMetrics;
87
+ }
88
+
89
+ struct RoundedPathParameters {
90
+ float topLeftRadiusX = 0;
91
+ float topLeftRadiusY = 0;
92
+ float topRightRadiusX = 0;
93
+ float topRightRadiusY = 0;
94
+ float bottomRightRadiusX = 0;
95
+ float bottomRightRadiusY = 0;
96
+ float bottomLeftRadiusX = 0;
97
+ float bottomLeftRadiusY = 0;
98
+ };
99
+
100
+ /*
101
+ * Creates and returns a PathGeometry object used to clip the visuals of an element when a BorderRadius is set.
102
+ * Can also be used as part of a GeometryGroup for drawing a rounded border / innerstroke when called from
103
+ * GetGeometryForRoundedBorder. "params" defines the radii (horizontal and vertical) for each corner (top left, top
104
+ * right, bottom right, bottom left). "rectPathGeometry" defines the bounding box of the generated shape.
105
+ */
106
+ static winrt::com_ptr<ID2D1PathGeometry> GenerateRoundedRectPathGeometry(
107
+ winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
108
+ const RoundedPathParameters &params,
109
+ const facebook::react::RectangleEdges<float> &rectPathGeometry) noexcept {
110
+ winrt::com_ptr<ID2D1PathGeometry> pathGeometry;
111
+ winrt::com_ptr<ID2D1Factory1> spD2dFactory;
112
+ compContext.as<::Microsoft::ReactNative::Composition::Experimental::ICompositionContextInterop>()->D2DFactory(
113
+ spD2dFactory.put());
114
+
115
+ // Create a path geometry.
116
+ HRESULT hr = spD2dFactory->CreatePathGeometry(pathGeometry.put());
117
+ if (FAILED(hr)) {
118
+ assert(false);
119
+ return nullptr;
120
+ }
121
+
122
+ // Write to the path geometry using the geometry sink.
123
+ winrt::com_ptr<ID2D1GeometrySink> spSink = nullptr;
124
+ hr = pathGeometry->Open(spSink.put());
125
+
126
+ if (FAILED(hr)) {
127
+ assert(false);
128
+ return nullptr;
129
+ }
130
+
131
+ float left = rectPathGeometry.left;
132
+ float right = rectPathGeometry.right;
133
+ float top = rectPathGeometry.top;
134
+ float bottom = rectPathGeometry.bottom;
135
+
136
+ // This function uses Cubic Beziers to approximate Arc segments, even though D2D supports arcs.
137
+ // This is INTENTIONAL. D2D Arc Segments are eventually converted into cubic beziers, but this
138
+ // is done in such a way that we don't have control over how many bezier curve segments are used
139
+ // for each arc. We need to ensure that we always use the same number of control points so that
140
+ // our paths can be used in a PathKeyFrameAnimation.
141
+ // Value for control point scale factor derived from methods described in:
142
+ // https://web.archive.org/web/20200322075504/http://itc.ktu.lt/index.php/ITC/article/download/11812/6479
143
+ constexpr float controlPointScaleFactor = 0.44771528244f; // 1 - (4 * (sqrtf(2.0f) - 1) / 3.0f);
144
+
145
+ #ifdef DEBUG
146
+ // std::sqrtf is not constexpr, so we precalculated this and wrote it in a constexpr form above.
147
+ // On debug, we should still check that the values are equivalent, though.
148
+ static float calculatedScaleFactor = 1 - (4 * (sqrtf(2.0f) - 1) / 3.0f);
149
+ assert(controlPointScaleFactor == calculatedScaleFactor);
150
+ #endif // DEBUG
151
+
152
+ bool needsConsistentNumberOfControlPoints = true; // VisualVersion::IsUseWinCompClippingRegionEnabled();
153
+
154
+ if (needsConsistentNumberOfControlPoints || (params.topLeftRadiusX != 0.0 && params.topLeftRadiusY != 0.0)) {
155
+ spSink->BeginFigure(D2D1::Point2F(left + params.topLeftRadiusX, top), D2D1_FIGURE_BEGIN_FILLED);
156
+ } else {
157
+ spSink->BeginFigure(D2D1::Point2F(left, top), D2D1_FIGURE_BEGIN_FILLED);
158
+ }
159
+
160
+ // Move to the top right corner
161
+ spSink->AddLine(D2D1::Point2F(right - params.topRightRadiusX, top));
162
+ if (needsConsistentNumberOfControlPoints) {
163
+ D2D1_BEZIER_SEGMENT arcSegmentTopRight = {
164
+ D2D1::Point2F(right - controlPointScaleFactor * params.topRightRadiusX, top),
165
+ D2D1::Point2F(right, top + controlPointScaleFactor * params.topRightRadiusY),
166
+ D2D1::Point2F(right, top + params.topRightRadiusY)};
167
+
168
+ spSink->AddBezier(&arcSegmentTopRight);
169
+ } else if (params.topRightRadiusX != 0.0 && params.topRightRadiusY != 0.0) {
170
+ D2D1_ARC_SEGMENT arcSegmentTopRight = {
171
+ D2D1::Point2F(right, top + params.topRightRadiusY),
172
+ D2D1::SizeF(params.topRightRadiusX, params.topRightRadiusY),
173
+ 0.0f,
174
+ D2D1_SWEEP_DIRECTION_CLOCKWISE,
175
+ D2D1_ARC_SIZE_SMALL};
176
+
177
+ spSink->AddArc(&arcSegmentTopRight);
178
+ } else {
179
+ spSink->AddLine(D2D1::Point2F(right, top));
180
+ }
181
+
182
+ // Move to the bottom right corner
183
+ spSink->AddLine(D2D1::Point2F(right, bottom - params.bottomRightRadiusY));
184
+ if (needsConsistentNumberOfControlPoints) {
185
+ D2D1_BEZIER_SEGMENT arcSegmentBottomRight = {
186
+ D2D1::Point2F(right, bottom - controlPointScaleFactor * params.bottomRightRadiusY),
187
+ D2D1::Point2F(right - controlPointScaleFactor * params.bottomRightRadiusX, bottom),
188
+ D2D1::Point2F(right - params.bottomRightRadiusX, bottom)};
189
+
190
+ spSink->AddBezier(&arcSegmentBottomRight);
191
+ } else if (params.bottomRightRadiusX != 0.0 && params.bottomRightRadiusY != 0.0) {
192
+ D2D1_ARC_SEGMENT arcSegmentBottomRight = {
193
+ D2D1::Point2F(right - params.bottomRightRadiusX, bottom),
194
+ D2D1::SizeF(params.bottomRightRadiusX, params.bottomRightRadiusY),
195
+ 0.0f,
196
+ D2D1_SWEEP_DIRECTION_CLOCKWISE,
197
+ D2D1_ARC_SIZE_SMALL};
198
+
199
+ spSink->AddArc(&arcSegmentBottomRight);
200
+ } else {
201
+ spSink->AddLine(D2D1::Point2F(right, bottom));
202
+ }
203
+
204
+ // Move to the bottom left corner
205
+ spSink->AddLine(D2D1::Point2F(left + params.bottomLeftRadiusX, bottom));
206
+ if (needsConsistentNumberOfControlPoints) {
207
+ D2D1_BEZIER_SEGMENT arcSegmentBottomLeft = {
208
+ D2D1::Point2F(left + controlPointScaleFactor * params.bottomLeftRadiusX, bottom),
209
+ D2D1::Point2F(left, bottom - controlPointScaleFactor * params.bottomLeftRadiusY),
210
+ D2D1::Point2F(left, bottom - params.bottomLeftRadiusY)};
211
+
212
+ spSink->AddBezier(&arcSegmentBottomLeft);
213
+ } else if (params.bottomLeftRadiusX != 0.0 && params.bottomLeftRadiusY != 0.0) {
214
+ D2D1_ARC_SEGMENT arcSegmentBottomLeft = {
215
+ D2D1::Point2F(left, bottom - params.bottomLeftRadiusY),
216
+ D2D1::SizeF(params.bottomLeftRadiusX, params.bottomLeftRadiusY),
217
+ 0.0f,
218
+ D2D1_SWEEP_DIRECTION_CLOCKWISE,
219
+ D2D1_ARC_SIZE_SMALL};
220
+
221
+ spSink->AddArc(&arcSegmentBottomLeft);
222
+ } else {
223
+ spSink->AddLine(D2D1::Point2F(left, bottom));
224
+ }
225
+
226
+ // Move to the top left corner
227
+ spSink->AddLine(D2D1::Point2F(left, top + params.topLeftRadiusY));
228
+ if (needsConsistentNumberOfControlPoints) {
229
+ D2D1_BEZIER_SEGMENT arcSegmentTopLeft = {
230
+ D2D1::Point2F(left, top + controlPointScaleFactor * params.topLeftRadiusY),
231
+ D2D1::Point2F(left + controlPointScaleFactor * params.topLeftRadiusX, top),
232
+ D2D1::Point2F(left + params.topLeftRadiusX, top)};
233
+
234
+ spSink->AddBezier(&arcSegmentTopLeft);
235
+ } else if (params.topLeftRadiusX != 0.0 && params.topLeftRadiusY != 0.0) {
236
+ D2D1_ARC_SEGMENT arcSegmentTopLeft = {
237
+ D2D1::Point2F(left + params.topLeftRadiusX, top),
238
+ D2D1::SizeF(params.topLeftRadiusX, params.topLeftRadiusY),
239
+ 0.0f,
240
+ D2D1_SWEEP_DIRECTION_CLOCKWISE,
241
+ D2D1_ARC_SIZE_SMALL};
242
+
243
+ spSink->AddArc(&arcSegmentTopLeft);
244
+ } else {
245
+ spSink->AddLine(D2D1::Point2F(left, top));
246
+ }
247
+
248
+ spSink->EndFigure(D2D1_FIGURE_END_CLOSED);
249
+ spSink->Close();
250
+
251
+ return pathGeometry;
252
+ }
253
+
254
+ RoundedPathParameters GenerateRoundedPathParameters(
255
+ const facebook::react::RectangleCorners<float> &baseRadius,
256
+ const facebook::react::RectangleEdges<float> &inset,
257
+ const facebook::react::Size &pathSize) noexcept {
258
+ RoundedPathParameters result;
259
+
260
+ if (pathSize.width == 0 || pathSize.height == 0) {
261
+ return result;
262
+ }
263
+
264
+ float totalTopRadius = baseRadius.topLeft + baseRadius.topRight;
265
+ float totalRightRadius = baseRadius.topRight + baseRadius.bottomRight;
266
+ float totalBottomRadius = baseRadius.bottomRight + baseRadius.bottomLeft;
267
+ float totalLeftRadius = baseRadius.bottomLeft + baseRadius.topLeft;
268
+
269
+ float maxHorizontalRadius = std::max(totalTopRadius, totalBottomRadius);
270
+ float maxVerticalRadius = std::max(totalLeftRadius, totalRightRadius);
271
+
272
+ double totalWidth = inset.left + inset.right + pathSize.width;
273
+ double totalHeight = inset.top + inset.bottom + pathSize.height;
274
+
275
+ float scaleHoriz = static_cast<float>(maxHorizontalRadius / totalWidth);
276
+ float scaleVert = static_cast<float>(maxVerticalRadius / totalHeight);
277
+
278
+ float maxScale = std::max(1.0f, std::max(scaleHoriz, scaleVert));
279
+
280
+ result.topLeftRadiusX = std::max(0.0f, baseRadius.topLeft / maxScale - inset.left);
281
+ result.topLeftRadiusY = std::max(0.0f, baseRadius.topLeft / maxScale - inset.top);
282
+ result.topRightRadiusX = std::max(0.0f, baseRadius.topRight / maxScale - inset.right);
283
+ result.topRightRadiusY = std::max(0.0f, baseRadius.topRight / maxScale - inset.top);
284
+ result.bottomRightRadiusX = std::max(0.0f, baseRadius.bottomRight / maxScale - inset.right);
285
+ result.bottomRightRadiusY = std::max(0.0f, baseRadius.bottomRight / maxScale - inset.bottom);
286
+ result.bottomLeftRadiusX = std::max(0.0f, baseRadius.bottomLeft / maxScale - inset.left);
287
+ result.bottomLeftRadiusY = std::max(0.0f, baseRadius.bottomLeft / maxScale - inset.bottom);
288
+
289
+ return result;
290
+ }
291
+
292
+ winrt::com_ptr<ID2D1PathGeometry> BorderPrimitive::GenerateRoundedRectPathGeometry(
293
+ winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
294
+ const facebook::react::RectangleCorners<float> &baseRadius,
295
+ const facebook::react::RectangleEdges<float> &inset,
296
+ const facebook::react::RectangleEdges<float> &rectPathGeometry) noexcept {
297
+ RoundedPathParameters params = GenerateRoundedPathParameters(
298
+ baseRadius,
299
+ inset,
300
+ {rectPathGeometry.right - rectPathGeometry.left, rectPathGeometry.bottom - rectPathGeometry.top});
301
+
302
+ return winrt::Microsoft::ReactNative::Composition::implementation::GenerateRoundedRectPathGeometry(
303
+ compContext, params, rectPathGeometry);
304
+ }
305
+
306
+ void DrawShape(
307
+ ID2D1RenderTarget *pRT,
308
+ const D2D1_RECT_F &rect,
309
+ ID2D1Brush *brush,
310
+ FLOAT strokeWidth,
311
+ ID2D1StrokeStyle *strokeStyle) {
312
+ pRT->DrawRectangle(rect, brush, strokeWidth, strokeStyle);
313
+ }
314
+
315
+ void DrawShape(ID2D1RenderTarget *pRT, ID2D1GeometryGroup &geometry, ID2D1Brush *brush, FLOAT, ID2D1StrokeStyle *) {
316
+ pRT->FillGeometry(&geometry, brush);
317
+ }
318
+
319
+ void DrawShape(
320
+ ID2D1RenderTarget *pRT,
321
+ ID2D1PathGeometry &geometry,
322
+ ID2D1Brush *brush,
323
+ FLOAT strokeWidth,
324
+ ID2D1StrokeStyle *strokeStyle) {
325
+ pRT->DrawGeometry(&geometry, brush, strokeWidth, strokeStyle);
326
+ }
327
+
328
+ template <typename TShape>
329
+ void SetBorderLayerPropertiesCommon(
330
+ winrt::Microsoft::ReactNative::Composition::implementation::Theme *theme,
331
+ winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
332
+ winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual &layer,
333
+ TShape &shape,
334
+ winrt::com_ptr<::Microsoft::ReactNative::Composition::Experimental::ICompositionDrawingSurfaceInterop>
335
+ &borderTexture,
336
+ const D2D1_RECT_F &textureRect,
337
+ facebook::react::Point anchorPoint,
338
+ facebook::react::Point anchorOffset,
339
+ winrt::Windows::Foundation::Numerics::float2 size,
340
+ winrt::Windows::Foundation::Numerics::float2 relativeSizeAdjustment,
341
+ FLOAT strokeWidth,
342
+ const facebook::react::SharedColor &borderColor,
343
+ facebook::react::BorderStyle borderStyle) {
344
+ layer.Offset({anchorOffset.x, anchorOffset.y, 0}, {anchorPoint.x, anchorPoint.y, 0});
345
+ layer.RelativeSizeWithOffset(size, relativeSizeAdjustment);
346
+ layer.as<::Microsoft::ReactNative::Composition::Experimental::IVisualInterop>()->SetClippingPath(nullptr);
347
+
348
+ if ((textureRect.right - textureRect.left) <= 0 || (textureRect.bottom - textureRect.top) <= 0)
349
+ return;
350
+
351
+ auto surface = compContext.CreateDrawingSurfaceBrush(
352
+ {(textureRect.right - textureRect.left), (textureRect.bottom - textureRect.top)},
353
+ winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized,
354
+ winrt::Windows::Graphics::DirectX::DirectXAlphaMode::Premultiplied);
355
+ surface.as(borderTexture);
356
+
357
+ layer.Brush(surface);
358
+
359
+ POINT offset;
360
+ ::Microsoft::ReactNative::Composition::AutoDrawDrawingSurface autoDraw(
361
+ surface, 1.0f /* We have already done the dpi scaling */, &offset);
362
+ if (auto pRT = autoDraw.GetRenderTarget()) {
363
+ // Clear with transparency
364
+ pRT->Clear();
365
+
366
+ if (!isColorMeaningful(borderColor, theme)) {
367
+ return;
368
+ }
369
+
370
+ winrt::com_ptr<ID2D1Factory> spFactory;
371
+ pRT->GetFactory(spFactory.put());
372
+ assert(spFactory);
373
+ if (spFactory == nullptr)
374
+ return;
375
+
376
+ winrt::com_ptr<ID2D1SolidColorBrush> spBorderBrush;
377
+ pRT->CreateSolidColorBrush(theme->D2DColor(*borderColor), spBorderBrush.put());
378
+ assert(spBorderBrush);
379
+ if (spBorderBrush == nullptr)
380
+ return;
381
+
382
+ winrt::com_ptr<ID2D1StrokeStyle> spStrokeStyle;
383
+
384
+ enum class BorderStyle { Solid, Dotted, Dashed };
385
+
386
+ if (borderStyle == facebook::react::BorderStyle::Dotted || borderStyle == facebook::react::BorderStyle::Dashed) {
387
+ const auto capStyle =
388
+ borderStyle == facebook::react::BorderStyle::Dashed ? D2D1_CAP_STYLE_FLAT : D2D1_CAP_STYLE_ROUND;
389
+ const auto strokeStyleProps = D2D1::StrokeStyleProperties(
390
+ capStyle,
391
+ capStyle,
392
+ capStyle,
393
+ D2D1_LINE_JOIN_MITER,
394
+ 10.0f,
395
+ borderStyle == facebook::react::BorderStyle::Dashed ? D2D1_DASH_STYLE_DASH : D2D1_DASH_STYLE_DOT,
396
+ 0.0f);
397
+ spFactory->CreateStrokeStyle(&strokeStyleProps, nullptr, 0, spStrokeStyle.put());
398
+ }
399
+ D2D1::Matrix3x2F originalTransform;
400
+ D2D1::Matrix3x2F translationTransform =
401
+ D2D1::Matrix3x2F::Translation(-textureRect.left + offset.x, -textureRect.top + offset.y);
402
+
403
+ pRT->GetTransform(&originalTransform);
404
+ translationTransform = originalTransform * translationTransform;
405
+
406
+ pRT->SetTransform(translationTransform);
407
+
408
+ DrawShape(pRT, shape, spBorderBrush.get(), strokeWidth, spStrokeStyle.get());
409
+
410
+ pRT->SetTransform(originalTransform);
411
+ }
412
+ }
413
+
414
+ template <typename TShape>
415
+ void SetBorderLayerProperties(
416
+ winrt::Microsoft::ReactNative::Composition::implementation::Theme *theme,
417
+ winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
418
+ winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual &layer,
419
+ TShape &shape,
420
+ winrt::com_ptr<::Microsoft::ReactNative::Composition::Experimental::ICompositionDrawingSurfaceInterop>
421
+ &borderTexture,
422
+ const D2D1_RECT_F &textureRect,
423
+ facebook::react::Point anchorPoint,
424
+ facebook::react::Point anchorOffset,
425
+ winrt::Windows::Foundation::Numerics::float2 size,
426
+ winrt::Windows::Foundation::Numerics::float2 relativeSizeAdjustment,
427
+ FLOAT strokeWidth,
428
+ const facebook::react::SharedColor &borderColor,
429
+ facebook::react::BorderStyle borderStyle) {
430
+ if constexpr (!std::is_base_of_v<ID2D1GeometryGroup, TShape>) {
431
+ SetBorderLayerPropertiesCommon(
432
+ theme,
433
+ compContext,
434
+ layer,
435
+ shape,
436
+ borderTexture,
437
+ textureRect,
438
+ anchorPoint,
439
+ anchorOffset,
440
+ size,
441
+ relativeSizeAdjustment,
442
+ strokeWidth,
443
+ borderColor,
444
+ borderStyle);
445
+ } else {
446
+ // if (VisualVersion::IsUseWinCompClippingRegionEnabled())
447
+ {
448
+ layer.Offset({anchorOffset.x, anchorOffset.y, 0}, {anchorPoint.x, anchorPoint.y, 0});
449
+ layer.RelativeSizeWithOffset(
450
+ {textureRect.right - textureRect.left, textureRect.bottom - textureRect.top}, {0.0f, 0.0f});
451
+
452
+ layer.Brush(theme->Brush(*borderColor));
453
+
454
+ winrt::com_ptr<ID2D1Factory1> spD2dFactory;
455
+ compContext.as<::Microsoft::ReactNative::Composition::Experimental::ICompositionContextInterop>()->D2DFactory(
456
+ spD2dFactory.put());
457
+
458
+ winrt::com_ptr<ID2D1TransformedGeometry> transformedShape;
459
+ D2D1::Matrix3x2F translationTransform = D2D1::Matrix3x2F::Translation(-textureRect.left, -textureRect.top);
460
+ winrt::check_hresult(
461
+ spD2dFactory->CreateTransformedGeometry(&shape, &translationTransform, transformedShape.put()));
462
+
463
+ layer.as<::Microsoft::ReactNative::Composition::Experimental::IVisualInterop>()->SetClippingPath(
464
+ transformedShape.get());
465
+ }
466
+ /*
467
+ else
468
+ {
469
+ SetBorderLayerPropertiesCommon(theme, comContext, layer, shape, borderTexture, textureRect,
470
+ anchorPoint, anchorOffset, strokeWidth, borderColor, borderStyle);
471
+ }
472
+ */
473
+ }
474
+ }
475
+
476
+ namespace AnchorPosition {
477
+ const float Left = 0.0;
478
+ const float Center = 0.5;
479
+ const float Right = 1.0;
480
+ const float Top = 0.0;
481
+ const float Bottom = 1.0;
482
+ } // namespace AnchorPosition
483
+
484
+ template <typename TShape>
485
+ void DrawAllBorderLayers(
486
+ winrt::Microsoft::ReactNative::Composition::implementation::Theme *theme,
487
+ winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
488
+ std::array<
489
+ winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual,
490
+ BorderPrimitive::SpecialBorderLayerCount> &spBorderLayers,
491
+ TShape &shape,
492
+ const facebook::react::BorderWidths &borderWidths,
493
+ const facebook::react::BorderRadii &borderRadii,
494
+ float textureWidth,
495
+ float textureHeight,
496
+ const facebook::react::BorderColors &borderColors,
497
+ facebook::react::BorderStyle borderStyle) {
498
+ // Now that we've drawn our nice border in one layer, split it into its component layers
499
+ winrt::com_ptr<::Microsoft::ReactNative::Composition::Experimental::ICompositionDrawingSurfaceInterop>
500
+ spTextures[BorderPrimitive::SpecialBorderLayerCount];
501
+
502
+ // Set component border properties
503
+ // Top Left Corner
504
+ SetBorderLayerProperties(
505
+ theme,
506
+ compContext,
507
+ spBorderLayers[0],
508
+ shape,
509
+ spTextures[0], // Target Layer, Source Texture, Target Texture
510
+ {0,
511
+ 0,
512
+ borderRadii.topLeft + borderWidths.left,
513
+ borderRadii.topLeft + borderWidths.top}, // Texture Left, Top, Width, Height
514
+ {AnchorPosition::Left, AnchorPosition::Top}, // Layer Anchor Point
515
+ {0, 0}, // Layer Anchor Offset
516
+ {borderRadii.topLeft + borderWidths.left, borderRadii.topLeft + borderWidths.top}, // size
517
+ {0.0f, 0.0f}, // relativeSize
518
+ std::max(borderWidths.left, borderWidths.top),
519
+ borderColors.left ? borderColors.left : borderColors.top,
520
+ borderStyle);
521
+
522
+ // Top Edge Border
523
+ SetBorderLayerProperties(
524
+ theme,
525
+ compContext,
526
+ spBorderLayers[1],
527
+ shape,
528
+ spTextures[1],
529
+ {borderRadii.topLeft + borderWidths.left,
530
+ 0,
531
+ textureWidth - (borderRadii.topRight + borderWidths.right),
532
+ borderWidths.top},
533
+ {AnchorPosition::Left, AnchorPosition::Top},
534
+ {borderRadii.topLeft + borderWidths.left, 0},
535
+ {-(borderRadii.topLeft + borderWidths.left + borderRadii.topRight + borderWidths.right),
536
+ borderWidths.top}, // size
537
+ {1.0f, 0.0f}, // relativeSize
538
+ borderWidths.top,
539
+ borderColors.top,
540
+ borderStyle);
541
+
542
+ // Top Right Corner Border
543
+ SetBorderLayerProperties(
544
+ theme,
545
+ compContext,
546
+ spBorderLayers[2],
547
+ shape,
548
+ spTextures[2],
549
+ {textureWidth - (borderRadii.topRight + borderWidths.right),
550
+ 0,
551
+ textureWidth,
552
+ borderRadii.topRight + borderWidths.top},
553
+ {AnchorPosition::Right, AnchorPosition::Top},
554
+ {-(borderRadii.topRight + borderWidths.right), 0},
555
+ {borderRadii.topRight + borderWidths.right, borderRadii.topRight + borderWidths.top},
556
+ {0.0f, 0.0f},
557
+ std::max(borderWidths.right, borderWidths.top),
558
+ borderColors.right ? borderColors.right : borderColors.top,
559
+ borderStyle);
560
+
561
+ // Right Edge Border
562
+ SetBorderLayerProperties(
563
+ theme,
564
+ compContext,
565
+ spBorderLayers[3],
566
+ shape,
567
+ spTextures[3],
568
+ {textureWidth - borderWidths.right,
569
+ borderWidths.top + borderRadii.topRight,
570
+ textureWidth,
571
+ textureHeight - (borderWidths.bottom + borderRadii.bottomRight)},
572
+ {AnchorPosition::Right, AnchorPosition::Top},
573
+ {-borderWidths.right, borderWidths.top + borderRadii.topRight},
574
+ {borderWidths.right,
575
+ -(borderWidths.top + borderRadii.topRight + borderWidths.bottom + borderRadii.bottomRight)}, // size
576
+ {0.0f, 1.0f},
577
+ borderWidths.right,
578
+ borderColors.right,
579
+ borderStyle);
580
+
581
+ // Bottom Right Corner Border
582
+ SetBorderLayerProperties(
583
+ theme,
584
+ compContext,
585
+ spBorderLayers[4],
586
+ shape,
587
+ spTextures[4],
588
+ {textureWidth - (borderWidths.right + borderRadii.bottomRight),
589
+ textureHeight - (borderWidths.bottom + borderRadii.bottomRight),
590
+ textureWidth,
591
+ textureHeight},
592
+ {AnchorPosition::Right, AnchorPosition::Bottom},
593
+ {-(borderWidths.right + borderRadii.bottomRight), -(borderWidths.bottom + borderRadii.bottomRight)},
594
+ {borderWidths.right + borderRadii.bottomRight, borderWidths.bottom + borderRadii.bottomRight},
595
+ {0, 0},
596
+ std::max(borderWidths.right, borderWidths.bottom),
597
+ borderColors.right ? borderColors.right : borderColors.bottom,
598
+ borderStyle);
599
+
600
+ // Bottom Edge Border
601
+ SetBorderLayerProperties(
602
+ theme,
603
+ compContext,
604
+ spBorderLayers[5],
605
+ shape,
606
+ spTextures[5],
607
+ {borderWidths.left + borderRadii.bottomLeft,
608
+ textureHeight - borderWidths.bottom,
609
+ textureWidth - (borderWidths.right + borderRadii.bottomRight),
610
+ textureHeight},
611
+ {AnchorPosition::Left, AnchorPosition::Bottom},
612
+ {borderWidths.left + borderRadii.bottomLeft, -borderWidths.bottom},
613
+ {-(borderWidths.right + borderRadii.bottomLeft + borderWidths.left + borderRadii.bottomRight),
614
+ borderWidths.bottom},
615
+ {1.0f, 0.0f},
616
+ borderWidths.bottom,
617
+ borderColors.bottom,
618
+ borderStyle);
619
+
620
+ // Bottom Left Corner Border
621
+ SetBorderLayerProperties(
622
+ theme,
623
+ compContext,
624
+ spBorderLayers[6],
625
+ shape,
626
+ spTextures[6],
627
+ {0,
628
+ textureHeight - (borderWidths.bottom + borderRadii.bottomLeft),
629
+ borderWidths.left + borderRadii.bottomLeft,
630
+ textureHeight},
631
+ {AnchorPosition::Left, AnchorPosition::Bottom},
632
+ {0, -(borderWidths.bottom + borderRadii.bottomLeft)},
633
+ {borderWidths.left + borderRadii.bottomLeft, borderWidths.bottom + borderRadii.bottomLeft},
634
+ {0, 0},
635
+ std::max(borderWidths.left, borderWidths.bottom),
636
+ borderColors.left ? borderColors.left : borderColors.bottom,
637
+ borderStyle);
638
+
639
+ // Left Edge Border
640
+ SetBorderLayerProperties(
641
+ theme,
642
+ compContext,
643
+ spBorderLayers[7],
644
+ shape,
645
+ spTextures[7],
646
+ {0,
647
+ borderWidths.top + borderRadii.topLeft,
648
+ borderWidths.left,
649
+ textureHeight - (borderWidths.bottom + borderRadii.bottomLeft)},
650
+ {AnchorPosition::Left, AnchorPosition::Top},
651
+ {0, borderWidths.top + borderRadii.topLeft},
652
+ {borderWidths.left, -(borderWidths.top + borderRadii.topLeft + borderWidths.bottom + borderRadii.bottomLeft)},
653
+ {0, 1},
654
+ borderWidths.left,
655
+ borderColors.left,
656
+ borderStyle);
657
+ }
658
+
659
+ winrt::com_ptr<ID2D1GeometryGroup> GetGeometryForRoundedBorder(
660
+ winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
661
+ const facebook::react::RectangleCorners<float> &radius,
662
+ const facebook::react::RectangleEdges<float> &inset,
663
+ const facebook::react::RectangleEdges<float> &thickness,
664
+ const facebook::react::RectangleEdges<float> &rectPathGeometry) noexcept {
665
+ winrt::com_ptr<ID2D1PathGeometry> outerPathGeometry =
666
+ BorderPrimitive::GenerateRoundedRectPathGeometry(compContext, radius, inset, rectPathGeometry);
667
+
668
+ if (outerPathGeometry == nullptr) {
669
+ assert(false);
670
+ return nullptr;
671
+ }
672
+
673
+ facebook::react::RectangleEdges<float> rectInnerPathGeometry = {
674
+ rectPathGeometry.left + thickness.left,
675
+ rectPathGeometry.top + thickness.top,
676
+ rectPathGeometry.right - thickness.right,
677
+ rectPathGeometry.bottom - thickness.bottom};
678
+
679
+ // Total thickness is larger than original element size.
680
+ // Clamp inner rect to have a width/height of 0, but placed such that the ratio of side-thicknesses is respected.
681
+ // We need to respect this ratio so that any animations work properly.
682
+
683
+ if (rectInnerPathGeometry.left > rectInnerPathGeometry.right) {
684
+ float leftRatio = thickness.left / (thickness.left + thickness.right);
685
+ auto x = std::floor(rectPathGeometry.left + ((rectPathGeometry.right - rectPathGeometry.left) * leftRatio));
686
+ rectInnerPathGeometry.left = x;
687
+ rectInnerPathGeometry.right = x;
688
+ }
689
+
690
+ if (rectInnerPathGeometry.top > rectInnerPathGeometry.bottom) {
691
+ float topRatio = thickness.top / (thickness.top + thickness.bottom);
692
+ auto y = rectPathGeometry.top + std::floor((rectPathGeometry.top - rectPathGeometry.bottom) * topRatio);
693
+ rectInnerPathGeometry.top = y;
694
+ rectInnerPathGeometry.bottom = y;
695
+ }
696
+
697
+ facebook::react::RectangleEdges<float> innerInset = {
698
+ inset.left + thickness.left,
699
+ inset.top + thickness.top,
700
+ inset.right + thickness.right,
701
+ inset.bottom + thickness.bottom};
702
+
703
+ winrt::com_ptr<ID2D1PathGeometry> innerPathGeometry =
704
+ BorderPrimitive::GenerateRoundedRectPathGeometry(compContext, radius, innerInset, rectInnerPathGeometry);
705
+
706
+ if (innerPathGeometry == nullptr) {
707
+ assert(false); // Failed to create inner pathGeometry for rounded border
708
+ return nullptr;
709
+ }
710
+
711
+ ID2D1Geometry *ppGeometries[] = {outerPathGeometry.get(), innerPathGeometry.get()};
712
+ winrt::com_ptr<ID2D1Factory1> spD2dFactory;
713
+ compContext.as<::Microsoft::ReactNative::Composition::Experimental::ICompositionContextInterop>()->D2DFactory(
714
+ spD2dFactory.put());
715
+
716
+ winrt::com_ptr<ID2D1GeometryGroup> geometryGroup = nullptr;
717
+ // Create a geometry group.
718
+ HRESULT hr = spD2dFactory->CreateGeometryGroup(
719
+ D2D1_FILL_MODE_ALTERNATE, ppGeometries, ARRAYSIZE(ppGeometries), geometryGroup.put());
720
+
721
+ if (SUCCEEDED(hr)) {
722
+ return geometryGroup;
723
+ }
724
+ return nullptr;
725
+ }
726
+
727
+ BorderPrimitive::BorderPrimitive(
728
+ winrt::Microsoft::ReactNative::Composition::implementation::ComponentView &outer,
729
+ const winrt::Microsoft::ReactNative::Composition::Experimental::IVisual &rootVisual)
730
+ : m_outer(&outer), m_rootVisual(rootVisual) {}
731
+
732
+ BorderPrimitive::BorderPrimitive(winrt::Microsoft::ReactNative::Composition::implementation::ComponentView &outer)
733
+ : m_outer(&outer), m_rootVisual(outer.CompositionContext().CreateSpriteVisual()) {}
734
+
735
+ winrt::Microsoft::ReactNative::Composition::Experimental::IVisual BorderPrimitive::RootVisual() const noexcept {
736
+ return m_rootVisual;
737
+ }
738
+
739
+ bool BorderPrimitive::requiresBorder(
740
+ const facebook::react::BorderMetrics &borderMetrics,
741
+ winrt::Microsoft::ReactNative::Composition::implementation::Theme *theme) noexcept {
742
+ // We only handle a single borderStyle for now
743
+ auto borderStyle = borderMetrics.borderStyles.left;
744
+
745
+ bool hasMeaningfulColor =
746
+ !borderMetrics.borderColors.isUniform() || !isColorMeaningful(borderMetrics.borderColors.left, theme);
747
+ bool hasMeaningfulWidth = !borderMetrics.borderWidths.isUniform() || (borderMetrics.borderWidths.left != 0);
748
+ if (!hasMeaningfulColor && !hasMeaningfulWidth) {
749
+ return false;
750
+ }
751
+ return true;
752
+ }
753
+
754
+ void BorderPrimitive::updateProps(
755
+ const facebook::react::ViewProps &oldViewProps,
756
+ const facebook::react::ViewProps &newViewProps) noexcept {
757
+ if (oldViewProps.borderColors != newViewProps.borderColors || oldViewProps.borderRadii != newViewProps.borderRadii ||
758
+ !(oldViewProps.yogaStyle.border(facebook::yoga::Edge::All) ==
759
+ newViewProps.yogaStyle.border(facebook::yoga::Edge::All)) ||
760
+ oldViewProps.borderStyles != newViewProps.borderStyles) {
761
+ m_needsUpdate = true;
762
+ }
763
+ }
764
+
765
+ void BorderPrimitive::markNeedsUpdate() noexcept {
766
+ m_needsUpdate = true;
767
+ }
768
+
769
+ void BorderPrimitive::finalize(
770
+ facebook::react::LayoutMetrics const &layoutMetrics,
771
+ const facebook::react::BorderMetrics &borderMetrics) noexcept {
772
+ if (!m_needsUpdate) {
773
+ return;
774
+ }
775
+
776
+ auto theme = m_outer->theme();
777
+ if (!theme || theme->IsEmpty()) {
778
+ return;
779
+ }
780
+
781
+ m_needsUpdate = false;
782
+ auto spBorderLayers = FindSpecialBorderLayers();
783
+
784
+ if (!TryUpdateSpecialBorderLayers(m_outer->theme(), spBorderLayers, layoutMetrics, borderMetrics)) {
785
+ for (auto &spBorderLayer : spBorderLayers) {
786
+ if (spBorderLayer) {
787
+ spBorderLayer.as<winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual>().Brush(nullptr);
788
+ }
789
+ }
790
+ }
791
+ }
792
+
793
+ void BorderPrimitive::onThemeChanged(
794
+ facebook::react::LayoutMetrics const &layoutMetrics,
795
+ const facebook::react::BorderMetrics &borderMetrics) noexcept {
796
+ m_needsUpdate = true;
797
+ finalize(layoutMetrics, borderMetrics);
798
+ }
799
+
800
+ std::array<
801
+ winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual,
802
+ BorderPrimitive::SpecialBorderLayerCount>
803
+ BorderPrimitive::FindSpecialBorderLayers() const noexcept {
804
+ std::array<winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual, SpecialBorderLayerCount> layers{
805
+ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
806
+
807
+ if (m_numBorderVisuals) {
808
+ for (uint8_t i = 0; i < m_numBorderVisuals; i++) {
809
+ auto visual = m_rootVisual.GetAt(i);
810
+ layers[i] = visual.as<winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual>();
811
+ }
812
+ }
813
+
814
+ return layers;
815
+ }
816
+
817
+ uint8_t BorderPrimitive::numberOfVisuals() const noexcept {
818
+ return m_numBorderVisuals;
819
+ }
820
+
821
+ void BorderPrimitive::setOuter(
822
+ winrt::Microsoft::ReactNative::Composition::implementation::ComponentView *outer) noexcept {
823
+ m_outer = outer;
824
+ }
825
+
826
+ bool BorderPrimitive::TryUpdateSpecialBorderLayers(
827
+ winrt::Microsoft::ReactNative::Composition::implementation::Theme *theme,
828
+ std::array<winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual, SpecialBorderLayerCount>
829
+ &spBorderVisuals,
830
+ facebook::react::LayoutMetrics const &layoutMetrics,
831
+ const facebook::react::BorderMetrics &borderMetrics) noexcept {
832
+ // We only handle a single borderStyle for now
833
+ auto borderStyle = borderMetrics.borderStyles.left;
834
+
835
+ bool hasMeaningfulColor =
836
+ !borderMetrics.borderColors.isUniform() || !isColorMeaningful(borderMetrics.borderColors.left, theme);
837
+ bool hasMeaningfulWidth = !borderMetrics.borderWidths.isUniform() || (borderMetrics.borderWidths.left != 0);
838
+ if (!hasMeaningfulColor && !hasMeaningfulWidth) {
839
+ return false;
840
+ }
841
+
842
+ // Create the special border layers if they don't exist yet
843
+ if (!spBorderVisuals[0]) {
844
+ for (uint8_t i = 0; i < SpecialBorderLayerCount; i++) {
845
+ auto visual = m_outer->CompositionContext().CreateSpriteVisual();
846
+ m_rootVisual.InsertAt(visual, i);
847
+ spBorderVisuals[i] = std::move(visual);
848
+ m_numBorderVisuals++;
849
+ }
850
+ }
851
+
852
+ float extentWidth = layoutMetrics.frame.size.width * layoutMetrics.pointScaleFactor;
853
+ float extentHeight = layoutMetrics.frame.size.height * layoutMetrics.pointScaleFactor;
854
+
855
+ if (borderMetrics.borderRadii.topLeft != 0 || borderMetrics.borderRadii.bottomLeft != 0 ||
856
+ borderMetrics.borderRadii.topRight != 0 || borderMetrics.borderRadii.bottomRight != 0) {
857
+ auto compContext = m_outer->CompositionContext();
858
+ if (borderStyle == facebook::react::BorderStyle::Dotted || borderStyle == facebook::react::BorderStyle::Dashed) {
859
+ // Because in DirectX geometry starts at the center of the stroke, we need to deflate
860
+ // rectangle by half the stroke width to render correctly.
861
+ facebook::react::RectangleEdges<float> rectPathGeometry = {
862
+ borderMetrics.borderWidths.left / 2.0f,
863
+ borderMetrics.borderWidths.top / 2.0f,
864
+ extentWidth - borderMetrics.borderWidths.right / 2.0f,
865
+ extentHeight - borderMetrics.borderWidths.bottom / 2.0f};
866
+
867
+ winrt::com_ptr<ID2D1PathGeometry> pathGeometry =
868
+ GenerateRoundedRectPathGeometry(compContext, borderMetrics.borderRadii, {0, 0, 0, 0}, rectPathGeometry);
869
+
870
+ if (pathGeometry) {
871
+ DrawAllBorderLayers(
872
+ theme,
873
+ compContext,
874
+ spBorderVisuals,
875
+ *pathGeometry,
876
+ borderMetrics.borderWidths,
877
+ borderMetrics.borderRadii,
878
+ extentWidth,
879
+ extentHeight,
880
+ borderMetrics.borderColors,
881
+ borderStyle);
882
+ } else {
883
+ assert(false);
884
+ }
885
+ } else {
886
+ facebook::react::RectangleEdges<float> rectPathGeometry = {0, 0, extentWidth, extentHeight};
887
+
888
+ winrt::com_ptr<ID2D1GeometryGroup> pathGeometry = GetGeometryForRoundedBorder(
889
+ compContext,
890
+ borderMetrics.borderRadii,
891
+ {0, 0, 0, 0}, // inset
892
+ borderMetrics.borderWidths,
893
+ rectPathGeometry);
894
+
895
+ DrawAllBorderLayers(
896
+ theme,
897
+ compContext,
898
+ spBorderVisuals,
899
+ *pathGeometry,
900
+ borderMetrics.borderWidths,
901
+ borderMetrics.borderRadii,
902
+ extentWidth,
903
+ extentHeight,
904
+ borderMetrics.borderColors,
905
+ borderStyle);
906
+ }
907
+ } else {
908
+ auto compContext = m_outer->CompositionContext();
909
+ // Because in DirectX geometry starts at the center of the stroke, we need to deflate rectangle by half the stroke
910
+ // width / height to render correctly.
911
+ D2D1_RECT_F rectShape{
912
+ borderMetrics.borderWidths.left / 2.0f,
913
+ borderMetrics.borderWidths.top / 2.0f,
914
+ extentWidth - (borderMetrics.borderWidths.right / 2.0f),
915
+ extentHeight - (borderMetrics.borderWidths.bottom / 2.0f)};
916
+ DrawAllBorderLayers(
917
+ theme,
918
+ compContext,
919
+ spBorderVisuals,
920
+ rectShape,
921
+ borderMetrics.borderWidths,
922
+ borderMetrics.borderRadii,
923
+ extentWidth,
924
+ extentHeight,
925
+ borderMetrics.borderColors,
926
+ borderStyle);
927
+ }
928
+ return true;
929
+ }
930
+
931
+ } // namespace winrt::Microsoft::ReactNative::Composition::implementation