Skip to content

Commit

Permalink
Merge pull request #62 from nativescript-community/fix-ios-set-matrix
Browse files Browse the repository at this point in the history
fix(ui-canvas): Proper iOS scale for bitmap cases
  • Loading branch information
farfromrefug authored Aug 1, 2024
2 parents ad59928 + b0affa0 commit d8c7e98
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/ui-canvas/canvas.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1361,8 +1361,26 @@ export class Canvas implements ICanvas {
mWidth: number;
mHeight: number;
mScale = 1;
mIsBitmap = false;
view: WeakRef<CanvasView>;

constructor(imageOrWidth: ImageSource | UIImage | number, height?: number) {
let isBitmap = true;

if (imageOrWidth instanceof ImageSource) {
this.mCgContext = this._createContextFromImage(imageOrWidth.ios);
} else if (imageOrWidth instanceof UIImage) {
this.mCgContext = this._createContextFromImage(imageOrWidth);
} else if (imageOrWidth > 0 && height > 0) {
this.mCgContext = this._createContext(imageOrWidth, height);
} else {
isBitmap = false;
}

this.mIsBitmap = isBitmap;
// CGContextFillRect(this._cgContext);
}

setBitmap(image) {
// if (image instanceof ImageSource) {
// this._bitmap = image.android;
Expand Down Expand Up @@ -1454,7 +1472,7 @@ export class Canvas implements ICanvas {
setMatrix(matrix: Matrix): void {
// TODO: Find a better way to implement matrix set
const ctx = this.ctx;
const density = Screen.mainScreen.scale;
const density = this.mIsBitmap ? 1 : Screen.mainScreen.scale;
const currentMatrix = this.getMatrix();
const invertedTransform = CGAffineTransformInvert(currentMatrix.mTransform);
const scaleTransform = CGAffineTransformMake(density, 0, 0, -density, 0, density * this.mHeight);
Expand Down Expand Up @@ -1765,16 +1783,6 @@ export class Canvas implements ICanvas {
getHeight() {
return this.mHeight;
}
constructor(imageOrWidth: ImageSource | UIImage | number, height?: number) {
if (imageOrWidth instanceof ImageSource) {
this.mCgContext = this._createContextFromImage(imageOrWidth.ios);
} else if (imageOrWidth instanceof UIImage) {
this.mCgContext = this._createContextFromImage(imageOrWidth);
} else if (imageOrWidth > 0 && height > 0) {
this.mCgContext = this._createContext(imageOrWidth, height);
}
// CGContextFillRect(this._cgContext);
}

startApplyPaint(paint?: Paint, withFont = false) {
this.save();
Expand Down

0 comments on commit d8c7e98

Please sign in to comment.