diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java index 3f5020e3ad..3d765969e4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java @@ -4,9 +4,9 @@ package com.facebook.react.uimanager; 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,9 +246,34 @@ public class LayoutShadowNode extends ReactShadowNode { 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) @@ -256,12 +281,25 @@ public class LayoutShadowNode extends ReactShadowNode { 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,8 +308,50 @@ public class LayoutShadowNode extends ReactShadowNode { 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) @@ -279,9 +359,50 @@ public class LayoutShadowNode extends ReactShadowNode { 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) @@ -289,9 +410,50 @@ public class LayoutShadowNode extends ReactShadowNode { 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) @@ -299,8 +461,38 @@ public class LayoutShadowNode extends ReactShadowNode { 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) @@ -308,8 +500,30 @@ public class LayoutShadowNode extends ReactShadowNode { 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) @@ -317,8 +531,26 @@ public class LayoutShadowNode extends ReactShadowNode { 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 class LayoutShadowNode extends ReactShadowNode { 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