Skip to content

Commit 96ae862

Browse files
committed
fix: Handle the case of giving a UIBezierPath parameter in _drawPath
1 parent 08360c5 commit 96ae862

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/ui-canvas/canvas.ios.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,13 @@ export class DashPathEffect extends PathEffect {
549549
export class Path implements IPath {
550550
private mPath: any;
551551
private mBPath?: UIBezierPath;
552-
mFillType: FillType;
552+
private mFillType: FillType;
553+
554+
constructor() {
555+
this.mPath = CGPathCreateMutable();
556+
this.mFillType = FillType.WINDING;
557+
// this._path = UIBezierPath.bezierPath();
558+
}
553559

554560
getOrCreateBPath() {
555561
if (!this.mBPath) {
@@ -577,11 +583,6 @@ export class Path implements IPath {
577583
this.mBPath = bPath;
578584
// this._path = this._bPath.CGPath;
579585
}
580-
constructor() {
581-
this.mPath = CGPathCreateMutable();
582-
this.mFillType = FillType.WINDING;
583-
// this._path = UIBezierPath.bezierPath();
584-
}
585586
computeBounds(rect: RectF, exact: boolean) {
586587
if (this.mBPath) {
587588
rect.cgRect = this.mBPath.bounds;
@@ -1920,17 +1921,23 @@ export class Canvas implements ICanvas {
19201921
CGContextClipToRect(ctx, rect);
19211922
return true;
19221923
}
1923-
private _drawPath(paint: Paint, ctx, path?) {
1924+
private _drawPath(paint: Paint, ctx, path?: Path | UIBezierPath) {
19241925
let bPath: UIBezierPath;
19251926
let cgPath;
1927+
let fillType: FillType;
1928+
19261929
if (path instanceof Path) {
19271930
bPath = path.getBPath();
19281931
cgPath = path.getCGPath();
1929-
} else if (path instanceof UIBezierPath) {
1930-
bPath = path;
1931-
cgPath = bPath.CGPath;
1932+
fillType = path.getFillType();
19321933
} else {
1933-
cgPath = path;
1934+
if (path instanceof UIBezierPath) {
1935+
bPath = path;
1936+
cgPath = bPath.CGPath;
1937+
} else {
1938+
cgPath = path;
1939+
}
1940+
fillType = FillType.WINDING;
19341941
}
19351942

19361943
const createBPath = () => {
@@ -1945,7 +1952,7 @@ export class Canvas implements ICanvas {
19451952
if (paint.shader && !cgPath) {
19461953
cgPath = CGContextCopyPath(ctx);
19471954
}
1948-
if (path && (path.getFillType() === FillType.INVERSE_WINDING || path.getFillType() === FillType.INVERSE_EVEN_ODD)) {
1955+
if (fillType === FillType.INVERSE_WINDING || fillType === FillType.INVERSE_EVEN_ODD) {
19491956
createBPath();
19501957
bPath = bPath.bezierPathByReversingPath();
19511958
cgPath = bPath.CGPath;
@@ -1991,15 +1998,15 @@ export class Canvas implements ICanvas {
19911998
}
19921999
if (paint.style === Style.FILL) {
19932000
// CGContextFillPath(ctx);
1994-
if (path && (path.getFillType() === FillType.EVEN_ODD || path.getFillType() === FillType.INVERSE_EVEN_ODD)) {
2001+
if (fillType === FillType.EVEN_ODD || fillType === FillType.INVERSE_EVEN_ODD) {
19952002
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathEOFill);
19962003
} else {
19972004
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathFill);
19982005
}
19992006
} else if (paint.style === Style.STROKE) {
20002007
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathStroke);
20012008
} else {
2002-
if (path && (path.getFillType() === FillType.EVEN_ODD || path.getFillType() === FillType.INVERSE_EVEN_ODD)) {
2009+
if (fillType === FillType.EVEN_ODD || fillType === FillType.INVERSE_EVEN_ODD) {
20032010
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathEOFillStroke);
20042011
} else {
20052012
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathFillStroke);

0 commit comments

Comments
 (0)