Skip to content

Commit

Permalink
C++ style enums 9/N: FlexDirection (#39484)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/yoga#1394

Pull Request resolved: #39484

Moves internal usages of YGDirection to Direction.

Changelog: [Internal]

Differential Revision: D49336066

fbshipit-source-id: 09b1165d8691becd14e196a259e87cb4736b4f19
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 18, 2023
1 parent 5fa07bf commit a844602
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,30 +193,30 @@ inline void fromRawValue(
inline void fromRawValue(
const PropsParserContext& context,
const RawValue& value,
YGFlexDirection& result) {
result = YGFlexDirectionColumn;
yoga::FlexDirection& result) {
result = yoga::FlexDirection::Column;
react_native_expect(value.hasType<std::string>());
if (!value.hasType<std::string>()) {
return;
}
auto stringValue = (std::string)value;
if (stringValue == "row") {
result = YGFlexDirectionRow;
result = yoga::FlexDirection::Row;
return;
}
if (stringValue == "column") {
result = YGFlexDirectionColumn;
result = yoga::FlexDirection::Column;
return;
}
if (stringValue == "column-reverse") {
result = YGFlexDirectionColumnReverse;
result = yoga::FlexDirection::ColumnReverse;
return;
}
if (stringValue == "row-reverse") {
result = YGFlexDirectionRowReverse;
result = yoga::FlexDirection::RowReverse;
return;
}
LOG(ERROR) << "Could not parse YGFlexDirection:" << stringValue;
LOG(ERROR) << "Could not parse yoga::FlexDirection:" << stringValue;
react_native_expect(false);
}

Expand Down Expand Up @@ -754,15 +754,15 @@ inline std::string toString(const yoga::Direction& value) {
}
}

inline std::string toString(const YGFlexDirection& value) {
inline std::string toString(const yoga::FlexDirection& value) {
switch (value) {
case YGFlexDirectionColumn:
case yoga::FlexDirection::Column:
return "column";
case YGFlexDirectionColumnReverse:
case yoga::FlexDirection::ColumnReverse:
return "column-reverse";
case YGFlexDirectionRow:
case yoga::FlexDirection::Row:
return "row";
case YGFlexDirectionRowReverse:
case yoga::FlexDirection::RowReverse:
return "row-reverse";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void HostPlatformViewProps::setProp(

bool HostPlatformViewProps::getProbablyMoreHorizontalThanVertical_DEPRECATED()
const {
return yogaStyle.flexDirection() == YGFlexDirectionRow;
return yogaStyle.flexDirection() == yoga::FlexDirection::Row;
}

#if RN_DEBUG_STRING_CONVERTIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class YogaDirtyFlagTest : public ::testing::Test {
props.nativeId = "native Id";
props.opacity = 0.5;
props.yogaStyle.alignContent() = YGAlignBaseline;
props.yogaStyle.flexDirection() = YGFlexDirectionRowReverse;
props.yogaStyle.flexDirection() = yoga::FlexDirection::RowReverse;
return mutableViewProps;
}),
Element<ViewShadowNode>()
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/ReactCommon/yoga/Yoga.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ Pod::Spec.new do |spec|
all_header_files = 'yoga/**/*.h'
all_header_files = File.join('ReactCommon/yoga', all_header_files) if ENV['INSTALL_YOGA_WITHOUT_PATH_OPTION']
spec.private_header_files = Dir.glob(all_header_files) - Dir.glob(public_header_files)
spec.preserve_paths = [all_header_files]
end
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ void YGNodeStyleSetFlexDirection(
const YGNodeRef node,
const YGFlexDirection flexDirection) {
updateStyle<MSVC_HINT(flexDirection)>(
node, &Style::flexDirection, flexDirection);
node, &Style::flexDirection, scopedEnum(flexDirection));
}
YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().flexDirection();
return unscopedEnum(resolveRef(node)->getStyle().flexDirection());
}

void YGNodeStyleSetJustifyContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <yoga/algorithm/FlexDirection.h>
#include <yoga/algorithm/ResolveValue.h>
#include <yoga/enums/FlexDirection.h>
#include <yoga/node/Node.h>
#include <yoga/numeric/Comparison.h>
#include <yoga/numeric/FloatOptional.h>
Expand All @@ -17,7 +18,7 @@ namespace facebook::yoga {

inline float paddingAndBorderForAxis(
const yoga::Node* const node,
const YGFlexDirection axis,
const FlexDirection axis,
const float widthSize) {
return (node->getLeadingPaddingAndBorder(axis, widthSize) +
node->getTrailingPaddingAndBorder(axis, widthSize))
Expand All @@ -26,7 +27,7 @@ inline float paddingAndBorderForAxis(

inline FloatOptional boundAxisWithinMinAndMax(
const yoga::Node* const node,
const YGFlexDirection axis,
const FlexDirection axis,
const FloatOptional value,
const float axisSize) {
FloatOptional min;
Expand Down Expand Up @@ -59,7 +60,7 @@ inline FloatOptional boundAxisWithinMinAndMax(
// go below the padding and border amount.
inline float boundAxis(
const yoga::Node* const node,
const YGFlexDirection axis,
const FlexDirection axis,
const float value,
const float axisSize,
const float widthSize) {
Expand Down
Loading

0 comments on commit a844602

Please sign in to comment.