mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 07:35:25 +00:00
Parse YogaValue from string. inverse of toString()
Reviewed By: kittens Differential Revision: D5120456 fbshipit-source-id: 6ac7cff2a040778e63a953070e1bd7e768fedaa7
This commit is contained in:
parent
0b4e772e3b
commit
e656adcaa8
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user