Permalink
Browse files

Optimize ReactShadowNode by more manually converting between string a…

…nd enums

Reviewed By: astreet

Differential Revision: D4778954

fbshipit-source-id: ee96415e6787ccfd8eb7a560d76d206db3eaee1d
  • Loading branch information...
emilsjolander authored and facebook-github-bot committed Mar 29, 2017
1 parent fd6f222 commit 436a9a5bf74536ab356460701ecfb7933cf2d9a6
Showing with 275 additions and 26 deletions.
  1. +275 −26 ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java
@@ -4,9 +4,9 @@
import javax.annotation.Nullable;
import java.util.Locale;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReadableType;
import com.facebook.yoga.YogaAlign;
@@ -246,22 +246,60 @@ public void setFlexDirection(@Nullable String flexDirection) {
if (isVirtual()) {
return;
}
setFlexDirection(
flexDirection == null ? YogaFlexDirection.COLUMN : YogaFlexDirection.valueOf(
flexDirection.toUpperCase(Locale.US).replace("-", "_")));
if (flexDirection == null) {
setFlexDirection(YogaFlexDirection.COLUMN);
return;
}
switch (flexDirection) {
case "column": {
setFlexDirection(YogaFlexDirection.COLUMN);
break;
}
case "column-reverse": {
setFlexDirection(YogaFlexDirection.COLUMN_REVERSE);
break;
}
case "row": {
setFlexDirection(YogaFlexDirection.ROW);
break;
}
case "row-reverse": {
setFlexDirection(YogaFlexDirection.ROW_REVERSE);
break;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for flexDirection: " + flexDirection);
}
}
}
@ReactProp(name = ViewProps.FLEX_WRAP)
public void setFlexWrap(@Nullable String flexWrap) {
if (isVirtual()) {
return;
}
if (flexWrap == null || flexWrap.equals("nowrap")) {
if (flexWrap == null) {
setFlexWrap(YogaWrap.NO_WRAP);
} else if (flexWrap.equals("wrap")) {
setFlexWrap(YogaWrap.WRAP);
} else {
throw new IllegalArgumentException("Unknown flexWrap value: " + flexWrap);
return;
}
switch (flexWrap) {
case "nowrap": {
setFlexWrap(YogaWrap.NO_WRAP);
break;
}
case "wrap": {
setFlexWrap(YogaWrap.WRAP);
break;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for flexWrap: " + flexWrap);
}
}
}
@@ -270,55 +308,249 @@ public void setAlignSelf(@Nullable String alignSelf) {
if (isVirtual()) {
return;
}
setAlignSelf(alignSelf == null ? YogaAlign.AUTO : YogaAlign.valueOf(
alignSelf.toUpperCase(Locale.US).replace("-", "_")));
if (alignSelf == null) {
setAlignSelf(YogaAlign.AUTO);
return;
}
switch (alignSelf) {
case "auto": {
setAlignSelf(YogaAlign.AUTO);
return;
}
case "flex-start": {
setAlignSelf(YogaAlign.FLEX_START);
return;
}
case "center": {
setAlignSelf(YogaAlign.CENTER);
return;
}
case "flex-end": {
setAlignSelf(YogaAlign.FLEX_END);
return;
}
case "stretch": {
setAlignSelf(YogaAlign.STRETCH);
return;
}
case "baseline": {
setAlignSelf(YogaAlign.BASELINE);
return;
}
case "space-between": {
setAlignSelf(YogaAlign.SPACE_BETWEEN);
return;
}
case "space-around": {
setAlignSelf(YogaAlign.SPACE_AROUND);
return;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for alignSelf: " + alignSelf);
}
}
}
@ReactProp(name = ViewProps.ALIGN_ITEMS)
public void setAlignItems(@Nullable String alignItems) {
if (isVirtual()) {
return;
}
setAlignItems(
alignItems == null ? YogaAlign.STRETCH : YogaAlign.valueOf(
alignItems.toUpperCase(Locale.US).replace("-", "_")));
if (alignItems == null) {
setAlignItems(YogaAlign.STRETCH);
return;
}
switch (alignItems) {
case "auto": {
setAlignItems(YogaAlign.AUTO);
return;
}
case "flex-start": {
setAlignItems(YogaAlign.FLEX_START);
return;
}
case "center": {
setAlignItems(YogaAlign.CENTER);
return;
}
case "flex-end": {
setAlignItems(YogaAlign.FLEX_END);
return;
}
case "stretch": {
setAlignItems(YogaAlign.STRETCH);
return;
}
case "baseline": {
setAlignItems(YogaAlign.BASELINE);
return;
}
case "space-between": {
setAlignItems(YogaAlign.SPACE_BETWEEN);
return;
}
case "space-around": {
setAlignItems(YogaAlign.SPACE_AROUND);
return;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for alignItems: " + alignItems);
}
}
}
@ReactProp(name = ViewProps.ALIGN_CONTENT)
public void setAlignContent(@Nullable String alignContent) {
if (isVirtual()) {
return;
}
setAlignContent(
alignContent == null ? YogaAlign.FLEX_START : YogaAlign.valueOf(
alignContent.toUpperCase(Locale.US).replace("-", "_")));
if (alignContent == null) {
setAlignContent(YogaAlign.FLEX_START);
return;
}
switch (alignContent) {
case "auto": {
setAlignContent(YogaAlign.AUTO);
return;
}
case "flex-start": {
setAlignContent(YogaAlign.FLEX_START);
return;
}
case "center": {
setAlignContent(YogaAlign.CENTER);
return;
}
case "flex-end": {
setAlignContent(YogaAlign.FLEX_END);
return;
}
case "stretch": {
setAlignContent(YogaAlign.STRETCH);
return;
}
case "baseline": {
setAlignContent(YogaAlign.BASELINE);
return;
}
case "space-between": {
setAlignContent(YogaAlign.SPACE_BETWEEN);
return;
}
case "space-around": {
setAlignContent(YogaAlign.SPACE_AROUND);
return;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for alignContent: " + alignContent);
}
}
}
@ReactProp(name = ViewProps.JUSTIFY_CONTENT)
public void setJustifyContent(@Nullable String justifyContent) {
if (isVirtual()) {
return;
}
setJustifyContent(justifyContent == null ? YogaJustify.FLEX_START : YogaJustify.valueOf(
justifyContent.toUpperCase(Locale.US).replace("-", "_")));
if (justifyContent == null) {
setJustifyContent(YogaJustify.FLEX_START);
return;
}
switch (justifyContent) {
case "flex-start": {
setJustifyContent(YogaJustify.FLEX_START);
break;
}
case "center": {
setJustifyContent(YogaJustify.CENTER);
break;
}
case "flex-end": {
setJustifyContent(YogaJustify.FLEX_END);
break;
}
case "space-between": {
setJustifyContent(YogaJustify.SPACE_BETWEEN);
break;
}
case "space-around": {
setJustifyContent(YogaJustify.SPACE_AROUND);
break;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for justifyContent: " + justifyContent);
}
}
}
@ReactProp(name = ViewProps.OVERFLOW)
public void setOverflow(@Nullable String overflow) {
if (isVirtual()) {
return;
}
setOverflow(overflow == null ? YogaOverflow.VISIBLE : YogaOverflow.valueOf(
overflow.toUpperCase(Locale.US).replace("-", "_")));
if (overflow == null) {
setOverflow(YogaOverflow.VISIBLE);
return;
}
switch (overflow) {
case "visible": {
setOverflow(YogaOverflow.VISIBLE);
break;
}
case "hidden": {
setOverflow(YogaOverflow.HIDDEN);
break;
}
case "scroll": {
setOverflow(YogaOverflow.SCROLL);
break;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for overflow: " + overflow);
}
}
}
@ReactProp(name = ViewProps.DISPLAY)
public void setDisplay(@Nullable String display) {
if (isVirtual()) {
return;
}
setDisplay(display == null ? YogaDisplay.FLEX : YogaDisplay.valueOf(
display.toUpperCase(Locale.US).replace("-", "_")));
if (display == null) {
setDisplay(YogaDisplay.FLEX);
return;
}
switch (display) {
case "flex": {
setDisplay(YogaDisplay.FLEX);
break;
}
case "none": {
setDisplay(YogaDisplay.NONE);
break;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for display: " + display);
}
}
}
@ReactPropGroup(names = {
@@ -424,9 +656,26 @@ public void setPosition(@Nullable String position) {
if (isVirtual()) {
return;
}
YogaPositionType positionType = position == null ?
YogaPositionType.RELATIVE : YogaPositionType.valueOf(position.toUpperCase(Locale.US));
setPositionType(positionType);
if (position == null) {
setPositionType(YogaPositionType.RELATIVE);
return;
}
switch (position) {
case "relative": {
setPositionType(YogaPositionType.RELATIVE);
break;
}
case "absolute": {
setPositionType(YogaPositionType.ABSOLUTE);
break;
}
default: {
throw new JSApplicationIllegalArgumentException(
"invalid value for position: " + position);
}
}
}
@Override

0 comments on commit 436a9a5

Please sign in to comment.