From b9991d33e323f59af4071cb2c42ed411d89354b3 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Tue, 20 Feb 2018 05:41:48 -0800 Subject: [PATCH] Move YGStyle to seperate file and add constructors Reviewed By: emilsjolander Differential Revision: D7016575 fbshipit-source-id: eb28df0ffb4cc813b23edaff80d7d4ebc56ce6af --- React/React.xcodeproj/project.pbxproj | 12 ++ ReactCommon/yoga/yoga/YGNode.cpp | 2 +- ReactCommon/yoga/yoga/YGNode.h | 2 +- ReactCommon/yoga/yoga/YGStyle.cpp | 78 ++++++++++++ ReactCommon/yoga/yoga/YGStyle.h | 43 +++++++ ReactCommon/yoga/yoga/Yoga-internal.h | 170 +++----------------------- scripts/.packager.env | 1 + 7 files changed, 153 insertions(+), 155 deletions(-) create mode 100644 ReactCommon/yoga/yoga/YGStyle.cpp create mode 100644 ReactCommon/yoga/yoga/YGStyle.h create mode 100644 scripts/.packager.env diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 4d9c41ed1..539f62fc6 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -952,6 +952,10 @@ 3DFE0D1C1DF8575800459392 /* Yoga.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 130A77081DF767AF001F9587 /* Yoga.h */; }; 3EDCA8A51D3591E700450C31 /* RCTErrorInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */; }; 5335D5411FE81A4700883D58 /* RCTShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5335D5401FE81A4700883D58 /* RCTShadowView.m */; }; + 5352C5752038FF9500A3B97E /* YGStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5352C5722038FF8D00A3B97E /* YGStyle.cpp */; }; + 5352C5762038FF9700A3B97E /* YGStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5352C5722038FF8D00A3B97E /* YGStyle.cpp */; }; + 5352C5772038FF9A00A3B97E /* YGStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 5352C5712038FF8D00A3B97E /* YGStyle.h */; }; + 5352C5782038FF9B00A3B97E /* YGStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 5352C5712038FF8D00A3B97E /* YGStyle.h */; }; 53756E3B2004FFFA00FBBD99 /* Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53756E372004FFF700FBBD99 /* Utils.cpp */; }; 53756E3C2004FFFC00FBBD99 /* Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 53756E382004FFF700FBBD99 /* Utils.h */; }; 53756E3D2004FFFE00FBBD99 /* Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 53756E382004FFF700FBBD99 /* Utils.h */; }; @@ -2144,6 +2148,8 @@ 3EDCA8A31D3591E700450C31 /* RCTErrorInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTErrorInfo.h; sourceTree = ""; }; 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTErrorInfo.m; sourceTree = ""; }; 5335D5401FE81A4700883D58 /* RCTShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowView.m; sourceTree = ""; }; + 5352C5712038FF8D00A3B97E /* YGStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGStyle.h; sourceTree = ""; }; + 5352C5722038FF8D00A3B97E /* YGStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGStyle.cpp; sourceTree = ""; }; 53756E372004FFF700FBBD99 /* Utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Utils.cpp; sourceTree = ""; }; 53756E382004FFF700FBBD99 /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utils.h; sourceTree = ""; }; 5376C5E01FC6DDB20083513D /* YGNodePrint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNodePrint.h; sourceTree = ""; }; @@ -2332,6 +2338,8 @@ 130A77021DF767AF001F9587 /* yoga */ = { isa = PBXGroup; children = ( + 5352C5722038FF8D00A3B97E /* YGStyle.cpp */, + 5352C5712038FF8D00A3B97E /* YGStyle.h */, 53756E372004FFF700FBBD99 /* Utils.cpp */, 53756E382004FFF700FBBD99 /* Utils.h */, 53EC85DF1FDEC75A0051B2B5 /* YGNode.cpp */, @@ -3268,6 +3276,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 5352C5782038FF9B00A3B97E /* YGStyle.h in Headers */, 53EC85E41FDEC7630051B2B5 /* YGNode.h in Headers */, 53D1239F1FBF1EFB001B8A10 /* Yoga-internal.h in Headers */, 3DFE0D161DF8574D00459392 /* YGEnums.h in Headers */, @@ -3346,6 +3355,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 5352C5772038FF9A00A3B97E /* YGStyle.h in Headers */, 53EC85E51FDEC7630051B2B5 /* YGNode.h in Headers */, 53D1239E1FBF1EFB001B8A10 /* Yoga-internal.h in Headers */, 133957881DF76D3500EC27BE /* YGEnums.h in Headers */, @@ -4292,6 +4302,7 @@ buildActionMask = 2147483647; files = ( 53D123A01FBF1EFF001B8A10 /* Yoga.cpp in Sources */, + 5352C5752038FF9500A3B97E /* YGStyle.cpp in Sources */, 53EC85E21FDEC75F0051B2B5 /* YGNode.cpp in Sources */, 53D1239A1FBF1EF2001B8A10 /* YGEnums.cpp in Sources */, 53756E3B2004FFFA00FBBD99 /* Utils.cpp in Sources */, @@ -4304,6 +4315,7 @@ buildActionMask = 2147483647; files = ( 53D123A11FBF1EFF001B8A10 /* Yoga.cpp in Sources */, + 5352C5762038FF9700A3B97E /* YGStyle.cpp in Sources */, 53EC85E31FDEC75F0051B2B5 /* YGNode.cpp in Sources */, 53D1239B1FBF1EF4001B8A10 /* YGEnums.cpp in Sources */, 53756E3E2005000300FBBD99 /* Utils.cpp in Sources */, diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index 56ce1b492..24a00a883 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -382,7 +382,7 @@ YGNode::YGNode() measure_(nullptr), baseline_(nullptr), dirtied_(nullptr), - style_(gYGNodeStyleDefaults), + style_(YGStyle()), layout_(gYGNodeLayoutDefaults), lineIndex_(0), parent_(nullptr), diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h index b3e312569..452b8f310 100644 --- a/ReactCommon/yoga/yoga/YGNode.h +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -7,7 +7,7 @@ #pragma once #include - +#include "YGStyle.h" #include "Yoga-internal.h" struct YGNode { diff --git a/ReactCommon/yoga/yoga/YGStyle.cpp b/ReactCommon/yoga/yoga/YGStyle.cpp new file mode 100644 index 000000000..516ce0618 --- /dev/null +++ b/ReactCommon/yoga/yoga/YGStyle.cpp @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#include "YGStyle.h" + +YGStyle::YGStyle() + : direction(YGDirectionInherit), + flexDirection(YGFlexDirectionColumn), + justifyContent(YGJustifyFlexStart), + alignContent(YGAlignFlexStart), + alignItems(YGAlignStretch), + alignSelf(YGAlignAuto), + positionType(YGPositionTypeRelative), + flexWrap(YGWrapNoWrap), + overflow(YGOverflowVisible), + display(YGDisplayFlex), + flex(YGUndefined), + flexGrow(YGUndefined), + flexShrink(YGUndefined), + flexBasis(kYGValueAuto), + margin(kYGDefaultEdgeValuesUnit), + position(kYGDefaultEdgeValuesUnit), + padding(kYGDefaultEdgeValuesUnit), + border(kYGDefaultEdgeValuesUnit), + dimensions(kYGDefaultDimensionValuesAutoUnit), + minDimensions(kYGDefaultDimensionValuesUnit), + maxDimensions(kYGDefaultDimensionValuesUnit), + aspectRatio(YGUndefined) {} + +// Yoga specific properties, not compatible with flexbox specification +bool YGStyle::operator==(const YGStyle& style) { + bool areNonFloatValuesEqual = direction == style.direction && + flexDirection == style.flexDirection && + justifyContent == style.justifyContent && + alignContent == style.alignContent && alignItems == style.alignItems && + alignSelf == style.alignSelf && positionType == style.positionType && + flexWrap == style.flexWrap && overflow == style.overflow && + display == style.display && YGValueEqual(flexBasis, style.flexBasis) && + YGValueArrayEqual(margin, style.margin) && + YGValueArrayEqual(position, style.position) && + YGValueArrayEqual(padding, style.padding) && + YGValueArrayEqual(border, style.border) && + YGValueArrayEqual(dimensions, style.dimensions) && + YGValueArrayEqual(minDimensions, style.minDimensions) && + YGValueArrayEqual(maxDimensions, style.maxDimensions); + + if (!(std::isnan(flex) && std::isnan(style.flex))) { + areNonFloatValuesEqual = areNonFloatValuesEqual && flex == style.flex; + } + + if (!(std::isnan(flexGrow) && std::isnan(style.flexGrow))) { + areNonFloatValuesEqual = + areNonFloatValuesEqual && flexGrow == style.flexGrow; + } + + if (!(std::isnan(flexShrink) && std::isnan(style.flexShrink))) { + areNonFloatValuesEqual = + areNonFloatValuesEqual && flexShrink == style.flexShrink; + } + + if (!(std::isnan(aspectRatio) && std::isnan(style.aspectRatio))) { + areNonFloatValuesEqual = + areNonFloatValuesEqual && aspectRatio == style.aspectRatio; + } + + return areNonFloatValuesEqual; +} + +bool YGStyle::operator!=(YGStyle style) { + return !(*this == style); +} + +YGStyle::~YGStyle() {} diff --git a/ReactCommon/yoga/yoga/YGStyle.h b/ReactCommon/yoga/yoga/YGStyle.h new file mode 100644 index 000000000..a95b4a297 --- /dev/null +++ b/ReactCommon/yoga/yoga/YGStyle.h @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#pragma once +#include "Yoga-internal.h" +#include "Yoga.h" + +struct YGStyle { + YGDirection direction; + YGFlexDirection flexDirection; + YGJustify justifyContent; + YGAlign alignContent; + YGAlign alignItems; + YGAlign alignSelf; + YGPositionType positionType; + YGWrap flexWrap; + YGOverflow overflow; + YGDisplay display; + float flex; + float flexGrow; + float flexShrink; + YGValue flexBasis; + std::array margin; + std::array position; + std::array padding; + std::array border; + std::array dimensions; + std::array minDimensions; + std::array maxDimensions; + float aspectRatio; + + YGStyle(); + // Yoga specific properties, not compatible with flexbox specification + bool operator==(const YGStyle& style); + + bool operator!=(YGStyle style); + ~YGStyle(); +}; diff --git a/ReactCommon/yoga/yoga/Yoga-internal.h b/ReactCommon/yoga/yoga/Yoga-internal.h index 6432e6cfc..b1bb0de3d 100644 --- a/ReactCommon/yoga/yoga/Yoga-internal.h +++ b/ReactCommon/yoga/yoga/Yoga-internal.h @@ -10,7 +10,6 @@ #include #include #include - #include "Yoga.h" using YGVector = std::vector; @@ -42,6 +41,23 @@ bool YGValueArrayEqual( return areEqual; } +const YGValue kYGValueUndefined = {YGUndefined, YGUnitUndefined}; +const YGValue kYGValueAuto = {YGUndefined, YGUnitAuto}; +const std::array kYGDefaultEdgeValuesUnit = { + {kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined}}; +const std::array kYGDefaultDimensionValuesAutoUnit = { + {kYGValueAuto, kYGValueAuto}}; +const std::array kYGDefaultDimensionValuesUnit = { + {kYGValueUndefined, kYGValueUndefined}}; + struct YGCachedMeasurement { float availableWidth; float availableHeight; @@ -141,74 +157,6 @@ struct YGLayout { } }; -struct YGStyle { - YGDirection direction; - YGFlexDirection flexDirection; - YGJustify justifyContent; - YGAlign alignContent; - YGAlign alignItems; - YGAlign alignSelf; - YGPositionType positionType; - YGWrap flexWrap; - YGOverflow overflow; - YGDisplay display; - float flex; - float flexGrow; - float flexShrink; - YGValue flexBasis; - std::array margin; - std::array position; - std::array padding; - std::array border; - std::array dimensions; - std::array minDimensions; - std::array maxDimensions; - - // Yoga specific properties, not compatible with flexbox specification - float aspectRatio; - bool operator==(YGStyle style) { - bool areNonFloatValuesEqual = direction == style.direction && - flexDirection == style.flexDirection && - justifyContent == style.justifyContent && - alignContent == style.alignContent && alignItems == style.alignItems && - alignSelf == style.alignSelf && positionType == style.positionType && - flexWrap == style.flexWrap && overflow == style.overflow && - display == style.display && YGValueEqual(flexBasis, style.flexBasis) && - YGValueArrayEqual(margin, style.margin) && - YGValueArrayEqual(position, style.position) && - YGValueArrayEqual(padding, style.padding) && - YGValueArrayEqual(border, style.border) && - YGValueArrayEqual(dimensions, style.dimensions) && - YGValueArrayEqual(minDimensions, style.minDimensions) && - YGValueArrayEqual(maxDimensions, style.maxDimensions); - - if (!(std::isnan(flex) && std::isnan(style.flex))) { - areNonFloatValuesEqual = areNonFloatValuesEqual && flex == style.flex; - } - - if (!(std::isnan(flexGrow) && std::isnan(style.flexGrow))) { - areNonFloatValuesEqual = - areNonFloatValuesEqual && flexGrow == style.flexGrow; - } - - if (!(std::isnan(flexShrink) && std::isnan(style.flexShrink))) { - areNonFloatValuesEqual = - areNonFloatValuesEqual && flexShrink == style.flexShrink; - } - - if (!(std::isnan(aspectRatio) && std::isnan(style.aspectRatio))) { - areNonFloatValuesEqual = - areNonFloatValuesEqual && aspectRatio == style.aspectRatio; - } - - return areNonFloatValuesEqual; - } - - bool operator!=(YGStyle style) { - return !(*this == style); - } -}; - struct YGConfig { bool experimentalFeatures[YGExperimentalFeatureCount + 1]; bool useWebDefaults; @@ -220,94 +168,10 @@ struct YGConfig { void* context; }; -#define YG_UNDEFINED_VALUES \ - { .value = YGUndefined, .unit = YGUnitUndefined } - -#define YG_AUTO_VALUES \ - { .value = YGUndefined, .unit = YGUnitAuto } - -#define YG_DEFAULT_EDGE_VALUES_UNIT \ - { \ - [YGEdgeLeft] = YG_UNDEFINED_VALUES, [YGEdgeTop] = YG_UNDEFINED_VALUES, \ - [YGEdgeRight] = YG_UNDEFINED_VALUES, [YGEdgeBottom] = YG_UNDEFINED_VALUES, \ - [YGEdgeStart] = YG_UNDEFINED_VALUES, [YGEdgeEnd] = YG_UNDEFINED_VALUES, \ - [YGEdgeHorizontal] = YG_UNDEFINED_VALUES, \ - [YGEdgeVertical] = YG_UNDEFINED_VALUES, [YGEdgeAll] = YG_UNDEFINED_VALUES, \ - } - -#define YG_DEFAULT_DIMENSION_VALUES \ - { [YGDimensionWidth] = YGUndefined, [YGDimensionHeight] = YGUndefined, } - -#define YG_DEFAULT_DIMENSION_VALUES_UNIT \ - { \ - [YGDimensionWidth] = YG_UNDEFINED_VALUES, \ - [YGDimensionHeight] = YG_UNDEFINED_VALUES, \ - } - -#define YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT \ - { [YGDimensionWidth] = YG_AUTO_VALUES, [YGDimensionHeight] = YG_AUTO_VALUES, } - static const float kDefaultFlexGrow = 0.0f; static const float kDefaultFlexShrink = 0.0f; static const float kWebDefaultFlexShrink = 1.0f; -static const YGStyle gYGNodeStyleDefaults = { - .direction = YGDirectionInherit, - .flexDirection = YGFlexDirectionColumn, - .justifyContent = YGJustifyFlexStart, - .alignContent = YGAlignFlexStart, - .alignItems = YGAlignStretch, - .alignSelf = YGAlignAuto, - .positionType = YGPositionTypeRelative, - .flexWrap = YGWrapNoWrap, - .overflow = YGOverflowVisible, - .display = YGDisplayFlex, - .flex = YGUndefined, - .flexGrow = YGUndefined, - .flexShrink = YGUndefined, - .flexBasis = YG_AUTO_VALUES, - .margin = {{YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES}}, - .position = {{YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES}}, - .padding = {{YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES}}, - .border = {{YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES, - YG_UNDEFINED_VALUES}}, - .dimensions = {{YG_AUTO_VALUES, YG_AUTO_VALUES}}, - .minDimensions = {{YG_UNDEFINED_VALUES, YG_UNDEFINED_VALUES}}, - .maxDimensions = {{YG_UNDEFINED_VALUES, YG_UNDEFINED_VALUES}}, - .aspectRatio = YGUndefined, -}; - static const YGLayout gYGNodeLayoutDefaults = { .position = {}, .dimensions = {{YGUndefined, YGUndefined}}, diff --git a/scripts/.packager.env b/scripts/.packager.env new file mode 100644 index 000000000..361f5fb47 --- /dev/null +++ b/scripts/.packager.env @@ -0,0 +1 @@ +export RCT_METRO_PORT=8081