Fixup recent fix to flex basis and put it behind an experimental flag

Summary: D4207106 previously fixed an issue where the computed flex basis was cached in between layout calculations, potentially caching wrong values. After landing we noticed that some product were implicitly relying on this behavior so this diff instead puts that behind a feature flag.

Reviewed By: gkassabli

Differential Revision: D4222910

fbshipit-source-id: d693482441fcc4d37a288e2e3529057a04f60541
This commit is contained in:
Emil Sjolander
2016-11-23 05:25:50 -08:00
committed by Facebook Github Bot
parent dc10fdd958
commit a0d560a24b
7 changed files with 28 additions and 3 deletions

View File

@@ -68,6 +68,7 @@ typedef enum CSSDirection {
typedef enum CSSExperimentalFeature {
CSSExperimentalFeatureRounding,
CSSExperimentalFeatureWebFlexBasis,
CSSExperimentalFeatureCount,
} CSSExperimentalFeature;

View File

@@ -977,7 +977,8 @@ static void computeChildFlexBasis(const CSSNodeRef node,
if (!CSSValueIsUndefined(CSSNodeStyleGetFlexBasis(child)) &&
!CSSValueIsUndefined(isMainAxisRow ? width : height)) {
if (CSSValueIsUndefined(child->layout.computedFlexBasis) ||
child->layout.computedFlexBasisGeneration != gCurrentGenerationCount) {
(CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeatureWebFlexBasis) &&
child->layout.computedFlexBasisGeneration != gCurrentGenerationCount)) {
child->layout.computedFlexBasis =
fmaxf(CSSNodeStyleGetFlexBasis(child), getPaddingAndBorderAxis(child, mainAxis));
}

View File

@@ -16,6 +16,12 @@
@end
@implementation CSSNodeBridge
+ (void)initialize
{
CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureWebFlexBasis, true);
}
- (instancetype)init
{
if ([super init]) {

View File

@@ -12,5 +12,6 @@ namespace Facebook.CSSLayout
public enum CSSExperimentalFeature
{
Rounding,
WebFlexBasis,
}
}

View File

@@ -79,6 +79,8 @@ ENUMS = {
],
'CSSExperimentalFeature': [
'Rounding',
# Mimic web flex-basis behavior.
'WebFlexBasis',
],
'CSSPrintOptions': [
('Layout', 1),

View File

@@ -10,7 +10,8 @@
package com.facebook.csslayout;
public enum CSSExperimentalFeature {
ROUNDING(0);
ROUNDING(0),
WEB_FLEX_BASIS(1);
private int mIntValue;
@@ -25,6 +26,7 @@ public enum CSSExperimentalFeature {
public static CSSExperimentalFeature fromInt(int value) {
switch (value) {
case 0: return ROUNDING;
case 1: return WEB_FLEX_BASIS;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
}
}

View File

@@ -10,7 +10,19 @@
#include <CSSLayout/CSSLayout.h>
#include <gtest/gtest.h>
TEST(CSSLayoutTest, dont_cache_computed_flex_basis_between_layouts) {
class CSSLayoutRelayoutTest : public ::testing::Test {
protected:
virtual void SetUp() {
CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureWebFlexBasis, true);
}
virtual void TearDown() {
CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureWebFlexBasis, false);
}
};
TEST_F(CSSLayoutRelayoutTest, dont_cache_computed_flex_basis_between_layouts) {
const CSSNodeRef root = CSSNodeNew();
const CSSNodeRef root_child0 = CSSNodeNew();