add resources to support image tile mode.

This commit is contained in:
吴尚昆
2022-03-17 17:27:02 +08:00
committed by osborn
parent 77617df848
commit 3f017a9beb
6 changed files with 63 additions and 11 deletions

View File

@@ -93,6 +93,7 @@ public class ImageNode extends ViewNode<ImageView> {
private int placeHolderColor = Color.TRANSPARENT;
private int errorColor = Color.TRANSPARENT;
private JSObject stretchInset = null;
private JSObject tileInset = null;
private float imageScale = DoricUtils.getScreenScale();
private Animatable2Compat.AnimationCallback animationCallback = null;
@@ -161,6 +162,10 @@ public class ImageNode extends ViewNode<ImageView> {
if (stretchInsetValue.isObject()) {
this.stretchInset = stretchInsetValue.asObject();
}
JSValue tileInsetValue = jsObject.getProperty("tileInset");
if (tileInsetValue.isObject()) {
this.tileInset = tileInsetValue.asObject();
}
JSValue imageScaleValue = jsObject.getProperty("imageScale");
if (imageScaleValue.isNumber()) {
this.imageScale = imageScaleValue.asNumber().toFloat();
@@ -371,6 +376,27 @@ public class ImageNode extends ViewNode<ImageView> {
(int) (bitmap.getHeight() - bottom)
);
NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(
getContext().getResources(),
bitmap,
DoricUtils.getNinePatchChunk(rect),
rect,
null
);
super.setResource(ninePatchDrawable);
} else if (tileInset != null) {
float left = tileInset.getProperty("left").asNumber().toFloat() * scale;
float top = tileInset.getProperty("top").asNumber().toFloat() * scale;
float right = tileInset.getProperty("right").asNumber().toFloat() * scale;
float bottom = tileInset.getProperty("bottom").asNumber().toFloat() * scale;
Rect rect = new Rect(
(int) left,
(int) top,
(int) (bitmap.getWidth() - right),
(int) (bitmap.getHeight() - bottom)
);
NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(
getContext().getResources(),
bitmap,