Skip to content

Commit 0e4a3da

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
yoga::Node::getStyle() to yoga::Node::style() (#42314)
Summary: Pull Request resolved: #42314 X-link: facebook/yoga#1555 The next diff moves a bunch of methods to `yoga::Style`. This renames the function to be a tad bit shorter, for more readable callsites. It also makes it more consistent with style property getters. Changelog: [Internal] Reviewed By: rozele Differential Revision: D52803393 fbshipit-source-id: 557df34a9f0fb0ee42ad23b1fda99c1e0eb1d4e3
1 parent 9bd69d3 commit 0e4a3da

File tree

12 files changed

+133
-134
lines changed

12 files changed

+133
-134
lines changed

packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void YogaLayoutableShadowNode::updateYogaChildren() {
360360
yogaLayoutableChildren_.at(yogaChildIndex)->yogaNode_;
361361

362362
isClean = isClean && !newYogaChildNode.isDirty() &&
363-
(newYogaChildNode.getStyle() == oldYogaChildNode.getStyle());
363+
(newYogaChildNode.style() == oldYogaChildNode.style());
364364
}
365365
}
366366
}
@@ -378,7 +378,7 @@ void YogaLayoutableShadowNode::updateYogaProps() {
378378
auto styleResult = applyAliasedProps(props.yogaStyle, props);
379379

380380
// Resetting `dirty` flag only if `yogaStyle` portion of `Props` was changed.
381-
if (!yogaNode_.isDirty() && (styleResult != yogaNode_.getStyle())) {
381+
if (!yogaNode_.isDirty() && (styleResult != yogaNode_.style())) {
382382
yogaNode_.setDirty(true);
383383
}
384384

@@ -532,7 +532,7 @@ YogaLayoutableShadowNode& YogaLayoutableShadowNode::cloneChildInPlace(
532532
void YogaLayoutableShadowNode::setSize(Size size) const {
533533
ensureUnsealed();
534534

535-
auto style = yogaNode_.getStyle();
535+
auto style = yogaNode_.style();
536536
style.setDimension(yoga::Dimension::Width, yoga::value::points(size.width));
537537
style.setDimension(yoga::Dimension::Height, yoga::value::points(size.height));
538538
yogaNode_.setStyle(style);
@@ -542,7 +542,7 @@ void YogaLayoutableShadowNode::setSize(Size size) const {
542542
void YogaLayoutableShadowNode::setPadding(RectangleEdges<Float> padding) const {
543543
ensureUnsealed();
544544

545-
auto style = yogaNode_.getStyle();
545+
auto style = yogaNode_.style();
546546

547547
auto leftPadding = yoga::value::points(padding.left);
548548
auto topPadding = yoga::value::points(padding.top);
@@ -566,7 +566,7 @@ void YogaLayoutableShadowNode::setPositionType(
566566
YGPositionType positionType) const {
567567
ensureUnsealed();
568568

569-
auto style = yogaNode_.getStyle();
569+
auto style = yogaNode_.style();
570570
style.setPositionType(yoga::scopedEnum(positionType));
571571
yogaNode_.setStyle(style);
572572
yogaNode_.setDirty(true);
@@ -617,7 +617,7 @@ void YogaLayoutableShadowNode::layoutTree(
617617
// `ownerHeight` to allow proper calculation of relative (e.g. specified in
618618
// percents) style values.
619619

620-
auto& yogaStyle = yogaNode_.getStyle();
620+
auto& yogaStyle = yogaNode_.style();
621621

622622
auto ownerWidth = yogaFloatFromFloat(maximumSize.width);
623623
auto ownerHeight = yogaFloatFromFloat(maximumSize.height);
@@ -717,7 +717,7 @@ void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
717717
}
718718
}
719719

720-
if (yogaNode_.getStyle().overflow() == yoga::Overflow::Visible) {
720+
if (yogaNode_.style().overflow() == yoga::Overflow::Visible) {
721721
// Note that the parent node's overflow layout is NOT affected by its
722722
// transform matrix. That transform matrix is applied on the parent node as
723723
// well as all of its child nodes, which won't cause changes on the
@@ -869,7 +869,7 @@ void YogaLayoutableShadowNode::swapStyleLeftAndRight() {
869869

870870
void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps(
871871
const YogaLayoutableShadowNode& shadowNode) {
872-
auto yogaStyle = shadowNode.yogaNode_.getStyle();
872+
auto yogaStyle = shadowNode.yogaNode_.style();
873873

874874
// Swap Yoga node values, position, padding and margin.
875875

packages/react-native/ReactCommon/react/renderer/components/view/conversions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ inline LayoutMetrics layoutMetricsFromYogaNode(yoga::Node& yogaNode) {
138138
layoutMetrics.borderWidth.bottom +
139139
floatFromYogaFloat(YGNodeLayoutGetPadding(&yogaNode, YGEdgeBottom))};
140140

141-
layoutMetrics.displayType =
142-
yogaNode.getStyle().display() == yoga::Display::None ? DisplayType::None
143-
: DisplayType::Flex;
141+
layoutMetrics.displayType = yogaNode.style().display() == yoga::Display::None
142+
? DisplayType::None
143+
: DisplayType::Flex;
144144

145145
layoutMetrics.positionType =
146-
positionTypeFromYogaPositionType(yogaNode.getStyle().positionType());
146+
positionTypeFromYogaPositionType(yogaNode.style().positionType());
147147

148148
layoutMetrics.layoutDirection =
149149
YGNodeLayoutGetDirection(&yogaNode) == YGDirectionRTL

packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace {
1616

1717
template <auto GetterT, auto SetterT, typename ValueT>
1818
void updateStyle(YGNodeRef node, ValueT value) {
19-
auto& style = resolveRef(node)->getStyle();
19+
auto& style = resolveRef(node)->style();
2020
if ((style.*GetterT)() != value) {
2121
(style.*SetterT)(value);
2222
resolveRef(node)->markDirtyAndPropagate();
@@ -25,7 +25,7 @@ void updateStyle(YGNodeRef node, ValueT value) {
2525

2626
template <auto GetterT, auto SetterT, typename IdxT, typename ValueT>
2727
void updateStyle(YGNodeRef node, IdxT idx, ValueT value) {
28-
auto& style = resolveRef(node)->getStyle();
28+
auto& style = resolveRef(node)->style();
2929
if ((style.*GetterT)(idx) != value) {
3030
(style.*SetterT)(idx, value);
3131
resolveRef(node)->markDirtyAndPropagate();
@@ -40,8 +40,8 @@ void YGNodeCopyStyle(
4040
auto dstNode = resolveRef(dstNodeRef);
4141
auto srcNode = resolveRef(srcNodeRef);
4242

43-
if (!(dstNode->getStyle() == srcNode->getStyle())) {
44-
dstNode->setStyle(srcNode->getStyle());
43+
if (!(dstNode->style() == srcNode->style())) {
44+
dstNode->setStyle(srcNode->style());
4545
dstNode->markDirtyAndPropagate();
4646
}
4747
}
@@ -51,7 +51,7 @@ void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) {
5151
}
5252

5353
YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
54-
return unscopedEnum(resolveRef(node)->getStyle().direction());
54+
return unscopedEnum(resolveRef(node)->style().direction());
5555
}
5656

5757
void YGNodeStyleSetFlexDirection(
@@ -62,7 +62,7 @@ void YGNodeStyleSetFlexDirection(
6262
}
6363

6464
YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
65-
return unscopedEnum(resolveRef(node)->getStyle().flexDirection());
65+
return unscopedEnum(resolveRef(node)->style().flexDirection());
6666
}
6767

6868
void YGNodeStyleSetJustifyContent(
@@ -73,7 +73,7 @@ void YGNodeStyleSetJustifyContent(
7373
}
7474

7575
YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
76-
return unscopedEnum(resolveRef(node)->getStyle().justifyContent());
76+
return unscopedEnum(resolveRef(node)->style().justifyContent());
7777
}
7878

7979
void YGNodeStyleSetAlignContent(
@@ -84,7 +84,7 @@ void YGNodeStyleSetAlignContent(
8484
}
8585

8686
YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
87-
return unscopedEnum(resolveRef(node)->getStyle().alignContent());
87+
return unscopedEnum(resolveRef(node)->style().alignContent());
8888
}
8989

9090
void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) {
@@ -93,7 +93,7 @@ void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) {
9393
}
9494

9595
YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
96-
return unscopedEnum(resolveRef(node)->getStyle().alignItems());
96+
return unscopedEnum(resolveRef(node)->style().alignItems());
9797
}
9898

9999
void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) {
@@ -102,7 +102,7 @@ void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) {
102102
}
103103

104104
YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
105-
return unscopedEnum(resolveRef(node)->getStyle().alignSelf());
105+
return unscopedEnum(resolveRef(node)->style().alignSelf());
106106
}
107107

108108
void YGNodeStyleSetPositionType(
@@ -113,7 +113,7 @@ void YGNodeStyleSetPositionType(
113113
}
114114

115115
YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) {
116-
return unscopedEnum(resolveRef(node)->getStyle().positionType());
116+
return unscopedEnum(resolveRef(node)->style().positionType());
117117
}
118118

119119
void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) {
@@ -122,7 +122,7 @@ void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) {
122122
}
123123

124124
YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
125-
return unscopedEnum(resolveRef(node)->getStyle().flexWrap());
125+
return unscopedEnum(resolveRef(node)->style().flexWrap());
126126
}
127127

128128
void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) {
@@ -131,15 +131,15 @@ void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) {
131131
}
132132

133133
YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
134-
return unscopedEnum(resolveRef(node)->getStyle().overflow());
134+
return unscopedEnum(resolveRef(node)->style().overflow());
135135
}
136136

137137
void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) {
138138
updateStyle<&Style::display, &Style::setDisplay>(node, scopedEnum(display));
139139
}
140140

141141
YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
142-
return unscopedEnum(resolveRef(node)->getStyle().display());
142+
return unscopedEnum(resolveRef(node)->style().display());
143143
}
144144

145145
void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
@@ -148,9 +148,8 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
148148

149149
float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
150150
const auto node = resolveRef(nodeRef);
151-
return node->getStyle().flex().isUndefined()
152-
? YGUndefined
153-
: node->getStyle().flex().unwrap();
151+
return node->style().flex().isUndefined() ? YGUndefined
152+
: node->style().flex().unwrap();
154153
}
155154

156155
void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
@@ -160,9 +159,9 @@ void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
160159

161160
float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) {
162161
const auto node = resolveRef(nodeRef);
163-
return node->getStyle().flexGrow().isUndefined()
162+
return node->style().flexGrow().isUndefined()
164163
? Style::DefaultFlexGrow
165-
: node->getStyle().flexGrow().unwrap();
164+
: node->style().flexGrow().unwrap();
166165
}
167166

168167
void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
@@ -172,10 +171,10 @@ void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
172171

173172
float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
174173
const auto node = resolveRef(nodeRef);
175-
return node->getStyle().flexShrink().isUndefined()
174+
return node->style().flexShrink().isUndefined()
176175
? (node->getConfig()->useWebDefaults() ? Style::WebDefaultFlexShrink
177176
: Style::DefaultFlexShrink)
178-
: node->getStyle().flexShrink().unwrap();
177+
: node->style().flexShrink().unwrap();
179178
}
180179

181180
void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
@@ -195,7 +194,7 @@ void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
195194
}
196195

197196
YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
198-
return (YGValue)resolveRef(node)->getStyle().flexBasis();
197+
return (YGValue)resolveRef(node)->style().flexBasis();
199198
}
200199

201200
void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) {
@@ -209,7 +208,7 @@ void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) {
209208
}
210209

211210
YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
212-
return (YGValue)resolveRef(node)->getStyle().position(scopedEnum(edge));
211+
return (YGValue)resolveRef(node)->style().position(scopedEnum(edge));
213212
}
214213

215214
void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
@@ -228,7 +227,7 @@ void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
228227
}
229228

230229
YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
231-
return (YGValue)resolveRef(node)->getStyle().margin(scopedEnum(edge));
230+
return (YGValue)resolveRef(node)->style().margin(scopedEnum(edge));
232231
}
233232

234233
void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
@@ -242,7 +241,7 @@ void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
242241
}
243242

244243
YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
245-
return (YGValue)resolveRef(node)->getStyle().padding(scopedEnum(edge));
244+
return (YGValue)resolveRef(node)->style().padding(scopedEnum(edge));
246245
}
247246

248247
void YGNodeStyleSetBorder(
@@ -254,7 +253,7 @@ void YGNodeStyleSetBorder(
254253
}
255254

256255
float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
257-
auto border = resolveRef(node)->getStyle().border(scopedEnum(edge));
256+
auto border = resolveRef(node)->style().border(scopedEnum(edge));
258257
if (border.isUndefined() || border.isAuto()) {
259258
return YGUndefined;
260259
}
@@ -271,7 +270,7 @@ void YGNodeStyleSetGap(
271270
}
272271

273272
float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
274-
auto gapLength = resolveRef(node)->getStyle().gap(scopedEnum(gutter));
273+
auto gapLength = resolveRef(node)->style().gap(scopedEnum(gutter));
275274
if (gapLength.isUndefined() || gapLength.isAuto()) {
276275
return YGUndefined;
277276
}
@@ -285,7 +284,7 @@ void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
285284
}
286285

287286
float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
288-
const FloatOptional op = resolveRef(node)->getStyle().aspectRatio();
287+
const FloatOptional op = resolveRef(node)->style().aspectRatio();
289288
return op.isUndefined() ? YGUndefined : op.unwrap();
290289
}
291290

@@ -305,7 +304,7 @@ void YGNodeStyleSetWidthAuto(YGNodeRef node) {
305304
}
306305

307306
YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
308-
return (YGValue)resolveRef(node)->getStyle().dimension(Dimension::Width);
307+
return (YGValue)resolveRef(node)->style().dimension(Dimension::Width);
309308
}
310309

311310
void YGNodeStyleSetHeight(YGNodeRef node, float points) {
@@ -324,7 +323,7 @@ void YGNodeStyleSetHeightAuto(YGNodeRef node) {
324323
}
325324

326325
YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
327-
return (YGValue)resolveRef(node)->getStyle().dimension(Dimension::Height);
326+
return (YGValue)resolveRef(node)->style().dimension(Dimension::Height);
328327
}
329328

330329
void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
@@ -338,7 +337,7 @@ void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
338337
}
339338

340339
YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
341-
return (YGValue)resolveRef(node)->getStyle().minDimension(Dimension::Width);
340+
return (YGValue)resolveRef(node)->style().minDimension(Dimension::Width);
342341
}
343342

344343
void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
@@ -354,7 +353,7 @@ void YGNodeStyleSetMinHeightPercent(
354353
}
355354

356355
YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
357-
return (YGValue)resolveRef(node)->getStyle().minDimension(Dimension::Height);
356+
return (YGValue)resolveRef(node)->style().minDimension(Dimension::Height);
358357
}
359358

360359
void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
@@ -368,7 +367,7 @@ void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
368367
}
369368

370369
YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
371-
return (YGValue)resolveRef(node)->getStyle().maxDimension(Dimension::Width);
370+
return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Width);
372371
}
373372

374373
void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
@@ -384,5 +383,5 @@ void YGNodeStyleSetMaxHeightPercent(
384383
}
385384

386385
YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
387-
return (YGValue)resolveRef(node)->getStyle().maxDimension(Dimension::Height);
386+
return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Height);
388387
}

0 commit comments

Comments
 (0)