Fix CSSLayout to Support RTL

Summary:
@public The current CSSLayout can't support RTL because wrong calculation for absolute position.
This change is mainly to fix the issue: https://github.com/facebook/css-layout/issues/197
Three main problems I fixed:
1. Calculate the position in the same way as margin, boarder, and padding. So that to fix the absolute problem.
2. Fix one wrong calculation for leading value when we only know the trailing value. It was hard code for the LTR situation. Now I changed it to depends on the main Axis.
3. Expose getter and setter function for RN to read layout direction and start/end position value.

Reviewed By: fkgozali

Differential Revision: D3616949

fbshipit-source-id: ae7a47cc0a5d02b42b95f87232be51ab144056d9
This commit is contained in:
Mengjue Wang
2016-07-28 14:43:40 -07:00
committed by Facebook Github Bot 1
parent b26794a375
commit 46c842c71a
7 changed files with 260 additions and 194 deletions

View File

@@ -17,10 +17,12 @@ import com.facebook.infer.annotation.Assertions;
import static com.facebook.csslayout.CSSLayout.DIMENSION_HEIGHT;
import static com.facebook.csslayout.CSSLayout.DIMENSION_WIDTH;
import static com.facebook.csslayout.CSSLayout.POSITION_BOTTOM;
import static com.facebook.csslayout.CSSLayout.POSITION_LEFT;
import static com.facebook.csslayout.CSSLayout.POSITION_RIGHT;
import static com.facebook.csslayout.CSSLayout.POSITION_TOP;
import static com.facebook.csslayout.Spacing.BOTTOM;
import static com.facebook.csslayout.Spacing.LEFT;
import static com.facebook.csslayout.Spacing.RIGHT;
import static com.facebook.csslayout.Spacing.TOP;
/**
* A CSS Node. It has a style object you can manipulate at {@link #style}. After calling
@@ -373,16 +375,28 @@ public class CSSNode {
}
}
/**
* Get this node's position, as defined by style.
*/
public Spacing getPosition() {
return style.position;
}
public void setPosition(int spacingType, float position) {
if (style.position.set(spacingType, position)) {
dirty();
}
}
/**
* Get this node's position top, as defined by style.
*/
public float getPositionTop() {
return style.position[POSITION_TOP];
return style.position.get(TOP);
}
public void setPositionTop(float positionTop) {
if (!valuesEqual(style.position[POSITION_TOP], positionTop)) {
style.position[POSITION_TOP] = positionTop;
if (style.position.set(TOP, positionTop)) {
dirty();
}
}
@@ -391,12 +405,11 @@ public class CSSNode {
* Get this node's position bottom, as defined by style.
*/
public float getPositionBottom() {
return style.position[POSITION_BOTTOM];
return style.position.get(BOTTOM);
}
public void setPositionBottom(float positionBottom) {
if (!valuesEqual(style.position[POSITION_BOTTOM], positionBottom)) {
style.position[POSITION_BOTTOM] = positionBottom;
if (style.position.set(BOTTOM, positionBottom)) {
dirty();
}
}
@@ -405,12 +418,11 @@ public class CSSNode {
* Get this node's position left, as defined by style.
*/
public float getPositionLeft() {
return style.position[POSITION_LEFT];
return style.position.get(LEFT);
}
public void setPositionLeft(float positionLeft) {
if (!valuesEqual(style.position[POSITION_LEFT], positionLeft)) {
style.position[POSITION_LEFT] = positionLeft;
if (style.position.set(LEFT, positionLeft)) {
dirty();
}
}
@@ -419,12 +431,11 @@ public class CSSNode {
* Get this node's position right, as defined by style.
*/
public float getPositionRight() {
return style.position[POSITION_RIGHT];
return style.position.get(RIGHT);
}
public void setPositionRight(float positionRight) {
if (!valuesEqual(style.position[POSITION_RIGHT], positionRight)) {
style.position[POSITION_RIGHT] = positionRight;
if (style.position.set(RIGHT, positionRight)) {
dirty();
}
}