From d91142a1db717d3c87ebb3c65f6d26f19b7c82c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Sat, 9 May 2020 10:50:58 +0800 Subject: [PATCH] Android: implements multiple segments as gradient color --- .../main/java/pub/doric/shader/ViewNode.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java index 926d4681..a28ad2e2 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -234,15 +234,22 @@ public abstract class ViewNode extends DoricContextHolder { if (prop.isNumber()) { setBackgroundColor(prop.asNumber().toInt()); } else if (prop.isObject()) { - JSValue start = prop.asObject().getProperty("start"); - JSValue end = prop.asObject().getProperty("end"); - JSValue orientation = prop.asObject().getProperty("orientation"); - GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setShape(GradientDrawable.RECTANGLE); - gradientDrawable.setColors(new int[]{start.asNumber().toInt(), end.asNumber().toInt()}); gradientDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); + if (prop.asObject().propertySet().contains("colors")) { + JSValue colors = prop.asObject().getProperty("colors"); + + gradientDrawable.setColors(colors.asArray().toIntArray()); + } else { + JSValue start = prop.asObject().getProperty("start"); + JSValue end = prop.asObject().getProperty("end"); + + gradientDrawable.setColors(new int[]{start.asNumber().toInt(), end.asNumber().toInt()}); + } + JSValue orientation = prop.asObject().getProperty("orientation"); + switch (orientation.asNumber().toInt()) { case 0: gradientDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM);