Files
yoga/tests/YGStyleAccessorsTest.cpp

255 lines
6.6 KiB
C++
Raw Normal View History

/*
* 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 <cstdint>
#include <type_traits>
#include <gtest/gtest.h>
C++ Cleanup 1/N: Reorganize YGStyle (#1349) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1349 X-link: https://github.com/facebook/react-native/pull/39171 ## This diff This diff adds a `style` directory for code related to storing and manipulating styles. `YGStyle`, which is not a public API, is renamed to `yoga::Style` and moved into this folder, alongside `CompactValue`. We will eventually add `ValuePool` alongside this for the next generation style representation. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48710084 fbshipit-source-id: 20961aee30d54a6b0d8c1cc2976df09b9b6d486a
2023-08-29 21:32:56 -07:00
#include <yoga/Yoga.h>
#include <yoga/style/Style.h>
#define ACCESSOR_TESTS_1(NAME, X) \
style.NAME() = X; \
ASSERT_EQ(style.NAME(), X);
#define ACCESSOR_TESTS_2(NAME, X, ...) \
ACCESSOR_TESTS_1(NAME, X); \
ACCESSOR_TESTS_1(NAME, __VA_ARGS__);
#define ACCESSOR_TESTS_3(NAME, X, ...) \
ACCESSOR_TESTS_1(NAME, X); \
ACCESSOR_TESTS_2(NAME, __VA_ARGS__);
#define ACCESSOR_TESTS_4(NAME, X, ...) \
ACCESSOR_TESTS_1(NAME, X); \
ACCESSOR_TESTS_3(NAME, __VA_ARGS__);
#define ACCESSOR_TESTS_5(NAME, X, ...) \
ACCESSOR_TESTS_1(NAME, X); \
ACCESSOR_TESTS_4(NAME, __VA_ARGS__)
#define ACCESSOR_TESTS_N(a, b, c, d, e, COUNT, ...) ACCESSOR_TESTS_##COUNT
#define ACCESSOR_TESTS(...) ACCESSOR_TESTS_N(__VA_ARGS__, 5, 4, 3, 2, 1)
C++ Cleanup 1/N: Reorganize YGStyle (#1349) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1349 X-link: https://github.com/facebook/react-native/pull/39171 ## This diff This diff adds a `style` directory for code related to storing and manipulating styles. `YGStyle`, which is not a public API, is renamed to `yoga::Style` and moved into this folder, alongside `CompactValue`. We will eventually add `ValuePool` alongside this for the next generation style representation. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48710084 fbshipit-source-id: 20961aee30d54a6b0d8c1cc2976df09b9b6d486a
2023-08-29 21:32:56 -07:00
#define INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
{ \
auto style = Style{}; \
style.NAME()[IDX] = X; \
ASSERT_EQ(style.NAME()[IDX], X); \
auto asArray = decltype(std::declval<const Style&>().NAME()){X}; \
style.NAME() = asArray; \
ASSERT_EQ(static_cast<decltype(asArray)>(style.NAME()), asArray); \
}
#define INDEX_ACCESSOR_TESTS_2(NAME, IDX, X, Y) \
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
INDEX_ACCESSOR_TESTS_1(NAME, IDX, Y)
#define INDEX_ACCESSOR_TESTS_3(NAME, IDX, X, ...) \
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
INDEX_ACCESSOR_TESTS_2(NAME, IDX, __VA_ARGS__)
#define INDEX_ACCESSOR_TESTS_4(NAME, IDX, X, ...) \
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
INDEX_ACCESSOR_TESTS_3(NAME, IDX, __VA_ARGS__)
#define INDEX_ACCESSOR_TESTS_5(NAME, IDX, X, ...) \
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
INDEX_ACCESSOR_TESTS_4(NAME, IDX, __VA_ARGS__)
#define INDEX_ACCESSOR_TESTS_N(a, b, c, d, e, COUNT, ...) \
INDEX_ACCESSOR_TESTS_##COUNT
#define INDEX_ACCESSOR_TESTS(...) \
INDEX_ACCESSOR_TESTS_N(__VA_ARGS__, 5, 4, 3, 2, 1)
// test macro for up to 5 values. If more are needed, extend the macros above.
#define ACCESSOR_TEST(NAME, DEFAULT_VAL, ...) \
C++ Cleanup 1/N: Reorganize YGStyle (#1349) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1349 X-link: https://github.com/facebook/react-native/pull/39171 ## This diff This diff adds a `style` directory for code related to storing and manipulating styles. `YGStyle`, which is not a public API, is renamed to `yoga::Style` and moved into this folder, alongside `CompactValue`. We will eventually add `ValuePool` alongside this for the next generation style representation. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48710084 fbshipit-source-id: 20961aee30d54a6b0d8c1cc2976df09b9b6d486a
2023-08-29 21:32:56 -07:00
TEST(Style, style_##NAME##_access) { \
auto style = Style{}; \
ASSERT_EQ(style.NAME(), DEFAULT_VAL); \
ACCESSOR_TESTS(__VA_ARGS__)(NAME, __VA_ARGS__) \
}
#define INDEX_ACCESSOR_TEST(NAME, DEFAULT_VAL, IDX, ...) \
C++ Cleanup 1/N: Reorganize YGStyle (#1349) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1349 X-link: https://github.com/facebook/react-native/pull/39171 ## This diff This diff adds a `style` directory for code related to storing and manipulating styles. `YGStyle`, which is not a public API, is renamed to `yoga::Style` and moved into this folder, alongside `CompactValue`. We will eventually add `ValuePool` alongside this for the next generation style representation. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48710084 fbshipit-source-id: 20961aee30d54a6b0d8c1cc2976df09b9b6d486a
2023-08-29 21:32:56 -07:00
TEST(Style, style_##NAME##_access) { \
ASSERT_EQ(Style{}.NAME()[IDX], DEFAULT_VAL); \
INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \
}
namespace facebook::yoga {
// TODO: MSVC doesn't like the macros
#ifndef _MSC_VER
ACCESSOR_TEST(
direction,
YGDirectionInherit,
YGDirectionLTR,
YGDirectionRTL,
YGDirectionInherit);
ACCESSOR_TEST(
flexDirection,
YGFlexDirectionColumn,
YGFlexDirectionColumnReverse,
YGFlexDirectionRowReverse,
YGFlexDirectionRow)
ACCESSOR_TEST(
justifyContent,
YGJustifyFlexStart,
YGJustifyFlexEnd,
YGJustifySpaceAround,
YGJustifyFlexStart,
YGJustifySpaceEvenly)
ACCESSOR_TEST(
alignContent,
YGAlignFlexStart,
YGAlignAuto,
YGAlignFlexStart,
YGAlignCenter,
YGAlignFlexEnd,
YGAlignStretch)
ACCESSOR_TEST(
alignItems,
YGAlignStretch,
YGAlignFlexStart,
YGAlignFlexEnd,
YGAlignBaseline,
YGAlignSpaceBetween,
YGAlignSpaceAround)
ACCESSOR_TEST(
alignSelf,
YGAlignAuto,
YGAlignFlexStart,
YGAlignCenter,
YGAlignAuto,
YGAlignFlexEnd,
YGAlignStretch)
ACCESSOR_TEST(
positionType,
YGPositionTypeStatic,
YGPositionTypeAbsolute,
YGPositionTypeRelative,
YGPositionTypeStatic)
ACCESSOR_TEST(
flexWrap,
YGWrapNoWrap,
YGWrapWrap,
YGWrapWrapReverse,
YGWrapNoWrap)
ACCESSOR_TEST(
overflow,
YGOverflowVisible,
YGOverflowHidden,
YGOverflowScroll,
YGOverflowVisible)
ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex)
ACCESSOR_TEST(
flex,
C++ Cleanup 6/N: YGFloatOptional (#1356) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1356 X-link: https://github.com/facebook/react-native/pull/39196 ## This diff This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48767992 fbshipit-source-id: afaff023435915dbd5e571fd1ee2e695e4f59a5c
2023-08-29 21:32:56 -07:00
FloatOptional{},
FloatOptional{123.45f},
FloatOptional{-9.87f},
FloatOptional{})
ACCESSOR_TEST(
flexGrow,
C++ Cleanup 6/N: YGFloatOptional (#1356) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1356 X-link: https://github.com/facebook/react-native/pull/39196 ## This diff This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48767992 fbshipit-source-id: afaff023435915dbd5e571fd1ee2e695e4f59a5c
2023-08-29 21:32:56 -07:00
FloatOptional{},
FloatOptional{123.45f},
FloatOptional{-9.87f},
FloatOptional{})
ACCESSOR_TEST(
flexShrink,
C++ Cleanup 6/N: YGFloatOptional (#1356) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1356 X-link: https://github.com/facebook/react-native/pull/39196 ## This diff This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48767992 fbshipit-source-id: afaff023435915dbd5e571fd1ee2e695e4f59a5c
2023-08-29 21:32:56 -07:00
FloatOptional{},
FloatOptional{123.45f},
FloatOptional{-9.87f},
FloatOptional{})
ACCESSOR_TEST(
flexBasis,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::ofAuto(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
INDEX_ACCESSOR_TEST(
position,
CompactValue::ofUndefined(),
YGEdgeBottom,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
INDEX_ACCESSOR_TEST(
margin,
CompactValue::ofUndefined(),
YGEdgeTop,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
INDEX_ACCESSOR_TEST(
padding,
CompactValue::ofUndefined(),
YGEdgeAll,
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPercent>(-100.0f))
INDEX_ACCESSOR_TEST(
border,
CompactValue::ofUndefined(),
YGEdgeHorizontal,
CompactValue::of<YGUnitPoint>(-7777.77f),
CompactValue::ofUndefined())
INDEX_ACCESSOR_TEST(
dimensions,
CompactValue::ofAuto(),
YGDimensionWidth,
CompactValue::ofUndefined(),
CompactValue::ofAuto(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
INDEX_ACCESSOR_TEST(
minDimensions,
CompactValue::ofUndefined(),
YGDimensionHeight,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
INDEX_ACCESSOR_TEST(
maxDimensions,
CompactValue::ofUndefined(),
YGDimensionHeight,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
ACCESSOR_TEST(
aspectRatio,
C++ Cleanup 6/N: YGFloatOptional (#1356) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1356 X-link: https://github.com/facebook/react-native/pull/39196 ## This diff This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48767992 fbshipit-source-id: afaff023435915dbd5e571fd1ee2e695e4f59a5c
2023-08-29 21:32:56 -07:00
FloatOptional{},
FloatOptional{-123.45f},
FloatOptional{9876.5f},
FloatOptional{0.0f},
FloatOptional{});
#endif
} // namespace facebook::yoga