Summary: @public This fixes measuring of items in the main axis of a container. Previously items were in a lot of cases measured with UNSPECIFIED instead of AT_MOST. This was to support scrolling containers. The correct way to handle scrolling containers is to instead provide them with their own overflow value to activate this behavior. This is also similar to how the web works. This is a breaking change. Most of your layouts will continue to function as before however some of them might not. Typically this is due to having a `flex: 1` style where it is currently a no-op due to being measured with an undefined size but after this change it may collapse your component to take zero size due to the implicit `flexBasis: 0` now being correctly treated. Removing the bad `flex: 1` style or changing it to `flexGrow: 1` should solve most if not all layout issues your see after this diff. Reviewed By: majak Differential Revision: D3876927 fbshipit-source-id: 81ea1c9d6574dd4564a3333f1b3617cf84b4022f
78 lines
2.3 KiB
Java
78 lines
2.3 KiB
Java
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
package com.facebook.csslayout;
|
|
|
|
import java.util.Arrays;
|
|
|
|
/**
|
|
* Where the output of {@link LayoutEngine#layoutNode(CSSNode, float)} will go in the CSSNode.
|
|
*/
|
|
public class CSSLayout {
|
|
// This value was chosen based on empiracle data. Even the most complicated
|
|
// layouts should not require more than 16 entries to fit within the cache.
|
|
public static final int MAX_CACHED_RESULT_COUNT = 16;
|
|
|
|
public static final int POSITION_LEFT = 0;
|
|
public static final int POSITION_TOP = 1;
|
|
public static final int POSITION_RIGHT = 2;
|
|
public static final int POSITION_BOTTOM = 3;
|
|
|
|
public static final int DIMENSION_WIDTH = 0;
|
|
public static final int DIMENSION_HEIGHT = 1;
|
|
|
|
public float[] position = new float[4];
|
|
public float[] dimensions = new float[2];
|
|
public CSSDirection direction = CSSDirection.LTR;
|
|
|
|
public float computedFlexBasis;
|
|
|
|
public int generationCount;
|
|
public CSSDirection lastParentDirection;
|
|
|
|
public int nextCachedMeasurementsIndex;
|
|
public CSSCachedMeasurement[] cachedMeasurements = new CSSCachedMeasurement[MAX_CACHED_RESULT_COUNT];
|
|
public float[] measuredDimensions = new float[2];
|
|
|
|
public CSSCachedMeasurement cachedLayout = new CSSCachedMeasurement();
|
|
|
|
CSSLayout() {
|
|
resetResult();
|
|
}
|
|
|
|
public void resetResult() {
|
|
Arrays.fill(position, 0);
|
|
Arrays.fill(dimensions, CSSConstants.UNDEFINED);
|
|
direction = CSSDirection.LTR;
|
|
|
|
computedFlexBasis = CSSConstants.UNDEFINED;
|
|
|
|
generationCount = 0;
|
|
lastParentDirection = null;
|
|
|
|
nextCachedMeasurementsIndex = 0;
|
|
measuredDimensions[DIMENSION_WIDTH] = CSSConstants.UNDEFINED;
|
|
measuredDimensions[DIMENSION_HEIGHT] = CSSConstants.UNDEFINED;
|
|
|
|
cachedLayout.widthMeasureMode = null;
|
|
cachedLayout.heightMeasureMode = null;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "layout: {" +
|
|
"left: " + position[POSITION_LEFT] + ", " +
|
|
"top: " + position[POSITION_TOP] + ", " +
|
|
"width: " + dimensions[DIMENSION_WIDTH] + ", " +
|
|
"height: " + dimensions[DIMENSION_HEIGHT] + ", " +
|
|
"direction: " + direction +
|
|
"}";
|
|
}
|
|
}
|