Call logger from within YGConfig
Summary: @public Stricter encapsulation of logging callbacks within `YGConfig`. Instead of invoking the logging callback directly (`node->logger(...)`), callers now have to go through `YGConfig::log()`. This change will allow us to add the concept of a *Layout Context,* where logging functions will be able to receive an additional `void *` argument if configured accordingly. This API will be used internally for Yoga’s JNI bindings, to avoid storing a weak JNI reference for each node, and avoid reference table overflows. Changed API: - `YGConfig::logger()` -> `YGConfig::log()` Reviewed By: SidharthGuglani Differential Revision: D14123483 fbshipit-source-id: 87b8bb7de0e4346b6a41e57a70ac4eb8d79b24af
This commit is contained in:
committed by
Facebook Github Bot
parent
1b9053bc5d
commit
0bdf36f5d1
@@ -6,4 +6,13 @@
|
||||
*/
|
||||
#include "YGConfig.h"
|
||||
|
||||
YGConfig::YGConfig(YGLogger logger) : logger(logger) {}
|
||||
YGConfig::YGConfig(YGLogger logger) : logger_{logger} {}
|
||||
|
||||
void YGConfig::log(
|
||||
YGConfig* config,
|
||||
YGNode* node,
|
||||
YGLogLevel logLevel,
|
||||
const char* format,
|
||||
va_list args) {
|
||||
logger_(config, node, logLevel, format, args);
|
||||
}
|
||||
|
@@ -10,17 +10,24 @@
|
||||
#include "Yoga.h"
|
||||
|
||||
struct YGConfig {
|
||||
std::array<bool, facebook::yoga::enums::count<YGExperimentalFeature>()>
|
||||
experimentalFeatures = {};
|
||||
private:
|
||||
YGLogger logger_;
|
||||
|
||||
public:
|
||||
bool useWebDefaults = false;
|
||||
bool useLegacyStretchBehaviour = false;
|
||||
bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false;
|
||||
bool printTree = false;
|
||||
float pointScaleFactor = 1.0f;
|
||||
YGLogger logger;
|
||||
YGCloneNodeFunc cloneNodeCallback = nullptr;
|
||||
std::array<bool, facebook::yoga::enums::count<YGExperimentalFeature>()>
|
||||
experimentalFeatures = {};
|
||||
void* context = nullptr;
|
||||
YGMarkerCallbacks markerCallbacks = {nullptr, nullptr};
|
||||
|
||||
YGConfig(YGLogger logger);
|
||||
void log(YGConfig*, YGNode*, YGLogLevel, const char*, va_list);
|
||||
void setLogger(YGLogger logger) {
|
||||
logger_ = logger;
|
||||
}
|
||||
};
|
||||
|
@@ -4182,12 +4182,12 @@ void YGNodeCalculateLayout(
|
||||
|
||||
void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
||||
if (logger != nullptr) {
|
||||
config->logger = logger;
|
||||
config->setLogger(logger);
|
||||
} else {
|
||||
#ifdef ANDROID
|
||||
config->logger = &YGAndroidLog;
|
||||
config->setLogger(&YGAndroidLog);
|
||||
#else
|
||||
config->logger = &YGDefaultLog;
|
||||
config->setLogger(&YGDefaultLog);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ void vlog(
|
||||
const char* format,
|
||||
va_list args) {
|
||||
YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault();
|
||||
logConfig->logger(logConfig, node, level, format, args);
|
||||
logConfig->log(logConfig, node, level, format, args);
|
||||
|
||||
if (level == YGLogLevelFatal) {
|
||||
abort();
|
||||
|
Reference in New Issue
Block a user