Skip to content

Commit 9c5e465

Browse files
J.T. Yimroryabraham
authored andcommitted
Add flexlayout dirSync to react-native-github
Summary: Changelog: [Internal] Include FlexLayout C++ source to ReactCommons Reviewed By: d16r, NickGerleman Differential Revision: D38716145 fbshipit-source-id: 0ca2ab040e72168f2f1b479609b6cda2787eba66
1 parent 17565e4 commit 9c5e465

23 files changed

+3704
-0
lines changed

ReactCommon/flexlayout/README.MD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# FlexLayout Source Code
2+
3+
The react-native repo is exposing this subset of the source code for the FlexLayout layout engine for exploratory purposes. We're currently experimenting with this alternative layout engine for Yoga, which we hope might help to address some of the pain points brought by the community over the years.
4+
5+
This inclusion of the new files in the repository can be safely ignored as they will have no functional impact on end users during this phase, ie. APK size will not be affected, and the layout API and functionality will remain entirely unchanged.
6+
7+
Please also note that we also will not yet be considering feature or pull requests for the FlexLayout engine at this point in time. Feel free to comment in the community discussions if you have any concerns or questions related to FlexLayout:
8+
https://github.com/react-native-community/discussions-and-proposals/discussions/499
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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 "Dimension.h"
9+
#include "Utils.h"
10+
11+
#ifdef DEBUG
12+
#include <ostream>
13+
#endif
14+
15+
namespace facebook {
16+
namespace flexlayout {
17+
18+
#ifdef DEBUG
19+
auto operator<<(std::ostream& os, const AlignContent& x) -> std::ostream& {
20+
switch (x) {
21+
case AlignContent::FlexStart:
22+
os << "FlexStart";
23+
break;
24+
case AlignContent::Center:
25+
os << "Center";
26+
break;
27+
case AlignContent::FlexEnd:
28+
os << "FlexEnd";
29+
break;
30+
case AlignContent::Stretch:
31+
os << "Stretch";
32+
break;
33+
case AlignContent::Baseline:
34+
os << "Baseline";
35+
break;
36+
case AlignContent::SpaceBetween:
37+
os << "SpaceBetween";
38+
break;
39+
case AlignContent::SpaceAround:
40+
os << "SpaceAround";
41+
break;
42+
}
43+
return os;
44+
}
45+
46+
auto operator<<(std::ostream& os, const AlignItems& x) -> std::ostream& {
47+
switch (x) {
48+
case AlignItems::FlexStart:
49+
os << "FlexStart";
50+
break;
51+
case AlignItems::Center:
52+
os << "Center";
53+
break;
54+
case AlignItems::FlexEnd:
55+
os << "FlexEnd";
56+
break;
57+
case AlignItems::Stretch:
58+
os << "Stretch";
59+
break;
60+
case AlignItems::Baseline:
61+
os << "Baseline";
62+
break;
63+
}
64+
return os;
65+
}
66+
67+
auto operator<<(std::ostream& os, const AlignSelf& x) -> std::ostream& {
68+
switch (x) {
69+
case AlignSelf::Auto:
70+
os << "Auto";
71+
break;
72+
case AlignSelf::FlexStart:
73+
os << "FlexStart";
74+
break;
75+
case AlignSelf::Center:
76+
os << "Center";
77+
break;
78+
case AlignSelf::FlexEnd:
79+
os << "FlexEnd";
80+
break;
81+
case AlignSelf::Stretch:
82+
os << "Stretch";
83+
break;
84+
case AlignSelf::Baseline:
85+
os << "Baseline";
86+
break;
87+
}
88+
return os;
89+
}
90+
91+
auto operator<<(std::ostream& os, const Edge& x) -> std::ostream& {
92+
switch (x) {
93+
case Edge::Left:
94+
os << "Left";
95+
break;
96+
case Edge::Top:
97+
os << "Top";
98+
break;
99+
case Edge::Right:
100+
os << "Right";
101+
break;
102+
case Edge::Bottom:
103+
os << "Bottom";
104+
break;
105+
}
106+
return os;
107+
}
108+
109+
auto operator<<(std::ostream& os, const PositionType& x) -> std::ostream& {
110+
switch (x) {
111+
case PositionType::Relative:
112+
os << "Relative";
113+
break;
114+
case PositionType::Absolute:
115+
os << "Absolute";
116+
break;
117+
}
118+
return os;
119+
}
120+
121+
auto operator<<(std::ostream& os, const Display& x) -> std::ostream& {
122+
switch (x) {
123+
case Display::Flex:
124+
os << "Flex";
125+
break;
126+
case Display::None:
127+
os << "None";
128+
break;
129+
}
130+
return os;
131+
}
132+
#endif
133+
134+
namespace utils {
135+
136+
auto Dimension::operator==(const Dimension& rhs) const -> bool {
137+
return unit == rhs.unit && FlexLayoutFloatsEqual(value, rhs.value);
138+
}
139+
140+
auto Dimension::operator!=(const Dimension& rhs) const -> bool {
141+
return !(*this == rhs);
142+
}
143+
144+
#ifdef DEBUG
145+
auto operator<<(std::ostream& os, const Dimension& x) -> std::ostream& {
146+
switch (x.unit) {
147+
case Unit::Undefined:
148+
os << "-";
149+
break;
150+
case Unit::Point:
151+
os << x.value << "pt";
152+
break;
153+
case Unit::Percent:
154+
os << x.value << "%";
155+
break;
156+
case Unit::Auto:
157+
os << "Auto";
158+
break;
159+
}
160+
return os;
161+
}
162+
#endif
163+
} // namespace utils
164+
} // namespace flexlayout
165+
} // namespace facebook
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
#pragma once
9+
10+
#include <cmath>
11+
#include "FlexLayoutEnums.h"
12+
#include "FlexLayoutMacros.h"
13+
#include "Type.h"
14+
15+
#ifdef DEBUG
16+
#include <iosfwd>
17+
#endif
18+
19+
namespace facebook {
20+
namespace flexlayout {
21+
22+
#ifdef DEBUG
23+
auto operator<<(std::ostream& os, const AlignContent& x) -> std::ostream&;
24+
auto operator<<(std::ostream& os, const AlignItems& x) -> std::ostream&;
25+
auto operator<<(std::ostream& os, const AlignSelf& x) -> std::ostream&;
26+
auto operator<<(std::ostream& os, const Edge& x) -> std::ostream&;
27+
auto operator<<(std::ostream& os, const PositionType& x) -> std::ostream&;
28+
auto operator<<(std::ostream& os, const Display& x) -> std::ostream&;
29+
#endif
30+
31+
namespace utils {
32+
33+
class Dimension {
34+
public:
35+
Dimension() {
36+
value = NAN;
37+
unit = Unit::Undefined;
38+
}
39+
40+
explicit Dimension(const Float value, const Unit unit)
41+
: value(value), unit(unit) {}
42+
43+
[[nodiscard]] auto resolve(const Float ownerSize) const -> Float {
44+
switch (unit) {
45+
case Unit::Point:
46+
return value;
47+
case Unit::Percent:
48+
return value * ownerSize * 0.01f;
49+
case Unit::Auto:
50+
case Unit::Undefined:
51+
return NAN;
52+
}
53+
}
54+
55+
FLEX_LAYOUT_EXPORT auto operator==(const Dimension& rhs) const -> bool;
56+
auto operator!=(const Dimension& rhs) const -> bool;
57+
58+
Float value;
59+
Unit unit;
60+
};
61+
62+
#ifdef DEBUG
63+
auto operator<<(std::ostream& os, const Dimension& x) -> std::ostream&;
64+
#endif
65+
} // namespace utils
66+
} // namespace flexlayout
67+
} // namespace facebook

0 commit comments

Comments
 (0)