Skip to content

Commit 118c73a

Browse files
committed
fix: full support for LinearGradient
1 parent 4a5493b commit 118c73a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/canvas.android.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,21 @@ export class LinearGradient {
441441
return this._native;
442442
}
443443
constructor(param0: number, param1: number, param2: number, param3: any, param4: any, param5: any, param6: any) {
444-
this._native = new android.graphics.LinearGradient(param0, param1, param2, param3, createColorParam(param4), param5 instanceof Array ? param5 : createColorParam(param5), param6);
444+
if (Array.isArray(param4)) {
445+
const testArray = Array.create('int', param4.length);
446+
param4.forEach((c, i) => (testArray[i] = createColorParam(c)));
447+
param4 = testArray;
448+
} else if (param4.hasOwnProperty('length')) {
449+
param4 = createColorParam(param4);
450+
}
451+
if (Array.isArray(param5)) {
452+
const testArray = Array.create('float', param4.length);
453+
param5.forEach((c, i) => (testArray[i] = c));
454+
param5 = testArray;
455+
} else if (param5.hasOwnProperty('length')) {
456+
param5 = createColorParam(param5);
457+
}
458+
this._native = new android.graphics.LinearGradient(param0, param1, param2, param3, param4, param5, param6);
445459
return new Proxy(this, this);
446460
}
447461
get(target, name, receiver) {

src/canvas.ios.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,8 +2120,15 @@ export class LinearGradient {
21202120
get gradient() {
21212121
if (!this._gradient) {
21222122
if (Array.isArray(this.colors)) {
2123+
let stopsRef = null;
2124+
if (this.stops) {
2125+
const CGFloatArray = interop.sizeof(interop.types.id) === 4 ? Float32Array : Float64Array;
2126+
const buffer = CGFloatArray.from(this.stops);
2127+
stopsRef = buffer;
2128+
}
2129+
21232130
const cgColors = this.colors.map((c) => (c instanceof Color ? c : new Color(c)).ios.CGColor);
2124-
this._gradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), cgColors as any, this.stops);
2131+
this._gradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), cgColors as any, stopsRef);
21252132
CFRetain(this._gradient);
21262133
} else {
21272134
const cgColors = [this.colors, this.stops].map((c) => (c instanceof Color ? c : new Color(c)).ios.CGColor);

0 commit comments

Comments
 (0)