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; 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 * 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 getLayoutWidth();
float getLayoutHeight(); float getLayoutHeight();
CSSDirection getLayoutDirection(); CSSDirection getLayoutDirection();
void setDefaultPadding(int spacingType, float padding);
CSSOverflow getOverflow(); CSSOverflow getOverflow();
void setOverflow(CSSOverflow overflow); void setOverflow(CSSOverflow overflow);
void setData(Object data); void setData(Object data);

View File

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

View File

@@ -30,7 +30,7 @@ public class CSSStyle {
public Spacing margin = new Spacing(); public Spacing margin = new Spacing();
public Spacing padding = new Spacing(); public Spacing padding = new Spacing();
public Spacing border = 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]; public float[] dimensions = new float[2];
@@ -61,13 +61,6 @@ public class CSSStyle {
border.reset(); border.reset();
position.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); Arrays.fill(dimensions, CSSConstants.UNDEFINED);
minWidth = CSSConstants.UNDEFINED; minWidth = CSSConstants.UNDEFINED;

View File

@@ -9,8 +9,6 @@
package com.facebook.csslayout; package com.facebook.csslayout;
import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
/** /**
@@ -71,10 +69,18 @@ public class Spacing {
}; };
private final float[] mSpacing = newFullSpacingArray(); private final float[] mSpacing = newFullSpacingArray();
@Nullable private float[] mDefaultSpacing = null;
private int mValueFlags = 0; private int mValueFlags = 0;
private float mDefaultValue;
private boolean mHasAliasesSet; private boolean mHasAliasesSet;
public Spacing() {
this(0);
}
public Spacing(float defaultValue) {
mDefaultValue = defaultValue;
}
/** /**
* Set a spacing value. * Set a spacing value.
* *
@@ -101,25 +107,7 @@ public class Spacing {
return true; 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; return false;
} }
@@ -129,9 +117,9 @@ public class Spacing {
* @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM} * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}
*/ */
public float get(int spacingType) { public float get(int spacingType) {
float defaultValue = (mDefaultSpacing != null) float defaultValue = (spacingType == START || spacingType == END
? mDefaultSpacing[spacingType] ? CSSConstants.UNDEFINED
: (spacingType == START || spacingType == END ? CSSConstants.UNDEFINED : 0); : mDefaultValue);
if (mValueFlags == 0) { if (mValueFlags == 0) {
return defaultValue; return defaultValue;
@@ -170,7 +158,6 @@ public class Spacing {
*/ */
void reset() { void reset() {
Arrays.fill(mSpacing, CSSConstants.UNDEFINED); Arrays.fill(mSpacing, CSSConstants.UNDEFINED);
mDefaultSpacing = null;
mHasAliasesSet = false; mHasAliasesSet = false;
mValueFlags = 0; mValueFlags = 0;
} }
@@ -200,22 +187,4 @@ public class Spacing {
CSSConstants.UNDEFINED, 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,
};
}
} }