Skip to content

Commit

Permalink
Move YGStyle to seperate file and add constructors
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D7016575

fbshipit-source-id: eb28df0ffb4cc813b23edaff80d7d4ebc56ce6af
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Feb 20, 2018
1 parent 973ef97 commit b9991d3
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 155 deletions.
12 changes: 12 additions & 0 deletions React/React.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -2144,6 +2148,8 @@
3EDCA8A31D3591E700450C31 /* RCTErrorInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTErrorInfo.h; sourceTree = "<group>"; };
3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTErrorInfo.m; sourceTree = "<group>"; };
5335D5401FE81A4700883D58 /* RCTShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowView.m; sourceTree = "<group>"; };
5352C5712038FF8D00A3B97E /* YGStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGStyle.h; sourceTree = "<group>"; };
5352C5722038FF8D00A3B97E /* YGStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGStyle.cpp; sourceTree = "<group>"; };
53756E372004FFF700FBBD99 /* Utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Utils.cpp; sourceTree = "<group>"; };
53756E382004FFF700FBBD99 /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utils.h; sourceTree = "<group>"; };
5376C5E01FC6DDB20083513D /* YGNodePrint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNodePrint.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2332,6 +2338,8 @@
130A77021DF767AF001F9587 /* yoga */ = {
isa = PBXGroup;
children = (
5352C5722038FF8D00A3B97E /* YGStyle.cpp */,
5352C5712038FF8D00A3B97E /* YGStyle.h */,
53756E372004FFF700FBBD99 /* Utils.cpp */,
53756E382004FFF700FBBD99 /* Utils.h */,
53EC85DF1FDEC75A0051B2B5 /* YGNode.cpp */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ YGNode::YGNode()
measure_(nullptr),
baseline_(nullptr),
dirtied_(nullptr),
style_(gYGNodeStyleDefaults),
style_(YGStyle()),
layout_(gYGNodeLayoutDefaults),
lineIndex_(0),
parent_(nullptr),
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/yoga/yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once
#include <stdio.h>

#include "YGStyle.h"
#include "Yoga-internal.h"

struct YGNode {
Expand Down
78 changes: 78 additions & 0 deletions ReactCommon/yoga/yoga/YGStyle.cpp
Original file line number Diff line number Diff line change
@@ -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() {}
43 changes: 43 additions & 0 deletions ReactCommon/yoga/yoga/YGStyle.h
Original file line number Diff line number Diff line change
@@ -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<YGValue, YGEdgeCount> margin;
std::array<YGValue, YGEdgeCount> position;
std::array<YGValue, YGEdgeCount> padding;
std::array<YGValue, YGEdgeCount> border;
std::array<YGValue, 2> dimensions;
std::array<YGValue, 2> minDimensions;
std::array<YGValue, 2> maxDimensions;
float aspectRatio;

YGStyle();
// Yoga specific properties, not compatible with flexbox specification
bool operator==(const YGStyle& style);

bool operator!=(YGStyle style);
~YGStyle();
};
Loading

0 comments on commit b9991d3

Please sign in to comment.