Summary: X-link: https://github.com/facebook/react-native/pull/39223 X-link: https://github.com/facebook/react-native/pull/39200 Pull Request resolved: https://github.com/facebook/yoga/pull/1351 ## This diff This splits up `BitUtils.h`, does some minor renaming, and namespace consistency fixes. ## 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. bypass-github-export-checks Reviewed By: shwanton Differential Revision: D48847255 fbshipit-source-id: 4b9722303372f43e936118f8187c0127bceeb1d4
112 lines
2.9 KiB
C++
112 lines
2.9 KiB
C++
/*
|
|
* 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 <yoga/Yoga.h>
|
|
|
|
#include <yoga/bits/EnumBitset.h>
|
|
#include <yoga/Yoga-internal.h>
|
|
|
|
// Tag struct used to form the opaque YGConfigRef for the public C API
|
|
struct YGConfig {};
|
|
|
|
namespace facebook::yoga {
|
|
|
|
class Config;
|
|
|
|
// Whether moving a node from config "a" to config "b" should dirty previously
|
|
// calculated layout results.
|
|
bool configUpdateInvalidatesLayout(Config* a, Config* b);
|
|
|
|
// Internal variants of log functions, currently used only by JNI bindings.
|
|
// TODO: Reconcile this with the public API
|
|
using LogWithContextFn = int (*)(
|
|
YGConfigRef config,
|
|
YGNodeRef node,
|
|
YGLogLevel level,
|
|
void* context,
|
|
const char* format,
|
|
va_list args);
|
|
using CloneWithContextFn = YGNodeRef (*)(
|
|
YGNodeRef node,
|
|
YGNodeRef owner,
|
|
int childIndex,
|
|
void* cloneContext);
|
|
|
|
#pragma pack(push)
|
|
#pragma pack(1)
|
|
// Packed structure of <32-bit options to miminize size per node.
|
|
struct ConfigFlags {
|
|
bool useWebDefaults : 1;
|
|
bool printTree : 1;
|
|
bool cloneNodeUsesContext : 1;
|
|
bool loggerUsesContext : 1;
|
|
};
|
|
#pragma pack(pop)
|
|
|
|
class YOGA_EXPORT Config : public ::YGConfig {
|
|
public:
|
|
Config(YGLogger logger);
|
|
|
|
void setUseWebDefaults(bool useWebDefaults);
|
|
bool useWebDefaults() const;
|
|
|
|
void setShouldPrintTree(bool printTree);
|
|
bool shouldPrintTree() const;
|
|
|
|
void setExperimentalFeatureEnabled(
|
|
YGExperimentalFeature feature,
|
|
bool enabled);
|
|
bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const;
|
|
EnumBitset<YGExperimentalFeature> getEnabledExperiments() const;
|
|
|
|
void setErrata(YGErrata errata);
|
|
void addErrata(YGErrata errata);
|
|
void removeErrata(YGErrata errata);
|
|
YGErrata getErrata() const;
|
|
bool hasErrata(YGErrata errata) const;
|
|
|
|
void setPointScaleFactor(float pointScaleFactor);
|
|
float getPointScaleFactor() const;
|
|
|
|
void setContext(void* context);
|
|
void* getContext() const;
|
|
|
|
void setLogger(YGLogger logger);
|
|
void setLogger(LogWithContextFn logger);
|
|
void setLogger(std::nullptr_t);
|
|
void log(YGNodeRef, YGLogLevel, void*, const char*, va_list);
|
|
|
|
void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
|
|
void setCloneNodeCallback(CloneWithContextFn cloneNode);
|
|
void setCloneNodeCallback(std::nullptr_t);
|
|
YGNodeRef cloneNode(
|
|
YGNodeRef node,
|
|
YGNodeRef owner,
|
|
int childIndex,
|
|
void* cloneContext) const;
|
|
|
|
private:
|
|
union {
|
|
CloneWithContextFn withContext;
|
|
YGCloneNodeFunc noContext;
|
|
} cloneNodeCallback_;
|
|
union {
|
|
LogWithContextFn withContext;
|
|
YGLogger noContext;
|
|
} logger_;
|
|
|
|
ConfigFlags flags_{};
|
|
EnumBitset<YGExperimentalFeature> experimentalFeatures_{};
|
|
YGErrata errata_ = YGErrataNone;
|
|
float pointScaleFactor_ = 1.0f;
|
|
void* context_ = nullptr;
|
|
};
|
|
|
|
} // namespace facebook::yoga
|