Skip to content

Commit aaeda5c

Browse files
committed
fix(ios): gradient error fix when stop outside of 0..1
1 parent 51a0d50 commit aaeda5c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/canvas.ios.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,17 +2123,21 @@ export class LinearGradient {
21232123
let stopsRef = null;
21242124
if (this.stops) {
21252125
const CGFloatArray = interop.sizeof(interop.types.id) === 4 ? Float32Array : Float64Array;
2126-
const buffer = CGFloatArray.from(this.stops);
2126+
const buffer = CGFloatArray.from(this.stops.map((s) => Math.max(0, Math.min(1, s))));
21272127
stopsRef = buffer;
21282128
}
21292129

21302130
const cgColors = this.colors.map((c) => (c instanceof Color ? c : new Color(c)).ios.CGColor);
21312131
this._gradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), cgColors as any, stopsRef);
2132-
CFRetain(this._gradient);
2132+
if (this._gradient) {
2133+
CFRetain(this._gradient);
2134+
}
21332135
} else {
21342136
const cgColors = [this.colors, this.stops].map((c) => (c instanceof Color ? c : new Color(c)).ios.CGColor);
21352137
this._gradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), cgColors as any, null);
2136-
CFRetain(this._gradient);
2138+
if (this._gradient) {
2139+
CFRetain(this._gradient);
2140+
}
21372141
}
21382142
}
21392143
return this._gradient;

0 commit comments

Comments
 (0)