Move default spacing out of csslayout

Summary: The concept of default padding was confusing and only used by react-native android. Makes more sense to let them manage this themselve.

Reviewed By: foghina

Differential Revision: D3709574

fbshipit-source-id: 6e0277bd97407a5c642d742f93ca2ac70d7307da
This commit is contained in:
Emil Sjolander
2016-08-18 03:15:51 -07:00
committed by Facebook Github Bot 2
parent 9d34b4e110
commit 0672f5572f
5 changed files with 13 additions and 67 deletions

View File

@@ -553,16 +553,6 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
return layout.direction;
}
/**
* Set a default padding (left/top/right/bottom) for this node.
*/
@Override
public void setDefaultPadding(int spacingType, float padding) {
if (style.padding.setDefault(spacingType, padding)) {
dirty();
}
}
/**
* Get this node's overflow property, as defined in the style
*/

View File

@@ -79,7 +79,6 @@ public interface CSSNodeAPI<CSSNodeType extends CSSNodeAPI> {
float getLayoutWidth();
float getLayoutHeight();
CSSDirection getLayoutDirection();
void setDefaultPadding(int spacingType, float padding);
CSSOverflow getOverflow();
void setOverflow(CSSOverflow overflow);
void setData(Object data);

View File

@@ -335,11 +335,6 @@ public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> {
jni_CSSNodeStyleSetPadding(mNativePointer, spacingType, padding);
}
@Override
public void setDefaultPadding(int spacingType, float padding) {
// TODO
}
private native float jni_CSSNodeStyleGetBorder(long nativePointer, int edge);
@Override
public Spacing getBorder() {

View File

@@ -30,7 +30,7 @@ public class CSSStyle {
public Spacing margin = new Spacing();
public Spacing padding = new Spacing();
public Spacing border = new Spacing();
public Spacing position = new Spacing();
public Spacing position = new Spacing(CSSConstants.UNDEFINED);
public float[] dimensions = new float[2];
@@ -61,13 +61,6 @@ public class CSSStyle {
border.reset();
position.reset();
position.setDefault(Spacing.LEFT, CSSConstants.UNDEFINED);
position.setDefault(Spacing.RIGHT, CSSConstants.UNDEFINED);
position.setDefault(Spacing.TOP, CSSConstants.UNDEFINED);
position.setDefault(Spacing.BOTTOM, CSSConstants.UNDEFINED);
position.setDefault(Spacing.START, CSSConstants.UNDEFINED);
position.setDefault(Spacing.END, CSSConstants.UNDEFINED);
Arrays.fill(dimensions, CSSConstants.UNDEFINED);
minWidth = CSSConstants.UNDEFINED;

View File

@@ -9,8 +9,6 @@
package com.facebook.csslayout;
import javax.annotation.Nullable;
import java.util.Arrays;
/**
@@ -71,10 +69,18 @@ public class Spacing {
};
private final float[] mSpacing = newFullSpacingArray();
@Nullable private float[] mDefaultSpacing = null;
private int mValueFlags = 0;
private float mDefaultValue;
private boolean mHasAliasesSet;
public Spacing() {
this(0);
}
public Spacing(float defaultValue) {
mDefaultValue = defaultValue;
}
/**
* Set a spacing value.
*
@@ -101,25 +107,7 @@ public class Spacing {
return true;
}
return false;
}
/**
* Set a default spacing value. This is used as a fallback when no spacing has been set for a
* particular direction.
*
* @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}
* @param value the default value for this direction
* @return
*/
public boolean setDefault(int spacingType, float value) {
if (mDefaultSpacing == null) {
mDefaultSpacing = newSpacingResultArray();
}
if (!FloatUtil.floatsEqual(mDefaultSpacing[spacingType], value)) {
mDefaultSpacing[spacingType] = value;
return true;
}
return false;
}
@@ -129,9 +117,9 @@ public class Spacing {
* @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}
*/
public float get(int spacingType) {
float defaultValue = (mDefaultSpacing != null)
? mDefaultSpacing[spacingType]
: (spacingType == START || spacingType == END ? CSSConstants.UNDEFINED : 0);
float defaultValue = (spacingType == START || spacingType == END
? CSSConstants.UNDEFINED
: mDefaultValue);
if (mValueFlags == 0) {
return defaultValue;
@@ -170,7 +158,6 @@ public class Spacing {
*/
void reset() {
Arrays.fill(mSpacing, CSSConstants.UNDEFINED);
mDefaultSpacing = null;
mHasAliasesSet = false;
mValueFlags = 0;
}
@@ -200,22 +187,4 @@ public class Spacing {
CSSConstants.UNDEFINED,
};
}
private static float[] newSpacingResultArray() {
return newSpacingResultArray(0);
}
private static float[] newSpacingResultArray(float defaultValue) {
return new float[] {
defaultValue,
defaultValue,
defaultValue,
defaultValue,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
defaultValue,
defaultValue,
defaultValue,
};
}
}