Files
vultix 5a83a1c858 Css gradients (#5534)
* feat(ios): Added support for css gradients.

* feat(android): Added support for css gradients.

* fix: Fixed gradient borders on ios

* fix(gradient): added backgroundGradient to View and Style.

* fix(ios-gradients): fixed ios gradients covering view content.

* test(gradient): Added ui app tests for background gradients.

* test(gradient): Added a test ensuring background gradient property is applied to style.

* style(gradient): Fixed tslint errors.

* fix(gradient): Removed the background-gradient property and added the gradient to background-image.

* style: fixed a consecutive blank line tslint error.

* fix(tests): fixed the bug that was causing tests to fail.

* chore(linear-gradient): fix equality comparer

* test(gradient): add linear gradients test app

* chore(tslint): update with latest tslint rules
2018-05-03 13:24:41 +03:00

64 lines
1.7 KiB
TypeScript

import { LengthPercentUnit } from "./style-properties";
import * as parser from "../../css/parser";
import { Color } from "../../color";
export class LinearGradient {
public angle: number;
public colorStops: ColorStop[];
static parse(value: parser.LinearGradient): LinearGradient {
const result = new LinearGradient();
result.angle = value.angle;
result.colorStops = value.colors.map(color => {
const offset = color.offset || null;
let offsetUnit: LengthPercentUnit;
if (offset && offset.unit === "%") {
offsetUnit = {
unit: "%",
value: offset.value
};
}
return {
color: new Color(color.argb),
offset: offsetUnit
}
});
return result;
}
static equals(first: LinearGradient, second: LinearGradient): boolean {
if (!first && !second) {
return true;
} else if (!first || !second) {
return false
}
if (first.angle !== second.angle) {
return false;
}
if (first.colorStops.length !== second.colorStops.length) {
return false;
}
for (let i = 0; i < first.colorStops.length; i++) {
const firstStop = first.colorStops[i];
const secondStop = second.colorStops[i];
if (firstStop.offset !== secondStop.offset) {
return false;
}
if (!Color.equals(firstStop.color, secondStop.color)) {
return false;
}
}
return true;
}
}
export interface ColorStop {
color: Color;
offset?: LengthPercentUnit;
}