-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
30e54ad
commit 4eec473
Showing
23 changed files
with
3,704 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# FlexLayout Source Code | ||
|
||
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. | ||
|
||
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. | ||
|
||
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: | ||
https://github.com/react-native-community/discussions-and-proposals/discussions/499 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "Dimension.h" | ||
#include "Utils.h" | ||
|
||
#ifdef DEBUG | ||
#include <ostream> | ||
#endif | ||
|
||
namespace facebook { | ||
namespace flexlayout { | ||
|
||
#ifdef DEBUG | ||
auto operator<<(std::ostream& os, const AlignContent& x) -> std::ostream& { | ||
switch (x) { | ||
case AlignContent::FlexStart: | ||
os << "FlexStart"; | ||
break; | ||
case AlignContent::Center: | ||
os << "Center"; | ||
break; | ||
case AlignContent::FlexEnd: | ||
os << "FlexEnd"; | ||
break; | ||
case AlignContent::Stretch: | ||
os << "Stretch"; | ||
break; | ||
case AlignContent::Baseline: | ||
os << "Baseline"; | ||
break; | ||
case AlignContent::SpaceBetween: | ||
os << "SpaceBetween"; | ||
break; | ||
case AlignContent::SpaceAround: | ||
os << "SpaceAround"; | ||
break; | ||
} | ||
return os; | ||
} | ||
|
||
auto operator<<(std::ostream& os, const AlignItems& x) -> std::ostream& { | ||
switch (x) { | ||
case AlignItems::FlexStart: | ||
os << "FlexStart"; | ||
break; | ||
case AlignItems::Center: | ||
os << "Center"; | ||
break; | ||
case AlignItems::FlexEnd: | ||
os << "FlexEnd"; | ||
break; | ||
case AlignItems::Stretch: | ||
os << "Stretch"; | ||
break; | ||
case AlignItems::Baseline: | ||
os << "Baseline"; | ||
break; | ||
} | ||
return os; | ||
} | ||
|
||
auto operator<<(std::ostream& os, const AlignSelf& x) -> std::ostream& { | ||
switch (x) { | ||
case AlignSelf::Auto: | ||
os << "Auto"; | ||
break; | ||
case AlignSelf::FlexStart: | ||
os << "FlexStart"; | ||
break; | ||
case AlignSelf::Center: | ||
os << "Center"; | ||
break; | ||
case AlignSelf::FlexEnd: | ||
os << "FlexEnd"; | ||
break; | ||
case AlignSelf::Stretch: | ||
os << "Stretch"; | ||
break; | ||
case AlignSelf::Baseline: | ||
os << "Baseline"; | ||
break; | ||
} | ||
return os; | ||
} | ||
|
||
auto operator<<(std::ostream& os, const Edge& x) -> std::ostream& { | ||
switch (x) { | ||
case Edge::Left: | ||
os << "Left"; | ||
break; | ||
case Edge::Top: | ||
os << "Top"; | ||
break; | ||
case Edge::Right: | ||
os << "Right"; | ||
break; | ||
case Edge::Bottom: | ||
os << "Bottom"; | ||
break; | ||
} | ||
return os; | ||
} | ||
|
||
auto operator<<(std::ostream& os, const PositionType& x) -> std::ostream& { | ||
switch (x) { | ||
case PositionType::Relative: | ||
os << "Relative"; | ||
break; | ||
case PositionType::Absolute: | ||
os << "Absolute"; | ||
break; | ||
} | ||
return os; | ||
} | ||
|
||
auto operator<<(std::ostream& os, const Display& x) -> std::ostream& { | ||
switch (x) { | ||
case Display::Flex: | ||
os << "Flex"; | ||
break; | ||
case Display::None: | ||
os << "None"; | ||
break; | ||
} | ||
return os; | ||
} | ||
#endif | ||
|
||
namespace utils { | ||
|
||
auto Dimension::operator==(const Dimension& rhs) const -> bool { | ||
return unit == rhs.unit && FlexLayoutFloatsEqual(value, rhs.value); | ||
} | ||
|
||
auto Dimension::operator!=(const Dimension& rhs) const -> bool { | ||
return !(*this == rhs); | ||
} | ||
|
||
#ifdef DEBUG | ||
auto operator<<(std::ostream& os, const Dimension& x) -> std::ostream& { | ||
switch (x.unit) { | ||
case Unit::Undefined: | ||
os << "-"; | ||
break; | ||
case Unit::Point: | ||
os << x.value << "pt"; | ||
break; | ||
case Unit::Percent: | ||
os << x.value << "%"; | ||
break; | ||
case Unit::Auto: | ||
os << "Auto"; | ||
break; | ||
} | ||
return os; | ||
} | ||
#endif | ||
} // namespace utils | ||
} // namespace flexlayout | ||
} // namespace facebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cmath> | ||
#include "FlexLayoutEnums.h" | ||
#include "FlexLayoutMacros.h" | ||
#include "Type.h" | ||
|
||
#ifdef DEBUG | ||
#include <iosfwd> | ||
#endif | ||
|
||
namespace facebook { | ||
namespace flexlayout { | ||
|
||
#ifdef DEBUG | ||
auto operator<<(std::ostream& os, const AlignContent& x) -> std::ostream&; | ||
auto operator<<(std::ostream& os, const AlignItems& x) -> std::ostream&; | ||
auto operator<<(std::ostream& os, const AlignSelf& x) -> std::ostream&; | ||
auto operator<<(std::ostream& os, const Edge& x) -> std::ostream&; | ||
auto operator<<(std::ostream& os, const PositionType& x) -> std::ostream&; | ||
auto operator<<(std::ostream& os, const Display& x) -> std::ostream&; | ||
#endif | ||
|
||
namespace utils { | ||
|
||
class Dimension { | ||
public: | ||
Dimension() { | ||
value = NAN; | ||
unit = Unit::Undefined; | ||
} | ||
|
||
explicit Dimension(const Float value, const Unit unit) | ||
: value(value), unit(unit) {} | ||
|
||
[[nodiscard]] auto resolve(const Float ownerSize) const -> Float { | ||
switch (unit) { | ||
case Unit::Point: | ||
return value; | ||
case Unit::Percent: | ||
return value * ownerSize * 0.01f; | ||
case Unit::Auto: | ||
case Unit::Undefined: | ||
return NAN; | ||
} | ||
} | ||
|
||
FLEX_LAYOUT_EXPORT auto operator==(const Dimension& rhs) const -> bool; | ||
auto operator!=(const Dimension& rhs) const -> bool; | ||
|
||
Float value; | ||
Unit unit; | ||
}; | ||
|
||
#ifdef DEBUG | ||
auto operator<<(std::ostream& os, const Dimension& x) -> std::ostream&; | ||
#endif | ||
} // namespace utils | ||
} // namespace flexlayout | ||
} // namespace facebook |
Oops, something went wrong.