Provide RTL support for RCTShadowView according to new csslayout

Summary:
@public The make current RCTShadowView support RTL layout.
1 Change all left/right to start/end for margin, padding, boarder and position
2 Calculate position in the same way as margin, padding and boarder

Reviewed By: fkgozali

Differential Revision: D3619292

fbshipit-source-id: eaaa6faeee93c964d59bb6f498d89effc09ed567
This commit is contained in:
Mengjue Wang
2016-07-29 10:30:34 -07:00
committed by Facebook Github Bot 6
parent 5e7d95b403
commit 5207b90420
2 changed files with 65 additions and 73 deletions

View File

@@ -378,11 +378,11 @@ public class CSSNode {
/**
* Get this node's position, as defined by style.
*/
public Spacing getPosition() {
public Spacing getPositionValue() {
return style.position;
}
public void setPosition(int spacingType, float position) {
public void setPositionValue(int spacingType, float position) {
if (style.position.set(spacingType, position)) {
dirty();
}
@@ -396,9 +396,7 @@ public class CSSNode {
}
public void setPositionTop(float positionTop) {
if (style.position.set(TOP, positionTop)) {
dirty();
}
setPositionValue(TOP, positionTop);
}
/**
@@ -409,9 +407,7 @@ public class CSSNode {
}
public void setPositionBottom(float positionBottom) {
if (style.position.set(BOTTOM, positionBottom)) {
dirty();
}
setPositionValue(BOTTOM, positionBottom);
}
/**
@@ -422,9 +418,7 @@ public class CSSNode {
}
public void setPositionLeft(float positionLeft) {
if (style.position.set(LEFT, positionLeft)) {
dirty();
}
setPositionValue(LEFT, positionLeft);
}
/**
@@ -435,9 +429,7 @@ public class CSSNode {
}
public void setPositionRight(float positionRight) {
if (style.position.set(RIGHT, positionRight)) {
dirty();
}
setPositionValue(RIGHT, positionRight);
}
/**

View File

@@ -2957,8 +2957,8 @@ public class LayoutEngineTest {
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.setPosition(Spacing.LEFT, 5);
node_0.setPosition(Spacing.TOP, 5);
node_0.setPositionValue(Spacing.LEFT, 5);
node_0.setPositionValue(Spacing.TOP, 5);
}
TestCSSNode root_layout = new TestCSSNode();
@@ -3016,7 +3016,7 @@ public class LayoutEngineTest {
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.setPosition(Spacing.BOTTOM, 5);
node_0.setPositionValue(Spacing.BOTTOM, 5);
}
TestCSSNode root_layout = new TestCSSNode();
@@ -3037,8 +3037,8 @@ public class LayoutEngineTest {
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.setPosition(Spacing.TOP, 10);
node_0.setPosition(Spacing.BOTTOM, 5);
node_0.setPositionValue(Spacing.TOP, 10);
node_0.setPositionValue(Spacing.BOTTOM, 5);
}
TestCSSNode root_layout = new TestCSSNode();
@@ -3333,8 +3333,8 @@ public class LayoutEngineTest {
node_1.style.dimensions[DIMENSION_HEIGHT] = 100;
node_1 = node_0.getChildAt(1);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.LEFT, 10);
node_1.setPosition(Spacing.TOP, 10);
node_1.setPositionValue(Spacing.LEFT, 10);
node_1.setPositionValue(Spacing.TOP, 10);
}
}
@@ -3381,7 +3381,7 @@ public class LayoutEngineTest {
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.LEFT, 5);
node_1.setPositionValue(Spacing.LEFT, 5);
}
}
@@ -3418,7 +3418,7 @@ public class LayoutEngineTest {
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setMargin(Spacing.TOP, 5);
node_1.setPosition(Spacing.TOP, 5);
node_1.setPositionValue(Spacing.TOP, 5);
}
}
@@ -3455,7 +3455,7 @@ public class LayoutEngineTest {
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setMargin(Spacing.LEFT, 5);
node_1.setPosition(Spacing.LEFT, 5);
node_1.setPositionValue(Spacing.LEFT, 5);
}
}
@@ -4028,7 +4028,7 @@ public class LayoutEngineTest {
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.TOP, -1);
node_1.setPositionValue(Spacing.TOP, -1);
}
}
@@ -4070,7 +4070,7 @@ public class LayoutEngineTest {
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.LEFT, 5);
node_1.setPositionValue(Spacing.LEFT, 5);
}
}
@@ -5199,10 +5199,10 @@ public class LayoutEngineTest {
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.LEFT, 0);
node_1.setPosition(Spacing.TOP, 0);
node_1.setPosition(Spacing.RIGHT, 0);
node_1.setPosition(Spacing.BOTTOM, 0);
node_1.setPositionValue(Spacing.LEFT, 0);
node_1.setPositionValue(Spacing.TOP, 0);
node_1.setPositionValue(Spacing.RIGHT, 0);
node_1.setPositionValue(Spacing.BOTTOM, 0);
}
}
@@ -5384,8 +5384,8 @@ public class LayoutEngineTest {
node_1.style.dimensions[DIMENSION_HEIGHT] = 100;
node_1 = node_0.getChildAt(1);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.LEFT, 0);
node_1.setPosition(Spacing.RIGHT, 0);
node_1.setPositionValue(Spacing.LEFT, 0);
node_1.setPositionValue(Spacing.RIGHT, 0);
}
}
@@ -5427,8 +5427,8 @@ public class LayoutEngineTest {
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.TOP, 0);
node_1.setPosition(Spacing.BOTTOM, 20);
node_1.setPositionValue(Spacing.TOP, 0);
node_1.setPositionValue(Spacing.BOTTOM, 20);
}
}
@@ -5467,10 +5467,10 @@ public class LayoutEngineTest {
node_1 = node_0.getChildAt(0);
node_1.style.justifyContent = CSSJustify.CENTER;
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.LEFT, 0);
node_1.setPosition(Spacing.TOP, 0);
node_1.setPosition(Spacing.RIGHT, 0);
node_1.setPosition(Spacing.BOTTOM, 0);
node_1.setPositionValue(Spacing.LEFT, 0);
node_1.setPositionValue(Spacing.TOP, 0);
node_1.setPositionValue(Spacing.RIGHT, 0);
node_1.setPositionValue(Spacing.BOTTOM, 0);
addChildren(node_1, 1);
{
TestCSSNode node_2;
@@ -5523,7 +5523,7 @@ public class LayoutEngineTest {
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.BOTTOM, 0);
node_1.setPositionValue(Spacing.BOTTOM, 0);
}
}
@@ -5560,7 +5560,7 @@ public class LayoutEngineTest {
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.setPosition(Spacing.RIGHT, 0);
node_1.setPositionValue(Spacing.RIGHT, 0);
}
}
@@ -5598,7 +5598,7 @@ public class LayoutEngineTest {
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.style.dimensions[DIMENSION_HEIGHT] = 10;
node_1.setPosition(Spacing.BOTTOM, 0);
node_1.setPositionValue(Spacing.BOTTOM, 0);
}
}
@@ -5636,7 +5636,7 @@ public class LayoutEngineTest {
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.style.dimensions[DIMENSION_WIDTH] = 10;
node_1.setPosition(Spacing.RIGHT, 0);
node_1.setPositionValue(Spacing.RIGHT, 0);
}
}
@@ -5673,7 +5673,7 @@ public class LayoutEngineTest {
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.style.dimensions[DIMENSION_HEIGHT] = 10;
node_1.setPosition(Spacing.BOTTOM, 0);
node_1.setPositionValue(Spacing.BOTTOM, 0);
}
}
@@ -5710,7 +5710,7 @@ public class LayoutEngineTest {
node_1 = node_0.getChildAt(0);
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.style.dimensions[DIMENSION_WIDTH] = 10;
node_1.setPosition(Spacing.RIGHT, 0);
node_1.setPositionValue(Spacing.RIGHT, 0);
}
}
@@ -5890,7 +5890,7 @@ public class LayoutEngineTest {
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.setPosition(Spacing.LEFT, 5);
node_1.setPositionValue(Spacing.LEFT, 5);
addChildren(node_1, 1);
{
TestCSSNode node_2;
@@ -7297,10 +7297,10 @@ public class LayoutEngineTest {
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.style.maxWidth = 500;
node_1.style.maxHeight = 600;
node_1.setPosition(Spacing.LEFT, 100);
node_1.setPosition(Spacing.TOP, 100);
node_1.setPosition(Spacing.RIGHT, 100);
node_1.setPosition(Spacing.BOTTOM, 100);
node_1.setPositionValue(Spacing.LEFT, 100);
node_1.setPositionValue(Spacing.TOP, 100);
node_1.setPositionValue(Spacing.RIGHT, 100);
node_1.setPositionValue(Spacing.BOTTOM, 100);
}
}
@@ -7340,10 +7340,10 @@ public class LayoutEngineTest {
node_1.style.positionType = CSSPositionType.ABSOLUTE;
node_1.style.minWidth = 900;
node_1.style.minHeight = 1000;
node_1.setPosition(Spacing.LEFT, 100);
node_1.setPosition(Spacing.TOP, 100);
node_1.setPosition(Spacing.RIGHT, 100);
node_1.setPosition(Spacing.BOTTOM, 100);
node_1.setPositionValue(Spacing.LEFT, 100);
node_1.setPositionValue(Spacing.TOP, 100);
node_1.setPositionValue(Spacing.RIGHT, 100);
node_1.setPositionValue(Spacing.BOTTOM, 100);
}
}
@@ -7478,19 +7478,19 @@ public class LayoutEngineTest {
node_1.setPadding(Spacing.BOTTOM, 10);
node_1.setPadding(Spacing.START, 10);
node_1.setPadding(Spacing.END, 10);
node_1.setPosition(Spacing.LEFT, 100);
node_1.setPosition(Spacing.TOP, 100);
node_1.setPosition(Spacing.RIGHT, 100);
node_1.setPosition(Spacing.BOTTOM, 100);
node_1.setPositionValue(Spacing.LEFT, 100);
node_1.setPositionValue(Spacing.TOP, 100);
node_1.setPositionValue(Spacing.RIGHT, 100);
node_1.setPositionValue(Spacing.BOTTOM, 100);
addChildren(node_1, 1);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.style.positionType = CSSPositionType.ABSOLUTE;
node_2.setPosition(Spacing.LEFT, 10);
node_2.setPosition(Spacing.TOP, 10);
node_2.setPosition(Spacing.RIGHT, 10);
node_2.setPosition(Spacing.BOTTOM, 10);
node_2.setPositionValue(Spacing.LEFT, 10);
node_2.setPositionValue(Spacing.TOP, 10);
node_2.setPositionValue(Spacing.RIGHT, 10);
node_2.setPositionValue(Spacing.BOTTOM, 10);
}
}
}
@@ -7550,19 +7550,19 @@ public class LayoutEngineTest {
node_1.setBorder(Spacing.BOTTOM, 1);
node_1.setBorder(Spacing.START, 1);
node_1.setBorder(Spacing.END, 1);
node_1.setPosition(Spacing.LEFT, 100);
node_1.setPosition(Spacing.TOP, 100);
node_1.setPosition(Spacing.RIGHT, 100);
node_1.setPosition(Spacing.BOTTOM, 100);
node_1.setPositionValue(Spacing.LEFT, 100);
node_1.setPositionValue(Spacing.TOP, 100);
node_1.setPositionValue(Spacing.RIGHT, 100);
node_1.setPositionValue(Spacing.BOTTOM, 100);
addChildren(node_1, 1);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.style.positionType = CSSPositionType.ABSOLUTE;
node_2.setPosition(Spacing.LEFT, 10);
node_2.setPosition(Spacing.TOP, 10);
node_2.setPosition(Spacing.RIGHT, 10);
node_2.setPosition(Spacing.BOTTOM, 10);
node_2.setPositionValue(Spacing.LEFT, 10);
node_2.setPositionValue(Spacing.TOP, 10);
node_2.setPositionValue(Spacing.RIGHT, 10);
node_2.setPositionValue(Spacing.BOTTOM, 10);
}
}
}
@@ -7621,10 +7621,10 @@ public class LayoutEngineTest {
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.style.positionType = CSSPositionType.ABSOLUTE;
node_2.setPosition(Spacing.LEFT, 10);
node_2.setPosition(Spacing.TOP, 10);
node_2.setPosition(Spacing.RIGHT, 10);
node_2.setPosition(Spacing.BOTTOM, 10);
node_2.setPositionValue(Spacing.LEFT, 10);
node_2.setPositionValue(Spacing.TOP, 10);
node_2.setPositionValue(Spacing.RIGHT, 10);
node_2.setPositionValue(Spacing.BOTTOM, 10);
}
}
}