feat: web backgroundColor support GradientColor
This commit is contained in:
parent
52456165ce
commit
1b60ce87a9
51
doric-web/dist/index.js
vendored
51
doric-web/dist/index.js
vendored
@ -6457,8 +6457,59 @@ var doric_web = (function (exports, axios, sandbox) {
|
||||
}
|
||||
}
|
||||
set backgroundColor(v) {
|
||||
console.log('background');
|
||||
if (typeof v === 'number') {
|
||||
this.applyCSSStyle({ backgroundColor: toRGBAString(v) });
|
||||
}
|
||||
else {
|
||||
let colorsParam = [];
|
||||
const { start, end, colors, locations, orientation = 0 } = v;
|
||||
if (colors) {
|
||||
colorsParam = colors.map((c) => {
|
||||
return toRGBAString(c);
|
||||
});
|
||||
}
|
||||
else if (start && end) {
|
||||
colorsParam.push(...[toRGBAString(start), toRGBAString(end)]);
|
||||
}
|
||||
switch (orientation) {
|
||||
case 1:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to bottom left, ${this.generateGradient(colorsParam, locations)})` });
|
||||
break;
|
||||
case 2:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to left, ${this.generateGradient(colorsParam, locations)})` });
|
||||
break;
|
||||
case 3:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to top left, ${this.generateGradient(colorsParam, locations)})` });
|
||||
break;
|
||||
case 4:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to top, ${this.generateGradient(colorsParam, locations)})` });
|
||||
break;
|
||||
case 5:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to top right, ${this.generateGradient(colorsParam, locations)})` });
|
||||
break;
|
||||
case 6:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to right, ${this.generateGradient(colorsParam, locations)})` });
|
||||
break;
|
||||
case 7:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to bottom right, ${this.generateGradient(colorsParam, locations)})` });
|
||||
break;
|
||||
default:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to bottom, ${this.generateGradient(colorsParam, locations)})` });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
generateGradient(colors, locations) {
|
||||
if (!locations) {
|
||||
return colors.join(', ');
|
||||
}
|
||||
if (colors.length !== locations.length) {
|
||||
throw new Error("Colors and locations arrays must have the same length.");
|
||||
}
|
||||
const gradientStops = colors.map((color, index) => `${color} ${locations[index] * 100}%`);
|
||||
return gradientStops.join(", ");
|
||||
}
|
||||
static create(context, type) {
|
||||
const viewNodeClass = acquireViewNode(type);
|
||||
if (viewNodeClass === undefined) {
|
||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
@ -58,6 +58,14 @@ export interface DVModel {
|
||||
},
|
||||
}
|
||||
|
||||
export interface GradientType {
|
||||
start?: number;
|
||||
end?: number;
|
||||
colors?: number[];
|
||||
locations?: number[];
|
||||
orientation?: number;
|
||||
}
|
||||
|
||||
export abstract class DoricViewNode {
|
||||
viewId = ""
|
||||
viewType = "View"
|
||||
@ -261,7 +269,8 @@ export abstract class DoricViewNode {
|
||||
this.frameHeight = prop as number
|
||||
break
|
||||
case 'backgroundColor':
|
||||
this.backgroundColor = prop as number
|
||||
this.backgroundColor = prop
|
||||
|
||||
break
|
||||
case 'layoutConfig':
|
||||
const layoutConfig = prop
|
||||
@ -367,8 +376,60 @@ export abstract class DoricViewNode {
|
||||
}
|
||||
}
|
||||
|
||||
set backgroundColor(v: number) {
|
||||
this.applyCSSStyle({ backgroundColor: toRGBAString(v) })
|
||||
set backgroundColor(v: number | GradientType) {
|
||||
console.log('background')
|
||||
if (typeof v === 'number') {
|
||||
this.applyCSSStyle({ backgroundColor: toRGBAString(v) });
|
||||
} else {
|
||||
let colorsParam:string[] = []
|
||||
const {start, end, colors, locations, orientation = 0} = v
|
||||
if (colors) {
|
||||
colorsParam = colors.map((c:number) => {
|
||||
return toRGBAString(c)
|
||||
})
|
||||
} else if (start && end){
|
||||
colorsParam.push(...[toRGBAString(start), toRGBAString(end)])
|
||||
}
|
||||
switch (orientation) {
|
||||
case 1 :
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to bottom left, ${this.generateGradient(colorsParam, locations)})` })
|
||||
break
|
||||
case 2:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to left, ${this.generateGradient(colorsParam, locations)})` })
|
||||
break
|
||||
case 3:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to top left, ${this.generateGradient(colorsParam, locations)})` })
|
||||
break
|
||||
case 4:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to top, ${this.generateGradient(colorsParam, locations)})` })
|
||||
break
|
||||
case 5:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to top right, ${this.generateGradient(colorsParam, locations)})` })
|
||||
break
|
||||
case 6:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to right, ${this.generateGradient(colorsParam, locations)})` })
|
||||
break
|
||||
case 7:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to bottom right, ${this.generateGradient(colorsParam, locations)})` })
|
||||
break
|
||||
default:
|
||||
this.applyCSSStyle({ backgroundImage: `linear-gradient(to bottom, ${this.generateGradient(colorsParam, locations)})` })
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generateGradient(colors: string[], locations?:number[]) {
|
||||
if (!locations) {
|
||||
return colors.join(', ')
|
||||
}
|
||||
|
||||
if (colors.length !== locations.length) {
|
||||
throw new Error("Colors and locations arrays must have the same length.");
|
||||
}
|
||||
|
||||
const gradientStops = colors.map((color, index) => `${color} ${locations[index] * 100}%`);
|
||||
return gradientStops.join(", ");
|
||||
}
|
||||
|
||||
static create(context: DoricContext, type: string) {
|
||||
@ -488,7 +549,7 @@ export abstract class DoricViewNode {
|
||||
return this.view.style.backgroundColor
|
||||
}
|
||||
|
||||
setBackgroundColor(v: number) {
|
||||
setBackgroundColor(v: number | GradientType) {
|
||||
this.backgroundColor = v
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user