Summary: X-link: https://github.com/facebook/react-native/pull/37207 Pull Request resolved: https://github.com/facebook/yoga/pull/1274 Yoga exposes public APIs for dirtying Nodes, but will itself perform dirty marking when changing bits which invalidate layout. E.g. changing the style of a Node will invalidate it along with every parent Node. Because config setting is newly public to the C ABI, this makes a similar change so that replacing a Node's config will dirty the tree above the node if there is a layout impacting config change (I don't think children need to be invalidated since child output shouldn't change given the same owner dimensions). One quirk of this is that configs may be changed independently of the node. So someone could attach a config to a Node, then change the live config after the fact. The config does not currently have a back pointer to the Node, so we do not invalidate in that case of live config edits. The future work to rectify this would be to make configs immutable once created. There are also currently some experimental features here which should maybe be compared, but these should be moved to YGErrata anyway. Reviewed By: javache Differential Revision: D45505089 fbshipit-source-id: 72b2b84ba758679af081d92e7403750c9cc53cb5
140 lines
3.3 KiB
C++
140 lines
3.3 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.
|
|
*/
|
|
|
|
#include "YGConfig.h"
|
|
|
|
using namespace facebook::yoga;
|
|
|
|
namespace facebook {
|
|
namespace yoga {
|
|
bool configUpdateInvalidatesLayout(YGConfigRef a, YGConfigRef b) {
|
|
return a->getErrata() != b->getErrata() ||
|
|
a->getEnabledExperiments() != b->getEnabledExperiments() ||
|
|
a->getPointScaleFactor() != b->getPointScaleFactor() ||
|
|
a->useWebDefaults() != b->useWebDefaults();
|
|
}
|
|
} // namespace yoga
|
|
} // namespace facebook
|
|
|
|
YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} {
|
|
setLogger(logger);
|
|
}
|
|
|
|
void YGConfig::setUseWebDefaults(bool useWebDefaults) {
|
|
flags_.useWebDefaults = useWebDefaults;
|
|
}
|
|
|
|
bool YGConfig::useWebDefaults() const {
|
|
return flags_.useWebDefaults;
|
|
}
|
|
|
|
void YGConfig::setShouldPrintTree(bool printTree) {
|
|
flags_.printTree = printTree;
|
|
}
|
|
|
|
bool YGConfig::shouldPrintTree() const {
|
|
return flags_.printTree;
|
|
}
|
|
|
|
void YGConfig::setExperimentalFeatureEnabled(
|
|
YGExperimentalFeature feature,
|
|
bool enabled) {
|
|
experimentalFeatures_.set(feature, enabled);
|
|
}
|
|
|
|
bool YGConfig::isExperimentalFeatureEnabled(
|
|
YGExperimentalFeature feature) const {
|
|
return experimentalFeatures_.test(feature);
|
|
}
|
|
|
|
ExperimentalFeatureSet YGConfig::getEnabledExperiments() const {
|
|
return experimentalFeatures_;
|
|
}
|
|
|
|
void YGConfig::setErrata(YGErrata errata) {
|
|
errata_ = errata;
|
|
}
|
|
|
|
YGErrata YGConfig::getErrata() const {
|
|
return errata_;
|
|
}
|
|
|
|
void YGConfig::setPointScaleFactor(float pointScaleFactor) {
|
|
pointScaleFactor_ = pointScaleFactor;
|
|
}
|
|
|
|
float YGConfig::getPointScaleFactor() const {
|
|
return pointScaleFactor_;
|
|
}
|
|
|
|
void YGConfig::setContext(void* context) {
|
|
context_ = context;
|
|
}
|
|
|
|
void* YGConfig::getContext() const {
|
|
return context_;
|
|
}
|
|
|
|
void YGConfig::setLogger(YGLogger logger) {
|
|
logger_.noContext = logger;
|
|
flags_.loggerUsesContext = false;
|
|
}
|
|
|
|
void YGConfig::setLogger(LogWithContextFn logger) {
|
|
logger_.withContext = logger;
|
|
flags_.loggerUsesContext = true;
|
|
}
|
|
|
|
void YGConfig::setLogger(std::nullptr_t) {
|
|
setLogger(YGLogger{nullptr});
|
|
}
|
|
|
|
void YGConfig::log(
|
|
YGConfig* config,
|
|
YGNode* node,
|
|
YGLogLevel logLevel,
|
|
void* logContext,
|
|
const char* format,
|
|
va_list args) const {
|
|
if (flags_.loggerUsesContext) {
|
|
logger_.withContext(config, node, logLevel, logContext, format, args);
|
|
} else {
|
|
logger_.noContext(config, node, logLevel, format, args);
|
|
}
|
|
}
|
|
|
|
void YGConfig::setCloneNodeCallback(YGCloneNodeFunc cloneNode) {
|
|
cloneNodeCallback_.noContext = cloneNode;
|
|
flags_.cloneNodeUsesContext = false;
|
|
}
|
|
|
|
void YGConfig::setCloneNodeCallback(CloneWithContextFn cloneNode) {
|
|
cloneNodeCallback_.withContext = cloneNode;
|
|
flags_.cloneNodeUsesContext = true;
|
|
}
|
|
|
|
void YGConfig::setCloneNodeCallback(std::nullptr_t) {
|
|
setCloneNodeCallback(YGCloneNodeFunc{nullptr});
|
|
}
|
|
|
|
YGNodeRef YGConfig::cloneNode(
|
|
YGNodeRef node,
|
|
YGNodeRef owner,
|
|
int childIndex,
|
|
void* cloneContext) const {
|
|
YGNodeRef clone = nullptr;
|
|
if (cloneNodeCallback_.noContext != nullptr) {
|
|
clone = flags_.cloneNodeUsesContext
|
|
? cloneNodeCallback_.withContext(node, owner, childIndex, cloneContext)
|
|
: cloneNodeCallback_.noContext(node, owner, childIndex);
|
|
}
|
|
if (clone == nullptr) {
|
|
clone = YGNodeClone(node);
|
|
}
|
|
return clone;
|
|
}
|