feat(css-bkg-pos): Added possibility to declare background pos by single numeric value (#7958)

* feat(css-bkg-pos): Added possibility to declare background pos by single numeric value

* feat(css-bkg-pos): Implemented numeric bkg pos for iOS

* feat(css-bkg-pos): removed unnecessary code

Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
This commit is contained in:
Nicu
2020-03-24 10:17:35 +02:00
committed by GitHub
parent 42fc4acea3
commit 1f04469fb3
2 changed files with 53 additions and 19 deletions

View File

@ -204,10 +204,12 @@ function parsePosition(pos: string): { x: CSSValue, y: CSSValue } {
return { x: values[0], y: values[1] };
}
if (values.length === 1 && values[0].type === "ident") {
const val = values[0].string.toLocaleLowerCase();
if (values.length === 1) {
const center = { type: "ident", string: "center" };
if (values[0].type === "ident") {
const val = values[0].string.toLocaleLowerCase();
// If you only one keyword is specified, the other value is "center"
if (val === "left" || val === "right") {
return { x: values[0], y: center };
@ -216,6 +218,9 @@ function parsePosition(pos: string): { x: CSSValue, y: CSSValue } {
} else if (val === "center") {
return { x: center, y: center };
}
} else if (values[0].type === "number") {
return {x: values[0], y: center};
}
}
return null;
@ -317,6 +322,18 @@ function getDrawParams(this: void, image: UIImage, background: BackgroundDefinit
res.posX = spaceX;
}
if (v.y.string.toLowerCase() === "center") {
res.posY = spaceY / 2;
} else if (v.y.string.toLowerCase() === "bottom") {
res.posY = spaceY;
}
} else if (v.x.type === "number" && v.y.type === "ident") {
if (v.x.unit === "%") {
res.posX = spaceX * v.x.value / 100;
} else if (v.x.unit === "px" || v.x.unit === "") {
res.posX = v.x.value;
}
if (v.y.string.toLowerCase() === "center") {
res.posY = spaceY / 2;
} else if (v.y.string.toLowerCase() === "bottom") {

View File

@ -713,6 +713,18 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
res.posX = spaceX;
}
if ("center".equals(vy.getString().toLowerCase(Locale.ENGLISH))) {
res.posY = spaceY / 2;
} else if ("bottom".equals(vy.getString().toLowerCase(Locale.ENGLISH))) {
res.posY = spaceY;
}
} else if ("number".equals(vx.getType()) && "ident".equals(vy.getType())) {
if ("%".equals(vx.getUnit())) {
res.posX = spaceX * vx.getValue() / 100;
} else if ("px".equals(vx.getUnit()) || vx.getUnit() == null || vx.getUnit().isEmpty()) {
res.posX = vx.getValue();
}
if ("center".equals(vy.getString().toLowerCase(Locale.ENGLISH))) {
res.posY = spaceY / 2;
} else if ("bottom".equals(vy.getString().toLowerCase(Locale.ENGLISH))) {
@ -731,11 +743,13 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
}
CSSValue[] result = null;
if (values.length == 1 && "ident".equals(values[0].getType())) {
String val = values[0].getString().toLowerCase(Locale.ENGLISH);
if (values.length == 1) {
// If you only one keyword is specified, the other value is "center"
CSSValue center = new CSSValue("ident", "center", null, 0);
// If you only one keyword is specified, the other value is "center"
if ("ident".equals(values[0].getType())) {
String val = values[0].getString().toLowerCase(Locale.ENGLISH);
if ("left".equals(val) || "right".equals(val)) {
result = new CSSValue[]{values[0], center};
} else if ("top".equals(val) || "bottom".equals(val)) {
@ -743,6 +757,9 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
} else if ("center".equals(val)) {
result = new CSSValue[]{center, center};
}
} else if ("number".equals(values[0].getType())) {
result = new CSSValue[]{values[0], center};
}
}
return result;