Permalink
Browse files

Parse YogaValue from string. inverse of toString()

Reviewed By: kittens

Differential Revision: D5120456

fbshipit-source-id: 6ac7cff2a040778e63a953070e1bd7e768fedaa7
  • Loading branch information...
emilsjolander authored and facebook-github-bot committed May 24, 2017
1 parent 0b4e772 commit e656adcaa8a4eda358f0a2b2bdf8a8f3b7eaabc7
Showing with 21 additions and 0 deletions.
  1. +21 −0 ReactAndroid/src/main/java/com/facebook/yoga/YogaValue.java
@@ -15,6 +15,7 @@
public class YogaValue {
static final YogaValue UNDEFINED = new YogaValue(YogaConstants.UNDEFINED, YogaUnit.UNDEFINED);
static final YogaValue ZERO = new YogaValue(0, YogaUnit.POINT);
static final YogaValue AUTO = new YogaValue(YogaConstants.UNDEFINED, YogaUnit.AUTO);
public final float value;
public final YogaUnit unit;
@@ -60,4 +61,24 @@ public String toString() {
throw new IllegalStateException();
}
}
public static YogaValue parse(String s) {
if (s == null) {
return null;
}
if ("undefined".equals(s)) {
return UNDEFINED;
}
if ("auto".equals(s)) {
return AUTO;
}
if (s.endsWith("%")) {
return new YogaValue(Float.parseFloat(s.substring(0, s.length() - 1)), YogaUnit.PERCENT);
}
return new YogaValue(Float.parseFloat(s), YogaUnit.POINT);
}
}

0 comments on commit e656adc

Please sign in to comment.