Add config version, and invalidate layout on config change (#1674)

Summary:
X-link: https://github.com/facebook/react-native/pull/45259

This is a continuation of the previous PR: https://github.com/facebook/react-native/pull/45047

I made the change more generic for allowing any kind of config change to invalidate layout.

Changelog: [Internal]

Pull Request resolved: https://github.com/facebook/yoga/pull/1674

Reviewed By: rozele

Differential Revision: D59286992

Pulled By: NickGerleman

fbshipit-source-id: f46f35b03d5d9a743b798844ee3e1a02c271ccde
This commit is contained in:
Andrew Coates
2024-07-03 12:46:18 -07:00
committed by Facebook GitHub Bot
parent a1e9abb9b3
commit e4fe14ab3e
7 changed files with 212 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ bool LayoutResults::operator==(LayoutResults layout) const {
direction() == layout.direction() &&
hadOverflow() == layout.hadOverflow() &&
lastOwnerDirection == layout.lastOwnerDirection &&
configVersion == layout.configVersion &&
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
cachedLayout == layout.cachedLayout &&
computedFlexBasis == layout.computedFlexBasis;

View File

@@ -30,6 +30,7 @@ struct LayoutResults {
// Instead of recomputing the entire layout every single time, we cache some
// information to break early when nothing changed
uint32_t generationCount = 0;
uint32_t configVersion = 0;
Direction lastOwnerDirection = Direction::Inherit;
uint32_t nextCachedMeasurementsIndex = 0;

View File

@@ -136,6 +136,11 @@ void Node::setConfig(yoga::Config* config) {
if (yoga::configUpdateInvalidatesLayout(*config_, *config)) {
markDirtyAndPropagate();
layout_.configVersion = 0;
} else {
// If the config is functionally the same, then align the configVersion so
// that we can reuse the layout cache
layout_.configVersion = config->getVersion();
}
config_ = config;