Parse YogaValue from string. inverse of toString()
Summary: Implement the inverse of toString. This allows us to parse a YogaValue from a string inputted from the user in debugging tools. Reviewed By: kittens Differential Revision: D5120456 fbshipit-source-id: 6ac7cff2a040778e63a953070e1bd7e768fedaa7
This commit is contained in:
committed by
Facebook Github Bot
parent
aad1c3055c
commit
f68b50bb4b
@@ -15,6 +15,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
|
||||
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 class YogaValue {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user