mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Key cached layouts on the owner size a node's percentages resolve against (#2042)
Summary: * Test that percentage padding and min sizes follow their owner on relayout * Key cached layouts on the owner size a node's percentages resolve against A clean node's cached layout and measurements are keyed on its available size and sizing modes. Its percentage padding, margin, width, min-width and max-width resolve against the owner's width (and its percentage height bounds against the owner's height), which the key does not record, so a node of fixed size keeps the layout its percentages produced under its owner's previous size. Each cache entry now records the owner size it was computed against, and a lookup for a node whose style resolves a percentage against the owner's width or height requires that size to match. Fixes #1626 Changelog: [Internal] bypass-github-export-checks Reviewed By: christophpurrer Differential Revision: D125706276 fbshipit-source-id: 7d4151abdd298be1620d908632e17e207b76deb9
This commit is contained in:
1 parent
7728787c25
commit
ccca5d7a29
15 files changed
+114
-4
No files matched your search
@@ -2704,6 +2704,19 @@ static void calculateLayoutImpl(
|
||||
// Input parameters are the same as calculateLayoutImpl (see above)
|
||||
// Return parameter is true if layout was performed, false if skipped
|
||||
//
|
||||
// A cached result holds only for the owner size it was computed against when
|
||||
// the node's style resolves a percentage against that size.
|
||||
static bool isCachedForOwnerSize(
|
||||
const yoga::Node* const node,
|
||||
const CachedMeasurement& cachedMeasurement,
|
||||
const float ownerWidth,
|
||||
const float ownerHeight) {
|
||||
return (!node->style().resolvesAgainstOwnerWidth() ||
|
||||
yoga::inexactEquals(cachedMeasurement.ownerWidth, ownerWidth)) &&
|
||||
(!node->style().resolvesAgainstOwnerHeight() ||
|
||||
yoga::inexactEquals(cachedMeasurement.ownerHeight, ownerHeight));
|
||||
}
|
||||
|
||||
bool calculateLayoutInternal(
|
||||
yoga::Node* const node,
|
||||
const float availableWidth,
|
||||
@@ -2736,6 +2749,8 @@ bool calculateLayoutInternal(
|
||||
layout->cachedLayout.heightSizingMode = SizingMode::MaxContent;
|
||||
layout->cachedLayout.computedWidth = -1;
|
||||
layout->cachedLayout.computedHeight = -1;
|
||||
layout->cachedLayout.ownerWidth = -1;
|
||||
layout->cachedLayout.ownerHeight = -1;
|
||||
}
|
||||
|
||||
CachedMeasurement* cachedResults = nullptr;
|
||||
@@ -2768,7 +2783,9 @@ bool calculateLayoutInternal(
|
||||
layout->cachedLayout.computedHeight,
|
||||
marginAxisRow,
|
||||
marginAxisColumn,
|
||||
node->getConfig())) {
|
||||
node->getConfig()) &&
|
||||
isCachedForOwnerSize(
|
||||
node, layout->cachedLayout, ownerWidth, ownerHeight)) {
|
||||
cachedResults = &layout->cachedLayout;
|
||||
} else {
|
||||
// Try to use the measurement cache.
|
||||
@@ -2786,7 +2803,9 @@ bool calculateLayoutInternal(
|
||||
layout->cachedMeasurements[i].computedHeight,
|
||||
marginAxisRow,
|
||||
marginAxisColumn,
|
||||
node->getConfig())) {
|
||||
node->getConfig()) &&
|
||||
isCachedForOwnerSize(
|
||||
node, layout->cachedMeasurements[i], ownerWidth, ownerHeight)) {
|
||||
cachedResults = &layout->cachedMeasurements[i];
|
||||
break;
|
||||
}
|
||||
@@ -2798,7 +2817,9 @@ bool calculateLayoutInternal(
|
||||
yoga::inexactEquals(
|
||||
layout->cachedLayout.availableHeight, availableHeight) &&
|
||||
layout->cachedLayout.widthSizingMode == widthSizingMode &&
|
||||
layout->cachedLayout.heightSizingMode == heightSizingMode) {
|
||||
layout->cachedLayout.heightSizingMode == heightSizingMode &&
|
||||
isCachedForOwnerSize(
|
||||
node, layout->cachedLayout, ownerWidth, ownerHeight)) {
|
||||
cachedResults = &layout->cachedLayout;
|
||||
}
|
||||
} else {
|
||||
@@ -2808,7 +2829,9 @@ bool calculateLayoutInternal(
|
||||
yoga::inexactEquals(
|
||||
layout->cachedMeasurements[i].availableHeight, availableHeight) &&
|
||||
layout->cachedMeasurements[i].widthSizingMode == widthSizingMode &&
|
||||
layout->cachedMeasurements[i].heightSizingMode == heightSizingMode) {
|
||||
layout->cachedMeasurements[i].heightSizingMode == heightSizingMode &&
|
||||
isCachedForOwnerSize(
|
||||
node, layout->cachedMeasurements[i], ownerWidth, ownerHeight)) {
|
||||
cachedResults = &layout->cachedMeasurements[i];
|
||||
break;
|
||||
}
|
||||
@@ -2871,6 +2894,8 @@ bool calculateLayoutInternal(
|
||||
layout->measuredDimension(Dimension::Width);
|
||||
newCacheEntry->computedHeight =
|
||||
layout->measuredDimension(Dimension::Height);
|
||||
newCacheEntry->ownerWidth = ownerWidth;
|
||||
newCacheEntry->ownerHeight = ownerHeight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ struct CachedMeasurement {
|
||||
float computedWidth{-1};
|
||||
float computedHeight{-1};
|
||||
|
||||
float ownerWidth{-1};
|
||||
float ownerHeight{-1};
|
||||
|
||||
bool operator==(CachedMeasurement measurement) const {
|
||||
bool isEqual = widthSizingMode == measurement.widthSizingMode &&
|
||||
heightSizingMode == measurement.heightSizingMode;
|
||||
@@ -45,6 +48,14 @@ struct CachedMeasurement {
|
||||
!yoga::isUndefined(measurement.computedHeight)) {
|
||||
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
||||
}
|
||||
if (!yoga::isUndefined(ownerWidth) ||
|
||||
!yoga::isUndefined(measurement.ownerWidth)) {
|
||||
isEqual = isEqual && ownerWidth == measurement.ownerWidth;
|
||||
}
|
||||
if (!yoga::isUndefined(ownerHeight) ||
|
||||
!yoga::isUndefined(measurement.ownerHeight)) {
|
||||
isEqual = isEqual && ownerHeight == measurement.ownerHeight;
|
||||
}
|
||||
|
||||
return isEqual;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
@@ -341,6 +342,22 @@ class YG_EXPORT Style {
|
||||
: FloatOptional{0.0});
|
||||
}
|
||||
|
||||
// Percentage margins and paddings resolve against the owner's width on both
|
||||
// axes, and a percentage size or size bound against the owner's size on its
|
||||
// own axis.
|
||||
bool resolvesAgainstOwnerWidth() const {
|
||||
return anyIsPercent(margin_) || anyIsPercent(padding_) ||
|
||||
dimensions_[yoga::to_underlying(Dimension::Width)].isPercent() ||
|
||||
minDimensions_[yoga::to_underlying(Dimension::Width)].isPercent() ||
|
||||
maxDimensions_[yoga::to_underlying(Dimension::Width)].isPercent();
|
||||
}
|
||||
|
||||
bool resolvesAgainstOwnerHeight() const {
|
||||
return dimensions_[yoga::to_underlying(Dimension::Height)].isPercent() ||
|
||||
minDimensions_[yoga::to_underlying(Dimension::Height)].isPercent() ||
|
||||
maxDimensions_[yoga::to_underlying(Dimension::Height)].isPercent();
|
||||
}
|
||||
|
||||
FloatOptional aspectRatio() const {
|
||||
return pool_.getNumber(aspectRatio_);
|
||||
}
|
||||
@@ -677,6 +694,15 @@ class YG_EXPORT Style {
|
||||
using Edges = std::array<StyleValueHandle, ordinalCount<Edge>()>;
|
||||
using Gutters = std::array<StyleValueHandle, ordinalCount<Gutter>()>;
|
||||
|
||||
template <size_t N>
|
||||
static inline bool anyIsPercent(
|
||||
const std::array<StyleValueHandle, N>& handles) {
|
||||
return std::any_of(
|
||||
handles.begin(), handles.end(), [](const StyleValueHandle& handle) {
|
||||
return handle.isPercent();
|
||||
});
|
||||
}
|
||||
|
||||
static inline bool numbersEqual(
|
||||
const StyleValueHandle& lhsHandle,
|
||||
const StyleValuePool& lhsPool,
|
||||
|
||||
@@ -6686,6 +6686,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -7048,6 +7050,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -11116,6 +11116,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -11478,6 +11480,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -6535,6 +6535,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -6897,6 +6899,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -6535,6 +6535,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -6897,6 +6899,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -8470,6 +8470,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -8832,6 +8834,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -12935,6 +12935,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -13297,6 +13299,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -8321,6 +8321,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -8683,6 +8685,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -8329,6 +8329,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -8691,6 +8693,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -3930,6 +3930,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -4292,6 +4294,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -8260,6 +8260,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -8622,6 +8624,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -3923,6 +3923,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -4285,6 +4287,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
@@ -3923,6 +3923,8 @@ class facebook::yoga::Style {
|
||||
public bool isInlineStartPositionAuto(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool isInlineStartPositionDefined(facebook::yoga::FlexDirection axis, facebook::yoga::Direction direction) const;
|
||||
public bool operator==(const facebook::yoga::Style& other) const;
|
||||
public bool resolvesAgainstOwnerHeight() const;
|
||||
public bool resolvesAgainstOwnerWidth() const;
|
||||
public bool verticalInsetsDefined() const;
|
||||
public const facebook::yoga::GridLine& gridColumnEnd() const;
|
||||
public const facebook::yoga::GridLine& gridColumnStart() const;
|
||||
@@ -4285,6 +4287,8 @@ struct facebook::yoga::CachedMeasurement {
|
||||
public float availableWidth;
|
||||
public float computedHeight;
|
||||
public float computedWidth;
|
||||
public float ownerHeight;
|
||||
public float ownerWidth;
|
||||
}
|
||||
|
||||
struct facebook::yoga::Event {
|
||||
|
||||
Reference in new issue
Block a user