mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Move default spacing out of csslayout
Reviewed By: foghina Differential Revision: D3709574 fbshipit-source-id: 6e0277bd97407a5c642d742f93ca2ac70d7307da
This commit is contained in:
committed by
Facebook Github Bot 4
parent
a2a8d7f5da
commit
fd34c6d567
@@ -13,7 +13,9 @@ import javax.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.facebook.csslayout.CSSConstants;
|
||||
import com.facebook.csslayout.CSSNode;
|
||||
import com.facebook.csslayout.Spacing;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.uimanager.annotations.ReactPropertyHolder;
|
||||
|
||||
@@ -59,6 +61,8 @@ public class ReactShadowNode extends CSSNode {
|
||||
private float mAbsoluteTop;
|
||||
private float mAbsoluteRight;
|
||||
private float mAbsoluteBottom;
|
||||
private final Spacing mDefaultPadding = new Spacing(0);
|
||||
private final Spacing mPadding = new Spacing(CSSConstants.UNDEFINED);
|
||||
|
||||
/**
|
||||
* Nodes that return {@code true} will be treated as "virtual" nodes. That is, nodes that are not
|
||||
@@ -116,6 +120,48 @@ public class ReactShadowNode extends CSSNode {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultPadding(int spacingType, float padding) {
|
||||
mDefaultPadding.set(spacingType, padding);
|
||||
updatePadding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPadding(int spacingType, float padding) {
|
||||
mPadding.set(spacingType, padding);
|
||||
updatePadding();
|
||||
}
|
||||
|
||||
private void updatePadding() {
|
||||
for (int spacingType = Spacing.LEFT; spacingType <= Spacing.ALL; spacingType++) {
|
||||
if (spacingType == Spacing.LEFT ||
|
||||
spacingType == Spacing.RIGHT ||
|
||||
spacingType == Spacing.START ||
|
||||
spacingType == Spacing.END) {
|
||||
if (CSSConstants.isUndefined(mPadding.getRaw(spacingType)) &&
|
||||
CSSConstants.isUndefined(mPadding.getRaw(Spacing.HORIZONTAL)) &&
|
||||
CSSConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) {
|
||||
super.setPadding(spacingType, mDefaultPadding.getRaw(spacingType));
|
||||
} else {
|
||||
super.setPadding(spacingType, mPadding.getRaw(spacingType));
|
||||
}
|
||||
} else if (spacingType == Spacing.TOP || spacingType == Spacing.BOTTOM) {
|
||||
if (CSSConstants.isUndefined(mPadding.getRaw(spacingType)) &&
|
||||
CSSConstants.isUndefined(mPadding.getRaw(Spacing.VERTICAL)) &&
|
||||
CSSConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) {
|
||||
super.setPadding(spacingType, mDefaultPadding.getRaw(spacingType));
|
||||
} else {
|
||||
super.setPadding(spacingType, mPadding.getRaw(spacingType));
|
||||
}
|
||||
} else {
|
||||
if (CSSConstants.isUndefined(mPadding.getRaw(spacingType))) {
|
||||
super.setPadding(spacingType, mDefaultPadding.getRaw(spacingType));
|
||||
} else {
|
||||
super.setPadding(spacingType, mPadding.getRaw(spacingType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChildAt(CSSNode child, int i) {
|
||||
super.addChildAt(child, i);
|
||||
|
||||
+9
-10
@@ -145,7 +145,7 @@ import com.facebook.csslayout.Spacing;
|
||||
super.getOutline(outline);
|
||||
return;
|
||||
}
|
||||
if((!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) {
|
||||
if ((!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) {
|
||||
updatePath();
|
||||
|
||||
outline.setConvexPath(mPathForBorderRadiusOutline);
|
||||
@@ -176,10 +176,10 @@ import com.facebook.csslayout.Spacing;
|
||||
// set RGB component
|
||||
if (mBorderRGB == null) {
|
||||
mBorderRGB = new Spacing();
|
||||
mBorderRGB.setDefault(Spacing.LEFT, DEFAULT_BORDER_RGB);
|
||||
mBorderRGB.setDefault(Spacing.TOP, DEFAULT_BORDER_RGB);
|
||||
mBorderRGB.setDefault(Spacing.RIGHT, DEFAULT_BORDER_RGB);
|
||||
mBorderRGB.setDefault(Spacing.BOTTOM, DEFAULT_BORDER_RGB);
|
||||
mBorderRGB.set(Spacing.LEFT, DEFAULT_BORDER_RGB);
|
||||
mBorderRGB.set(Spacing.TOP, DEFAULT_BORDER_RGB);
|
||||
mBorderRGB.set(Spacing.RIGHT, DEFAULT_BORDER_RGB);
|
||||
mBorderRGB.set(Spacing.BOTTOM, DEFAULT_BORDER_RGB);
|
||||
}
|
||||
if (!FloatUtil.floatsEqual(mBorderRGB.getRaw(position), rgb)) {
|
||||
mBorderRGB.set(position, rgb);
|
||||
@@ -191,10 +191,10 @@ import com.facebook.csslayout.Spacing;
|
||||
// set Alpha component
|
||||
if (mBorderAlpha == null) {
|
||||
mBorderAlpha = new Spacing();
|
||||
mBorderAlpha.setDefault(Spacing.LEFT, DEFAULT_BORDER_ALPHA);
|
||||
mBorderAlpha.setDefault(Spacing.TOP, DEFAULT_BORDER_ALPHA);
|
||||
mBorderAlpha.setDefault(Spacing.RIGHT, DEFAULT_BORDER_ALPHA);
|
||||
mBorderAlpha.setDefault(Spacing.BOTTOM, DEFAULT_BORDER_ALPHA);
|
||||
mBorderAlpha.set(Spacing.LEFT, DEFAULT_BORDER_ALPHA);
|
||||
mBorderAlpha.set(Spacing.TOP, DEFAULT_BORDER_ALPHA);
|
||||
mBorderAlpha.set(Spacing.RIGHT, DEFAULT_BORDER_ALPHA);
|
||||
mBorderAlpha.set(Spacing.BOTTOM, DEFAULT_BORDER_ALPHA);
|
||||
}
|
||||
if (!FloatUtil.floatsEqual(mBorderAlpha.getRaw(position), alpha)) {
|
||||
mBorderAlpha.set(position, alpha);
|
||||
@@ -291,7 +291,6 @@ import com.facebook.csslayout.Spacing;
|
||||
float bottomRightRadius = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[2]) ? mBorderCornerRadii[2] : defaultBorderRadius;
|
||||
float bottomLeftRadius = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[3]) ? mBorderCornerRadii[3] : defaultBorderRadius;
|
||||
|
||||
|
||||
mPathForBorderRadius.addRoundRect(
|
||||
mTempRectForBorderRadius,
|
||||
new float[] {
|
||||
|
||||
Reference in New Issue
Block a user