mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 21:53:30 +00:00
Move default spacing out of csslayout
Reviewed By: foghina Differential Revision: D3709574 fbshipit-source-id: 6e0277bd97407a5c642d742f93ca2ac70d7307da
This commit is contained in:
parent
a2a8d7f5da
commit
fd34c6d567
@ -241,6 +241,23 @@ class BlurOnSubmitExample extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
class ToggleDefaultPaddingExample extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {hasPadding: false};
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<View>
|
||||
<TextInput style={this.state.hasPadding ? { padding: 0 } : null}/>
|
||||
<Text onPress={() => this.setState({hasPadding: !this.state.hasPadding})}>
|
||||
Toggle padding
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
multiline: {
|
||||
height: 60,
|
||||
@ -602,4 +619,8 @@ exports.examples = [
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Toggle Default Padding',
|
||||
render: function(): ReactElement { return <ToggleDefaultPaddingExample />; },
|
||||
},
|
||||
];
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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[] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user