react-native-windows 0.0.0-canary.705 → 0.0.0-canary.706

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 (62) hide show
  1. package/.flowconfig +2 -1
  2. package/Libraries/Animated/components/AnimatedFlatList.js +1 -1
  3. package/Libraries/Animated/components/AnimatedSectionList.js +1 -1
  4. package/Libraries/Animated/nodes/AnimatedColor.js +1 -1
  5. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +3 -1
  6. package/Libraries/Components/TextInput/TextInput.js +2 -0
  7. package/Libraries/Components/TextInput/TextInput.windows.js +2 -0
  8. package/Libraries/Components/ToastAndroid/ToastAndroid.js +9 -1
  9. package/Libraries/Components/ToastAndroid/ToastAndroid.windows.js +9 -1
  10. package/Libraries/Components/View/ViewNativeComponent.js +1 -0
  11. package/Libraries/Components/View/ViewPropTypes.js +9 -0
  12. package/Libraries/Components/View/ViewPropTypes.windows.js +9 -0
  13. package/Libraries/Core/ReactNativeVersion.js +1 -1
  14. package/Libraries/DOM/Nodes/ReadOnlyElement.js +28 -0
  15. package/Libraries/Image/Image.android.js +1 -1
  16. package/Libraries/Image/Image.ios.js +1 -0
  17. package/Libraries/Image/Image.windows.js +1 -0
  18. package/Libraries/NativeComponent/BaseViewConfig.android.js +2 -0
  19. package/Libraries/NativeComponent/BaseViewConfig.ios.js +2 -0
  20. package/Libraries/NativeComponent/BaseViewConfig.windows.js +2 -0
  21. package/Libraries/Network/RCTNetworking.android.js +2 -1
  22. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +3 -1
  23. package/Libraries/Pressability/Pressability.js +7 -1
  24. package/Libraries/Pressability/Pressability.windows.js +7 -1
  25. package/Libraries/ReactNative/AppContainer.js +32 -9
  26. package/Libraries/ReactNative/FabricUIManager.js +7 -0
  27. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +3 -0
  28. package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +9 -4
  29. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +28 -13
  30. package/Libraries/StyleSheet/PlatformColorValueTypes.windows.js +9 -4
  31. package/Libraries/StyleSheet/PlatformColorValueTypesIOS.ios.js +1 -1
  32. package/Libraries/StyleSheet/StyleSheet.js +2 -0
  33. package/Libraries/StyleSheet/StyleSheetTypes.js +1 -1
  34. package/Libraries/StyleSheet/processColor.js +1 -2
  35. package/Libraries/Utilities/Platform.android.js +6 -8
  36. package/Libraries/Utilities/Platform.flow.js +84 -0
  37. package/Libraries/Utilities/Platform.flow.windows.js +111 -0
  38. package/Libraries/Utilities/Platform.ios.js +6 -8
  39. package/Libraries/Utilities/Platform.windows.js +6 -8
  40. package/Microsoft.ReactNative/Fabric/platform/react/components/view/windows/WindowsViewProps.cpp +85 -3
  41. package/Microsoft.ReactNative/Fabric/platform/react/components/view/windows/WindowsViewProps.h +27 -2
  42. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformTouch.h +10 -0
  43. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewEventEmitter.h +10 -0
  44. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +32 -0
  45. package/Microsoft.ReactNative/Fabric/platform/react/renderer/core/graphicsConversions.h +1 -1
  46. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/Color.h +3 -2
  47. package/Microsoft.ReactNative/packages.lock.json +40 -41
  48. package/PropertySheets/Generated/PackageVersion.g.props +2 -2
  49. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/{ViewEventEmitter.cpp → BaseViewEventEmitter.cpp} +12 -12
  50. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/{ViewEventEmitter.h → BaseViewEventEmitter.h} +2 -4
  51. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/{ViewProps.cpp → BaseViewProps.cpp} +14 -97
  52. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/{ViewProps.h → BaseViewProps.h} +7 -8
  53. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/TouchEventEmitter.cpp +0 -16
  54. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/ViewShadowNode.cpp +7 -20
  55. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/YogaLayoutableShadowNode.cpp +1020 -0
  56. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/YogaStylableProps.cpp +1 -2
  57. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/primitives.h +6 -43
  58. package/Shared/Shared.vcxitems +5 -2
  59. package/Shared/Shared.vcxitems.filters +2 -0
  60. package/package.json +8 -8
  61. package/types/experimental.d.ts +9 -0
  62. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +0 -1445
@@ -0,0 +1,1020 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #include "YogaLayoutableShadowNode.h"
9
+ #include <logger/react_native_log.h>
10
+ #include <react/debug/flags.h>
11
+ #include <react/debug/react_native_assert.h>
12
+ #include <react/renderer/components/view/ViewProps.h>
13
+ #include <react/renderer/components/view/ViewShadowNode.h>
14
+ #include <react/renderer/components/view/conversions.h>
15
+ #include <react/renderer/core/LayoutConstraints.h>
16
+ #include <react/renderer/core/LayoutContext.h>
17
+ #include <react/renderer/core/TraitCast.h>
18
+ #include <react/renderer/debug/DebugStringConvertibleItem.h>
19
+ #include <react/renderer/debug/SystraceSection.h>
20
+ #include <react/utils/CoreFeatures.h>
21
+ #include <yoga/Yoga.h>
22
+ #include <algorithm>
23
+ #include <limits>
24
+ #include <memory>
25
+
26
+ namespace facebook::react {
27
+
28
+ static int FabricDefaultYogaLog(
29
+ const YGConfigRef /*unused*/,
30
+ const YGNodeRef /*unused*/,
31
+ YGLogLevel level,
32
+ const char *format,
33
+ va_list args) {
34
+ va_list args_copy;
35
+ va_copy(args_copy, args);
36
+
37
+ // Adding 1 to add space for terminating null character.
38
+ int size_s = vsnprintf(nullptr, 0, format, args);
39
+ auto size = static_cast<size_t>(size_s);
40
+ std::vector<char> buffer(size);
41
+
42
+ vsnprintf(buffer.data(), size, format, args_copy);
43
+ switch (level) {
44
+ case YGLogLevelError:
45
+ react_native_log_error(buffer.data());
46
+ break;
47
+ case YGLogLevelFatal:
48
+ react_native_log_fatal(buffer.data());
49
+ break;
50
+ case YGLogLevelWarn:
51
+ react_native_log_warn(buffer.data());
52
+ break;
53
+ case YGLogLevelInfo:
54
+ case YGLogLevelDebug:
55
+ case YGLogLevelVerbose:
56
+ default:
57
+ react_native_log_info(buffer.data());
58
+ }
59
+
60
+ return size_s;
61
+ }
62
+
63
+ thread_local LayoutContext threadLocalLayoutContext;
64
+
65
+ ShadowNodeTraits YogaLayoutableShadowNode::BaseTraits() {
66
+ auto traits = LayoutableShadowNode::BaseTraits();
67
+ traits.set(IdentifierTrait());
68
+ return traits;
69
+ }
70
+
71
+ ShadowNodeTraits::Trait YogaLayoutableShadowNode::IdentifierTrait() {
72
+ return ShadowNodeTraits::Trait::YogaLayoutableKind;
73
+ }
74
+
75
+ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
76
+ ShadowNodeFragment const &fragment,
77
+ ShadowNodeFamily::Shared const &family,
78
+ ShadowNodeTraits traits)
79
+ : LayoutableShadowNode(fragment, family, traits),
80
+ yogaConfig_(FabricDefaultYogaLog),
81
+ yogaNode_(&initializeYogaConfig(yogaConfig_)) {
82
+ yogaNode_.setContext(this);
83
+
84
+ // Newly created node must be `dirty` just because it is new.
85
+ // This is not a default for `YGNode`.
86
+ yogaNode_.setDirty(true);
87
+
88
+ if (getTraits().check(ShadowNodeTraits::Trait::MeasurableYogaNode)) {
89
+ react_native_assert(
90
+ getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode));
91
+
92
+ yogaNode_.setMeasureFunc(
93
+ YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector);
94
+ }
95
+
96
+ updateYogaProps();
97
+ updateYogaChildren();
98
+
99
+ ensureConsistency();
100
+ }
101
+
102
+ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
103
+ ShadowNode const &sourceShadowNode,
104
+ ShadowNodeFragment const &fragment)
105
+ : LayoutableShadowNode(sourceShadowNode, fragment),
106
+ yogaConfig_(FabricDefaultYogaLog),
107
+ yogaNode_(static_cast<YogaLayoutableShadowNode const &>(sourceShadowNode)
108
+ .yogaNode_) {
109
+ // Note, cloned `YGNode` instance (copied using copy-constructor) inherits
110
+ // dirty flag, measure function, and other properties being set originally in
111
+ // the `YogaLayoutableShadowNode` constructor above.
112
+
113
+ react_native_assert(
114
+ static_cast<YogaLayoutableShadowNode const &>(sourceShadowNode)
115
+ .yogaNode_.isDirty() == yogaNode_.isDirty() &&
116
+ "Yoga node must inherit dirty flag.");
117
+
118
+ if (!getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
119
+ for (auto &child : getChildren()) {
120
+ if (auto layoutableChild = traitCast<YogaLayoutableShadowNode>(child)) {
121
+ yogaLayoutableChildren_.push_back(layoutableChild);
122
+ }
123
+ }
124
+ }
125
+
126
+ YGConfigRef previousConfig = YGNodeGetConfig(
127
+ &static_cast<YogaLayoutableShadowNode const &>(sourceShadowNode)
128
+ .yogaNode_);
129
+
130
+ yogaNode_.setContext(this);
131
+ yogaNode_.setOwner(nullptr);
132
+ yogaNode_.setConfig(&initializeYogaConfig(yogaConfig_, previousConfig));
133
+ updateYogaChildrenOwnersIfNeeded();
134
+
135
+ // This is the only legit place where we can dirty cloned Yoga node.
136
+ // If we do it later, ancestor nodes will not be able to observe this and
137
+ // dirty (and clone) themselves as a result.
138
+ if (getTraits().check(ShadowNodeTraits::Trait::DirtyYogaNode) ||
139
+ getTraits().check(ShadowNodeTraits::Trait::MeasurableYogaNode)) {
140
+ yogaNode_.setDirty(true);
141
+ }
142
+
143
+ // We do not need to reconfigure this subtree before the next layout pass if
144
+ // the previous node with the same props and children has already been
145
+ // configured.
146
+ if (!fragment.props && !fragment.children) {
147
+ yogaTreeHasBeenConfigured_ =
148
+ static_cast<YogaLayoutableShadowNode const &>(sourceShadowNode)
149
+ .yogaTreeHasBeenConfigured_;
150
+ }
151
+
152
+ if (fragment.props) {
153
+ updateYogaProps();
154
+ }
155
+
156
+ if (fragment.children) {
157
+ updateYogaChildren();
158
+ }
159
+
160
+ ensureConsistency();
161
+ }
162
+
163
+ void YogaLayoutableShadowNode::cleanLayout() {
164
+ yogaNode_.setDirty(false);
165
+ }
166
+
167
+ void YogaLayoutableShadowNode::dirtyLayout() {
168
+ yogaNode_.setDirty(true);
169
+ }
170
+
171
+ bool YogaLayoutableShadowNode::getIsLayoutClean() const {
172
+ return !yogaNode_.isDirty();
173
+ }
174
+
175
+ #pragma mark - Mutating Methods
176
+
177
+ void YogaLayoutableShadowNode::enableMeasurement() {
178
+ ensureUnsealed();
179
+
180
+ yogaNode_.setMeasureFunc(
181
+ YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector);
182
+ }
183
+
184
+ void YogaLayoutableShadowNode::appendYogaChild(
185
+ YogaLayoutableShadowNode::Shared const &childNode) {
186
+ // The caller must check this before calling this method.
187
+ react_native_assert(
188
+ !getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode));
189
+
190
+ ensureYogaChildrenLookFine();
191
+
192
+ yogaLayoutableChildren_.push_back(childNode);
193
+ yogaNode_.insertChild(
194
+ &childNode->yogaNode_,
195
+ static_cast<uint32_t>(yogaNode_.getChildren().size()));
196
+
197
+ ensureYogaChildrenLookFine();
198
+ }
199
+
200
+ void YogaLayoutableShadowNode::adoptYogaChild(size_t index) {
201
+ ensureUnsealed();
202
+ ensureYogaChildrenLookFine();
203
+
204
+ // The caller must check this before calling this method.
205
+ react_native_assert(
206
+ !getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode));
207
+
208
+ auto &childNode =
209
+ traitCast<YogaLayoutableShadowNode const &>(*getChildren().at(index));
210
+
211
+ if (childNode.yogaNode_.getOwner() == nullptr) {
212
+ // The child node is not owned.
213
+ childNode.yogaNode_.setOwner(&yogaNode_);
214
+ // At this point the child yoga node must be already inserted by the caller.
215
+ // react_native_assert(layoutableChildNode.yogaNode_.isDirty());
216
+ } else {
217
+ // The child is owned by some other node, we need to clone that.
218
+ // TODO: At this point, React has wrong reference to the node. (T138668036)
219
+ auto clonedChildNode = childNode.clone({});
220
+
221
+ // Replace the child node with a newly cloned one in the children list.
222
+ replaceChild(childNode, clonedChildNode, static_cast<int>(index));
223
+ }
224
+
225
+ ensureYogaChildrenLookFine();
226
+ }
227
+
228
+ void YogaLayoutableShadowNode::appendChild(
229
+ ShadowNode::Shared const &childNode) {
230
+ ensureUnsealed();
231
+ ensureConsistency();
232
+
233
+ // Calling the base class (`ShadowNode`) method.
234
+ LayoutableShadowNode::appendChild(childNode);
235
+
236
+ if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
237
+ // This node is a declared leaf.
238
+ return;
239
+ }
240
+
241
+ if (auto yogaLayoutableChild =
242
+ traitCast<YogaLayoutableShadowNode>(childNode)) {
243
+ // Here we don't have information about the previous structure of the node
244
+ // (if it that existed before), so we don't have anything to compare the
245
+ // Yoga node with (like a previous version of this node). Therefore we must
246
+ // dirty the node.
247
+ yogaNode_.setDirty(true);
248
+
249
+ // Appending the Yoga node.
250
+ appendYogaChild(yogaLayoutableChild);
251
+
252
+ ensureYogaChildrenLookFine();
253
+ ensureYogaChildrenAlignment();
254
+
255
+ // Adopting the Yoga node.
256
+ adoptYogaChild(getChildren().size() - 1);
257
+
258
+ ensureConsistency();
259
+ }
260
+ }
261
+
262
+ void YogaLayoutableShadowNode::replaceChild(
263
+ ShadowNode const &oldChild,
264
+ ShadowNode::Shared const &newChild,
265
+ int32_t suggestedIndex) {
266
+ LayoutableShadowNode::replaceChild(oldChild, newChild, suggestedIndex);
267
+
268
+ ensureUnsealed();
269
+ ensureYogaChildrenLookFine();
270
+
271
+ auto layoutableOldChild =
272
+ traitCast<YogaLayoutableShadowNode const *>(&oldChild);
273
+ auto layoutableNewChild = traitCast<YogaLayoutableShadowNode>(newChild);
274
+
275
+ if (layoutableOldChild == nullptr && layoutableNewChild == nullptr) {
276
+ // No need to mutate yogaLayoutableChildren_
277
+ return;
278
+ }
279
+
280
+ // [Windows]
281
+ bool suggestedIndexAccurate = suggestedIndex >= 0 &&
282
+ suggestedIndex < static_cast<int32_t>(yogaLayoutableChildren_.size()) &&
283
+ yogaLayoutableChildren_[suggestedIndex].get() == layoutableOldChild;
284
+
285
+ auto oldChildIter = suggestedIndexAccurate
286
+ ? yogaLayoutableChildren_.begin() + suggestedIndex
287
+ : std::find_if(
288
+ yogaLayoutableChildren_.begin(),
289
+ yogaLayoutableChildren_.end(),
290
+ [&](YogaLayoutableShadowNode::Shared const &layoutableChild) {
291
+ return layoutableChild.get() == layoutableOldChild;
292
+ });
293
+ auto oldChildIndex =
294
+ static_cast<int32_t>(oldChildIter - yogaLayoutableChildren_.begin());
295
+
296
+ if (oldChildIter == yogaLayoutableChildren_.end()) {
297
+ // oldChild does not exist as part of our node
298
+ return;
299
+ }
300
+
301
+ if (layoutableNewChild) {
302
+ // Both children are layoutable, replace the old one with the new one
303
+ react_native_assert(layoutableNewChild->yogaNode_.getOwner() == nullptr);
304
+ layoutableNewChild->yogaNode_.setOwner(&yogaNode_);
305
+ *oldChildIter = layoutableNewChild;
306
+ yogaNode_.replaceChild(&layoutableNewChild->yogaNode_, oldChildIndex);
307
+ } else {
308
+ // Layoutable child replaced with non layoutable child. Remove the previous
309
+ // child from the layoutable children list.
310
+ yogaLayoutableChildren_.erase(oldChildIter);
311
+ yogaNode_.removeChild(oldChildIndex);
312
+ }
313
+
314
+ ensureYogaChildrenLookFine();
315
+ }
316
+
317
+ bool YogaLayoutableShadowNode::doesOwn(
318
+ YogaLayoutableShadowNode const &child) const {
319
+ return child.yogaNode_.getOwner() == &yogaNode_;
320
+ }
321
+
322
+ void YogaLayoutableShadowNode::updateYogaChildrenOwnersIfNeeded() {
323
+ for (auto &childYogaNode : yogaNode_.getChildren()) {
324
+ if (childYogaNode->getOwner() == &yogaNode_) {
325
+ childYogaNode->setOwner(reinterpret_cast<YGNodeRef>(0xBADC0FFEE0DDF00D));
326
+ }
327
+ }
328
+ }
329
+
330
+ void YogaLayoutableShadowNode::updateYogaChildren() {
331
+ if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
332
+ return;
333
+ }
334
+
335
+ ensureUnsealed();
336
+
337
+ bool isClean = !yogaNode_.isDirty() &&
338
+ getChildren().size() == yogaNode_.getChildren().size();
339
+
340
+ auto oldYogaChildren = isClean ? yogaNode_.getChildren() : YGVector{};
341
+ yogaNode_.setChildren({});
342
+ yogaLayoutableChildren_.clear();
343
+
344
+ for (size_t i = 0; i < getChildren().size(); i++) {
345
+ if (auto yogaLayoutableChild =
346
+ traitCast<YogaLayoutableShadowNode>(getChildren()[i])) {
347
+ appendYogaChild(yogaLayoutableChild);
348
+ adoptYogaChild(i);
349
+
350
+ if (isClean) {
351
+ auto yogaChildIndex = yogaLayoutableChildren_.size() - 1;
352
+ auto &oldYogaChildNode = *oldYogaChildren.at(yogaChildIndex);
353
+ auto &newYogaChildNode =
354
+ yogaLayoutableChildren_.at(yogaChildIndex)->yogaNode_;
355
+
356
+ isClean = isClean && !newYogaChildNode.isDirty() &&
357
+ (newYogaChildNode.getStyle() == oldYogaChildNode.getStyle());
358
+ }
359
+ }
360
+ }
361
+
362
+ react_native_assert(
363
+ yogaLayoutableChildren_.size() == yogaNode_.getChildren().size());
364
+
365
+ yogaNode_.setDirty(!isClean);
366
+ }
367
+
368
+ void YogaLayoutableShadowNode::updateYogaProps() {
369
+ ensureUnsealed();
370
+
371
+ auto props = static_cast<YogaStylableProps const &>(*props_);
372
+ auto styleResult = applyAliasedProps(props.yogaStyle, props);
373
+
374
+ // Resetting `dirty` flag only if `yogaStyle` portion of `Props` was changed.
375
+ if (!yogaNode_.isDirty() && (styleResult != yogaNode_.getStyle())) {
376
+ yogaNode_.setDirty(true);
377
+ }
378
+
379
+ yogaNode_.setStyle(styleResult);
380
+ }
381
+
382
+ /*static*/ YGStyle YogaLayoutableShadowNode::applyAliasedProps(
383
+ const YGStyle &baseStyle,
384
+ const YogaStylableProps &props) {
385
+ YGStyle result{baseStyle};
386
+
387
+ // Aliases with precedence
388
+ if (!props.inset.isUndefined()) {
389
+ result.position()[YGEdgeAll] = props.inset;
390
+ }
391
+ if (!props.insetBlock.isUndefined()) {
392
+ result.position()[YGEdgeVertical] = props.insetBlock;
393
+ }
394
+ if (!props.insetInline.isUndefined()) {
395
+ result.position()[YGEdgeHorizontal] = props.insetInline;
396
+ }
397
+ if (!props.insetInlineEnd.isUndefined()) {
398
+ result.position()[YGEdgeEnd] = props.insetInlineEnd;
399
+ }
400
+ if (!props.insetInlineStart.isUndefined()) {
401
+ result.position()[YGEdgeStart] = props.insetInlineStart;
402
+ }
403
+ if (!props.marginInline.isUndefined()) {
404
+ result.margin()[YGEdgeHorizontal] = props.marginInline;
405
+ }
406
+ if (!props.marginInlineStart.isUndefined()) {
407
+ result.margin()[YGEdgeStart] = props.marginInlineStart;
408
+ }
409
+ if (!props.marginInlineEnd.isUndefined()) {
410
+ result.margin()[YGEdgeEnd] = props.marginInlineEnd;
411
+ }
412
+ if (!props.marginBlock.isUndefined()) {
413
+ result.margin()[YGEdgeVertical] = props.marginBlock;
414
+ }
415
+ if (!props.paddingInline.isUndefined()) {
416
+ result.padding()[YGEdgeHorizontal] = props.paddingInline;
417
+ }
418
+ if (!props.paddingInlineStart.isUndefined()) {
419
+ result.padding()[YGEdgeStart] = props.paddingInlineStart;
420
+ }
421
+ if (!props.paddingInlineEnd.isUndefined()) {
422
+ result.padding()[YGEdgeEnd] = props.paddingInlineEnd;
423
+ }
424
+ if (!props.paddingBlock.isUndefined()) {
425
+ result.padding()[YGEdgeVertical] = props.paddingBlock;
426
+ }
427
+
428
+ // Aliases without precedence
429
+ if (CompactValue(result.position()[YGEdgeBottom]).isUndefined()) {
430
+ result.position()[YGEdgeBottom] = props.insetBlockEnd;
431
+ }
432
+ if (CompactValue(result.position()[YGEdgeTop]).isUndefined()) {
433
+ result.position()[YGEdgeTop] = props.insetBlockStart;
434
+ }
435
+ if (CompactValue(result.margin()[YGEdgeTop]).isUndefined()) {
436
+ result.margin()[YGEdgeTop] = props.marginBlockStart;
437
+ }
438
+ if (CompactValue(result.margin()[YGEdgeBottom]).isUndefined()) {
439
+ result.margin()[YGEdgeBottom] = props.marginBlockEnd;
440
+ }
441
+ if (CompactValue(result.padding()[YGEdgeTop]).isUndefined()) {
442
+ result.padding()[YGEdgeTop] = props.paddingBlockStart;
443
+ }
444
+ if (CompactValue(result.padding()[YGEdgeBottom]).isUndefined()) {
445
+ result.padding()[YGEdgeBottom] = props.paddingBlockEnd;
446
+ }
447
+
448
+ return result;
449
+ }
450
+
451
+ void YogaLayoutableShadowNode::configureYogaTree(
452
+ float pointScaleFactor,
453
+ YGErrata defaultErrata,
454
+ bool swapLeftAndRight) {
455
+ ensureUnsealed();
456
+
457
+ // Set state on our own Yoga node
458
+ YGErrata errata = resolveErrata(defaultErrata);
459
+ YGConfigSetErrata(&yogaConfig_, errata);
460
+ YGConfigSetPointScaleFactor(&yogaConfig_, pointScaleFactor);
461
+
462
+ // TODO: `swapLeftAndRight` modified backing props and cannot be undone
463
+ if (swapLeftAndRight) {
464
+ swapStyleLeftAndRight();
465
+ }
466
+
467
+ yogaTreeHasBeenConfigured_ = true;
468
+
469
+ // Recursively propagate the configuration to child nodes. If a child was
470
+ // already configured as part of a previous ShadowTree generation, we only
471
+ // need to reconfigure it if the context values passed to the Node have
472
+ // changed.
473
+ // [Windows]
474
+ for (size_t i = 0; i < yogaLayoutableChildren_.size(); i++) {
475
+ const auto &child = *yogaLayoutableChildren_[i];
476
+ auto childLayoutMetrics = child.getLayoutMetrics();
477
+ auto childErrata =
478
+ YGConfigGetErrata(const_cast<YGConfigRef>(&child.yogaConfig_));
479
+
480
+ if (child.yogaTreeHasBeenConfigured_ &&
481
+ childLayoutMetrics.pointScaleFactor == pointScaleFactor &&
482
+ childLayoutMetrics.wasLeftAndRightSwapped == swapLeftAndRight &&
483
+ childErrata == child.resolveErrata(errata)) {
484
+ continue;
485
+ }
486
+
487
+ if (doesOwn(child)) {
488
+ auto &mutableChild = const_cast<YogaLayoutableShadowNode &>(child);
489
+ mutableChild.configureYogaTree(
490
+ pointScaleFactor, child.resolveErrata(errata), swapLeftAndRight);
491
+ } else {
492
+ cloneChildInPlace(static_cast<int32_t>(i)).configureYogaTree(
493
+ pointScaleFactor, errata, swapLeftAndRight);
494
+ }
495
+ }
496
+ }
497
+
498
+ YGErrata YogaLayoutableShadowNode::resolveErrata(YGErrata defaultErrata) const {
499
+ if (auto viewShadowNode = traitCast<ViewShadowNode const *>(this)) {
500
+ const auto &props = viewShadowNode->getConcreteProps();
501
+ switch (props.experimental_layoutConformance) {
502
+ case LayoutConformance::Classic:
503
+ return YGErrataAll;
504
+ case LayoutConformance::Strict:
505
+ return YGErrataNone;
506
+ case LayoutConformance::Undefined:
507
+ return defaultErrata;
508
+ }
509
+ }
510
+
511
+ return defaultErrata;
512
+ }
513
+
514
+ YogaLayoutableShadowNode &YogaLayoutableShadowNode::cloneChildInPlace(
515
+ int32_t layoutableChildIndex) {
516
+ ensureUnsealed();
517
+
518
+ const auto &childNode = *yogaLayoutableChildren_[layoutableChildIndex];
519
+
520
+ // TODO: Why does this not use `ShadowNodeFragment::statePlaceholder()` like
521
+ // `adoptYogaChild()`?
522
+ auto clonedChildNode = childNode.clone(
523
+ {ShadowNodeFragment::propsPlaceholder(),
524
+ ShadowNodeFragment::childrenPlaceholder(),
525
+ childNode.getState()});
526
+
527
+ replaceChild(childNode, clonedChildNode, layoutableChildIndex);
528
+ return static_cast<YogaLayoutableShadowNode &>(*clonedChildNode);
529
+ }
530
+
531
+ void YogaLayoutableShadowNode::setSize(Size size) const {
532
+ ensureUnsealed();
533
+
534
+ auto style = yogaNode_.getStyle();
535
+ style.dimensions()[YGDimensionWidth] = yogaStyleValueFromFloat(size.width);
536
+ style.dimensions()[YGDimensionHeight] = yogaStyleValueFromFloat(size.height);
537
+ yogaNode_.setStyle(style);
538
+ yogaNode_.setDirty(true);
539
+ }
540
+
541
+ void YogaLayoutableShadowNode::setPadding(RectangleEdges<Float> padding) const {
542
+ ensureUnsealed();
543
+
544
+ auto style = yogaNode_.getStyle();
545
+
546
+ auto leftPadding = yogaStyleValueFromFloat(padding.left);
547
+ auto topPadding = yogaStyleValueFromFloat(padding.top);
548
+ auto rightPadding = yogaStyleValueFromFloat(padding.right);
549
+ auto bottomPadding = yogaStyleValueFromFloat(padding.bottom);
550
+
551
+ if (leftPadding != style.padding()[YGEdgeLeft] ||
552
+ topPadding != style.padding()[YGEdgeTop] ||
553
+ rightPadding != style.padding()[YGEdgeRight] ||
554
+ bottomPadding != style.padding()[YGEdgeBottom]) {
555
+ style.padding()[YGEdgeTop] = yogaStyleValueFromFloat(padding.top);
556
+ style.padding()[YGEdgeLeft] = yogaStyleValueFromFloat(padding.left);
557
+ style.padding()[YGEdgeRight] = yogaStyleValueFromFloat(padding.right);
558
+ style.padding()[YGEdgeBottom] = yogaStyleValueFromFloat(padding.bottom);
559
+ yogaNode_.setStyle(style);
560
+ yogaNode_.setDirty(true);
561
+ }
562
+ }
563
+
564
+ void YogaLayoutableShadowNode::setPositionType(
565
+ YGPositionType positionType) const {
566
+ ensureUnsealed();
567
+
568
+ auto style = yogaNode_.getStyle();
569
+ style.positionType() = positionType;
570
+ yogaNode_.setStyle(style);
571
+ yogaNode_.setDirty(true);
572
+ }
573
+
574
+ void YogaLayoutableShadowNode::layoutTree(
575
+ LayoutContext layoutContext,
576
+ LayoutConstraints layoutConstraints) {
577
+ ensureUnsealed();
578
+
579
+ SystraceSection s1("YogaLayoutableShadowNode::layoutTree");
580
+
581
+ bool swapLeftAndRight = layoutContext.swapLeftAndRightInRTL &&
582
+ (layoutConstraints.layoutDirection == LayoutDirection::RightToLeft ||
583
+ !CoreFeatures::doNotSwapLeftAndRightOnAndroidInLTR);
584
+
585
+ {
586
+ SystraceSection s2("YogaLayoutableShadowNode::configureYogaTree");
587
+ configureYogaTree(
588
+ layoutContext.pointScaleFactor,
589
+ YGErrataAll /*defaultErrata*/,
590
+ swapLeftAndRight);
591
+ }
592
+
593
+ auto minimumSize = layoutConstraints.minimumSize;
594
+ auto maximumSize = layoutConstraints.maximumSize;
595
+
596
+ // The caller must ensure that layout constraints make sense.
597
+ // Values cannot be NaN.
598
+ react_native_assert(!std::isnan(minimumSize.width));
599
+ react_native_assert(!std::isnan(minimumSize.height));
600
+ react_native_assert(!std::isnan(maximumSize.width));
601
+ react_native_assert(!std::isnan(maximumSize.height));
602
+ // Values cannot be negative.
603
+ react_native_assert(minimumSize.width >= 0);
604
+ react_native_assert(minimumSize.height >= 0);
605
+ react_native_assert(maximumSize.width >= 0);
606
+ react_native_assert(maximumSize.height >= 0);
607
+ // Minimum size cannot be infinity.
608
+ react_native_assert(!std::isinf(minimumSize.width));
609
+ react_native_assert(!std::isinf(minimumSize.height));
610
+
611
+ // Internally Yoga uses three different measurement modes controlling layout
612
+ // constraints: `Undefined`, `Exactly`, and `AtMost`. These modes are an
613
+ // implementation detail and are not defined in `CSS Flexible Box Layout
614
+ // Module`. Yoga C++ API (and `YGNodeCalculateLayout` function particularly)
615
+ // does not allow to specify the measure modes explicitly. Instead, it infers
616
+ // these from styles associated with the root node.
617
+ // To pass the actual layout constraints to Yoga we represent them as
618
+ // `(min/max)(Height/Width)` style properties. Also, we pass `ownerWidth` &
619
+ // `ownerHeight` to allow proper calculation of relative (e.g. specified in
620
+ // percents) style values.
621
+
622
+ auto &yogaStyle = yogaNode_.getStyle();
623
+
624
+ auto ownerWidth = yogaFloatFromFloat(maximumSize.width);
625
+ auto ownerHeight = yogaFloatFromFloat(maximumSize.height);
626
+
627
+ yogaStyle.maxDimensions()[YGDimensionWidth] = std::isfinite(maximumSize.width)
628
+ ? yogaStyleValueFromFloat(maximumSize.width)
629
+ : YGValueUndefined;
630
+
631
+ yogaStyle.maxDimensions()[YGDimensionHeight] =
632
+ std::isfinite(maximumSize.height)
633
+ ? yogaStyleValueFromFloat(maximumSize.height)
634
+ : YGValueUndefined;
635
+
636
+ yogaStyle.minDimensions()[YGDimensionWidth] = minimumSize.width > 0
637
+ ? yogaStyleValueFromFloat(minimumSize.width)
638
+ : YGValueUndefined;
639
+
640
+ yogaStyle.minDimensions()[YGDimensionHeight] = minimumSize.height > 0
641
+ ? yogaStyleValueFromFloat(minimumSize.height)
642
+ : YGValueUndefined;
643
+
644
+ auto direction =
645
+ yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection);
646
+
647
+ threadLocalLayoutContext = layoutContext;
648
+
649
+ {
650
+ SystraceSection s3("YogaLayoutableShadowNode::YGNodeCalculateLayout");
651
+ YGNodeCalculateLayout(&yogaNode_, ownerWidth, ownerHeight, direction);
652
+ }
653
+
654
+ // Update layout metrics for root node. Updated for children in
655
+ // YogaLayoutableShadowNode::layout
656
+ if (yogaNode_.getHasNewLayout()) {
657
+ auto layoutMetrics = layoutMetricsFromYogaNode(yogaNode_);
658
+ layoutMetrics.pointScaleFactor = layoutContext.pointScaleFactor;
659
+ layoutMetrics.wasLeftAndRightSwapped = swapLeftAndRight;
660
+ setLayoutMetrics(layoutMetrics);
661
+ yogaNode_.setHasNewLayout(false);
662
+ }
663
+
664
+ layout(layoutContext);
665
+ }
666
+
667
+ static EdgeInsets calculateOverflowInset(
668
+ Rect containerFrame,
669
+ Rect contentFrame) {
670
+ auto size = containerFrame.size;
671
+ auto overflowInset = EdgeInsets{};
672
+ overflowInset.left = std::min(contentFrame.getMinX(), Float{0.0});
673
+ overflowInset.top = std::min(contentFrame.getMinY(), Float{0.0});
674
+ overflowInset.right =
675
+ -std::max(contentFrame.getMaxX() - size.width, Float{0.0});
676
+ overflowInset.bottom =
677
+ -std::max(contentFrame.getMaxY() - size.height, Float{0.0});
678
+ return overflowInset;
679
+ }
680
+
681
+ void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
682
+ // Reading data from a dirtied node does not make sense.
683
+ react_native_assert(!yogaNode_.isDirty());
684
+
685
+ auto contentFrame = Rect{};
686
+ for (auto childYogaNode : yogaNode_.getChildren()) {
687
+ auto &childNode = shadowNodeFromContext(childYogaNode);
688
+
689
+ // Verifying that the Yoga node belongs to the ShadowNode.
690
+ react_native_assert(&childNode.yogaNode_ == childYogaNode);
691
+
692
+ if (childYogaNode->getHasNewLayout()) {
693
+ childYogaNode->setHasNewLayout(false);
694
+
695
+ // Reading data from a dirtied node does not make sense.
696
+ react_native_assert(!childYogaNode->isDirty());
697
+
698
+ // We must copy layout metrics from Yoga node only once (when the parent
699
+ // node exclusively ownes the child node).
700
+ react_native_assert(childYogaNode->getOwner() == &yogaNode_);
701
+
702
+ // We are about to mutate layout metrics of the node.
703
+ childNode.ensureUnsealed();
704
+
705
+ auto newLayoutMetrics = layoutMetricsFromYogaNode(*childYogaNode);
706
+ newLayoutMetrics.pointScaleFactor = layoutContext.pointScaleFactor;
707
+ newLayoutMetrics.wasLeftAndRightSwapped =
708
+ layoutContext.swapLeftAndRightInRTL &&
709
+ (newLayoutMetrics.layoutDirection == LayoutDirection::RightToLeft ||
710
+ !CoreFeatures::doNotSwapLeftAndRightOnAndroidInLTR);
711
+
712
+ // Child node's layout has changed. When a node is added to
713
+ // `affectedNodes`, onLayout event is called on the component. Comparing
714
+ // `newLayoutMetrics.frame` with `childNode.getLayoutMetrics().frame` to
715
+ // detect if layout has not changed is not advised, please refer to
716
+ // D22999891 for details.
717
+ if (layoutContext.affectedNodes != nullptr) {
718
+ layoutContext.affectedNodes->push_back(&childNode);
719
+ }
720
+
721
+ childNode.setLayoutMetrics(newLayoutMetrics);
722
+
723
+ if (newLayoutMetrics.displayType != DisplayType::None) {
724
+ childNode.layout(layoutContext);
725
+ }
726
+ }
727
+
728
+ auto layoutMetricsWithOverflowInset = childNode.getLayoutMetrics();
729
+ if (layoutMetricsWithOverflowInset.displayType != DisplayType::None) {
730
+ auto viewChildNode = traitCast<ViewShadowNode const *>(&childNode);
731
+ auto hitSlop = viewChildNode != nullptr
732
+ ? viewChildNode->getConcreteProps().hitSlop
733
+ : EdgeInsets{};
734
+
735
+ // The contentFrame should always union with existing child node layout +
736
+ // overflowInset. The transform may in a deferred animation and not
737
+ // applied yet.
738
+ contentFrame.unionInPlace(insetBy(
739
+ layoutMetricsWithOverflowInset.frame,
740
+ layoutMetricsWithOverflowInset.overflowInset));
741
+ contentFrame.unionInPlace(
742
+ outsetBy(layoutMetricsWithOverflowInset.frame, hitSlop));
743
+
744
+ auto childTransform = childNode.getTransform();
745
+ if (childTransform != Transform::Identity()) {
746
+ // The child node's transform matrix will affect the parent node's
747
+ // contentFrame. We need to union with child node's after transform
748
+ // layout here.
749
+ contentFrame.unionInPlace(insetBy(
750
+ layoutMetricsWithOverflowInset.frame * childTransform,
751
+ layoutMetricsWithOverflowInset.overflowInset * childTransform));
752
+ contentFrame.unionInPlace(outsetBy(
753
+ layoutMetricsWithOverflowInset.frame * childTransform, hitSlop));
754
+ }
755
+ }
756
+ }
757
+
758
+ if (yogaNode_.getStyle().overflow() == YGOverflowVisible) {
759
+ // Note that the parent node's overflow layout is NOT affected by its
760
+ // transform matrix. That transform matrix is applied on the parent node as
761
+ // well as all of its child nodes, which won't cause changes on the
762
+ // overflowInset values. A special note on the scale transform -- the scaled
763
+ // layout may look like it's causing overflowInset changes, but it's purely
764
+ // cosmetic and will be handled by pixel density conversion logic later when
765
+ // render the view. The actual overflowInset value is not changed as if the
766
+ // transform is not happening here.
767
+ layoutMetrics_.overflowInset =
768
+ calculateOverflowInset(layoutMetrics_.frame, contentFrame);
769
+ } else {
770
+ layoutMetrics_.overflowInset = {};
771
+ }
772
+ }
773
+
774
+ #pragma mark - Yoga Connectors
775
+
776
+ YGNode *YogaLayoutableShadowNode::yogaNodeCloneCallbackConnector(
777
+ YGNode * /*oldYogaNode*/,
778
+ YGNode *parentYogaNode,
779
+ int childIndex) {
780
+ SystraceSection s("YogaLayoutableShadowNode::yogaNodeCloneCallbackConnector");
781
+
782
+ auto &parentNode = shadowNodeFromContext(parentYogaNode);
783
+ return &parentNode.cloneChildInPlace(childIndex).yogaNode_;
784
+ }
785
+
786
+ YGSize YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector(
787
+ YGNode *yogaNode,
788
+ float width,
789
+ YGMeasureMode widthMode,
790
+ float height,
791
+ YGMeasureMode heightMode) {
792
+ SystraceSection s(
793
+ "YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector");
794
+
795
+ auto &shadowNode = shadowNodeFromContext(yogaNode);
796
+
797
+ auto minimumSize = Size{0, 0};
798
+ auto maximumSize = Size{
799
+ std::numeric_limits<Float>::infinity(),
800
+ std::numeric_limits<Float>::infinity()};
801
+
802
+ switch (widthMode) {
803
+ case YGMeasureModeUndefined:
804
+ break;
805
+ case YGMeasureModeExactly:
806
+ minimumSize.width = floatFromYogaFloat(width);
807
+ maximumSize.width = floatFromYogaFloat(width);
808
+ break;
809
+ case YGMeasureModeAtMost:
810
+ maximumSize.width = floatFromYogaFloat(width);
811
+ break;
812
+ }
813
+
814
+ switch (heightMode) {
815
+ case YGMeasureModeUndefined:
816
+ break;
817
+ case YGMeasureModeExactly:
818
+ minimumSize.height = floatFromYogaFloat(height);
819
+ maximumSize.height = floatFromYogaFloat(height);
820
+ break;
821
+ case YGMeasureModeAtMost:
822
+ maximumSize.height = floatFromYogaFloat(height);
823
+ break;
824
+ }
825
+
826
+ auto size = shadowNode.measureContent(
827
+ threadLocalLayoutContext, {minimumSize, maximumSize});
828
+
829
+ return YGSize{
830
+ yogaFloatFromFloat(size.width), yogaFloatFromFloat(size.height)};
831
+ }
832
+
833
+ YogaLayoutableShadowNode &YogaLayoutableShadowNode::shadowNodeFromContext(
834
+ YGNode *yogaNode) {
835
+ return traitCast<YogaLayoutableShadowNode &>(
836
+ *static_cast<ShadowNode *>(yogaNode->getContext()));
837
+ }
838
+
839
+ YGConfig &YogaLayoutableShadowNode::initializeYogaConfig(
840
+ YGConfig &config,
841
+ const YGConfigRef previousConfig) {
842
+ YGConfigSetCloneNodeFunc(
843
+ &config, YogaLayoutableShadowNode::yogaNodeCloneCallbackConnector);
844
+ if (previousConfig != nullptr) {
845
+ YGConfigSetPointScaleFactor(
846
+ &config, YGConfigGetPointScaleFactor(previousConfig));
847
+ YGConfigSetErrata(&config, YGConfigGetErrata(previousConfig));
848
+ }
849
+
850
+ #ifdef RN_DEBUG_YOGA_LOGGER
851
+ YGConfigSetPrintTreeFlag(&config, true);
852
+ #endif
853
+ return config;
854
+ }
855
+
856
+ #pragma mark - RTL left and right swapping
857
+
858
+ void YogaLayoutableShadowNode::swapStyleLeftAndRight() {
859
+ ensureUnsealed();
860
+
861
+ swapLeftAndRightInYogaStyleProps(*this);
862
+ swapLeftAndRightInViewProps(*this);
863
+ }
864
+
865
+ void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps(
866
+ YogaLayoutableShadowNode const &shadowNode) {
867
+ auto yogaStyle = shadowNode.yogaNode_.getStyle();
868
+
869
+ YGStyle::Edges const &position = yogaStyle.position();
870
+ YGStyle::Edges const &padding = yogaStyle.padding();
871
+ YGStyle::Edges const &margin = yogaStyle.margin();
872
+
873
+ // Swap Yoga node values, position, padding and margin.
874
+
875
+ if (yogaStyle.position()[YGEdgeLeft] != YGValueUndefined) {
876
+ yogaStyle.position()[YGEdgeStart] = position[YGEdgeLeft];
877
+ yogaStyle.position()[YGEdgeLeft] = YGValueUndefined;
878
+ }
879
+
880
+ if (yogaStyle.position()[YGEdgeRight] != YGValueUndefined) {
881
+ yogaStyle.position()[YGEdgeEnd] = position[YGEdgeRight];
882
+ yogaStyle.position()[YGEdgeRight] = YGValueUndefined;
883
+ }
884
+
885
+ if (yogaStyle.padding()[YGEdgeLeft] != YGValueUndefined) {
886
+ yogaStyle.padding()[YGEdgeStart] = padding[YGEdgeLeft];
887
+ yogaStyle.padding()[YGEdgeLeft] = YGValueUndefined;
888
+ }
889
+
890
+ if (yogaStyle.padding()[YGEdgeRight] != YGValueUndefined) {
891
+ yogaStyle.padding()[YGEdgeEnd] = padding[YGEdgeRight];
892
+ yogaStyle.padding()[YGEdgeRight] = YGValueUndefined;
893
+ }
894
+
895
+ if (yogaStyle.margin()[YGEdgeLeft] != YGValueUndefined) {
896
+ yogaStyle.margin()[YGEdgeStart] = margin[YGEdgeLeft];
897
+ yogaStyle.margin()[YGEdgeLeft] = YGValueUndefined;
898
+ }
899
+
900
+ if (yogaStyle.margin()[YGEdgeRight] != YGValueUndefined) {
901
+ yogaStyle.margin()[YGEdgeEnd] = margin[YGEdgeRight];
902
+ yogaStyle.margin()[YGEdgeRight] = YGValueUndefined;
903
+ }
904
+
905
+ shadowNode.yogaNode_.setStyle(yogaStyle);
906
+ }
907
+
908
+ void YogaLayoutableShadowNode::swapLeftAndRightInViewProps(
909
+ YogaLayoutableShadowNode const &shadowNode) {
910
+ auto &typedCasting = static_cast<ViewProps const &>(*shadowNode.props_);
911
+ auto &props = const_cast<ViewProps &>(typedCasting);
912
+
913
+ // Swap border node values, borderRadii, borderColors and borderStyles.
914
+
915
+ if (props.borderRadii.topLeft.has_value()) {
916
+ props.borderRadii.topStart = props.borderRadii.topLeft;
917
+ props.borderRadii.topLeft.reset();
918
+ }
919
+
920
+ if (props.borderRadii.bottomLeft.has_value()) {
921
+ props.borderRadii.bottomStart = props.borderRadii.bottomLeft;
922
+ props.borderRadii.bottomLeft.reset();
923
+ }
924
+
925
+ if (props.borderRadii.topRight.has_value()) {
926
+ props.borderRadii.topEnd = props.borderRadii.topRight;
927
+ props.borderRadii.topRight.reset();
928
+ }
929
+
930
+ if (props.borderRadii.bottomRight.has_value()) {
931
+ props.borderRadii.bottomEnd = props.borderRadii.bottomRight;
932
+ props.borderRadii.bottomRight.reset();
933
+ }
934
+
935
+ if (props.borderColors.left.has_value()) {
936
+ props.borderColors.start = props.borderColors.left;
937
+ props.borderColors.left.reset();
938
+ }
939
+
940
+ if (props.borderColors.right.has_value()) {
941
+ props.borderColors.end = props.borderColors.right;
942
+ props.borderColors.right.reset();
943
+ }
944
+
945
+ if (props.borderStyles.left.has_value()) {
946
+ props.borderStyles.start = props.borderStyles.left;
947
+ props.borderStyles.left.reset();
948
+ }
949
+
950
+ if (props.borderStyles.right.has_value()) {
951
+ props.borderStyles.end = props.borderStyles.right;
952
+ props.borderStyles.right.reset();
953
+ }
954
+
955
+ YGStyle::Edges const &border = props.yogaStyle.border();
956
+
957
+ if (props.yogaStyle.border()[YGEdgeLeft] != YGValueUndefined) {
958
+ props.yogaStyle.border()[YGEdgeStart] = border[YGEdgeLeft];
959
+ props.yogaStyle.border()[YGEdgeLeft] = YGValueUndefined;
960
+ }
961
+
962
+ if (props.yogaStyle.border()[YGEdgeRight] != YGValueUndefined) {
963
+ props.yogaStyle.border()[YGEdgeEnd] = border[YGEdgeRight];
964
+ props.yogaStyle.border()[YGEdgeRight] = YGValueUndefined;
965
+ }
966
+ }
967
+
968
+ #pragma mark - Consistency Ensuring Helpers
969
+
970
+ void YogaLayoutableShadowNode::ensureConsistency() const {
971
+ ensureYogaChildrenLookFine();
972
+ ensureYogaChildrenAlignment();
973
+ }
974
+
975
+ void YogaLayoutableShadowNode::ensureYogaChildrenLookFine() const {
976
+ #ifdef REACT_NATIVE_DEBUG
977
+ // Checking that the shapes of Yoga node children object look fine.
978
+ // This is the only heuristic that might produce false-positive results
979
+ // (really broken dangled nodes might look fine). This is useful as an early
980
+ // signal that something went wrong.
981
+ auto &yogaChildren = yogaNode_.getChildren();
982
+
983
+ for (auto const &yogaChild : yogaChildren) {
984
+ react_native_assert(yogaChild->getContext());
985
+ react_native_assert(yogaChild->getChildren().size() < 16384);
986
+ if (!yogaChild->getChildren().empty()) {
987
+ react_native_assert(!yogaChild->hasMeasureFunc());
988
+ }
989
+ }
990
+ #endif
991
+ }
992
+
993
+ void YogaLayoutableShadowNode::ensureYogaChildrenAlignment() const {
994
+ #ifdef REACT_NATIVE_DEBUG
995
+ // If the node is not a leaf node, checking that:
996
+ // - All children are `YogaLayoutableShadowNode` subclasses.
997
+ // - All Yoga children are owned/connected to corresponding children of
998
+ // this node.
999
+
1000
+ auto &yogaChildren = yogaNode_.getChildren();
1001
+ auto &children = yogaLayoutableChildren_;
1002
+
1003
+ if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
1004
+ react_native_assert(yogaChildren.empty());
1005
+ return;
1006
+ }
1007
+
1008
+ react_native_assert(yogaChildren.size() == children.size());
1009
+
1010
+ for (size_t i = 0; i < children.size(); i++) {
1011
+ auto &yogaChild = yogaChildren.at(i);
1012
+ auto &child = children.at(i);
1013
+ react_native_assert(
1014
+ yogaChild->getContext() ==
1015
+ traitCast<YogaLayoutableShadowNode const *>(child.get()));
1016
+ }
1017
+ #endif
1018
+ }
1019
+
1020
+ } // namespace facebook::react