Skip to content

Commit 3807620

Browse files
committed
chore: code cleanup
1 parent efae572 commit 3807620

File tree

1 file changed

+3
-35
lines changed

1 file changed

+3
-35
lines changed

src/canvas.android.ts

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ export function parseDashEffect(value: string) {
7575
const array = value.split(' ').map(parseFloat);
7676
const length = array.length;
7777
const phase = array[length - 1];
78-
// const nNative = Array.create('float', length - 1);
79-
// for (let i = 0; i < length - 1; i++) {
80-
// nNative[i] = array[i];
81-
// }
8278
const result = new DashPathEffect(array, phase);
8379
return result;
8480
}
@@ -135,27 +131,19 @@ class Canvas {
135131
_bitmap: android.graphics.Bitmap;
136132
_shouldReleaseBitmap = false;
137133
constructor(imageOrWidth?: ImageSource | android.graphics.Bitmap | number, height?: number) {
138-
// if no args must be a canvas wrapper
139134
if (imageOrWidth) {
140135
if (imageOrWidth instanceof ImageSource) {
141136
this._bitmap = imageOrWidth.android;
142137
} else if (imageOrWidth instanceof android.graphics.Bitmap) {
143138
this._bitmap = imageOrWidth;
144139
} else {
145140
this._shouldReleaseBitmap = true;
146-
// console.log('create canvas with size', imageOrWidth, height);
147-
// const options = new android.graphics.BitmapFactory.Options();
148-
// options.inMutable = true;
149-
// (options as any).outConfig = android.graphics.Bitmap.Config.ARGB_8888;
150-
// console.log('create canvas with size about to create bitmap');
151141
this._bitmap = android.graphics.Bitmap.createBitmap(imageOrWidth, height, android.graphics.Bitmap.Config.ARGB_8888);
152-
// console.log('create canvas with size created bitmap', this._bitmap);
153142
}
154143
if (!this._bitmap.isMutable()) {
155144
this._shouldReleaseBitmap = true;
156145
this._bitmap = this._bitmap.copy(android.graphics.Bitmap.Config.ARGB_8888, true);
157146
}
158-
// this.setBitmap(this._bitmap);
159147
this._native = new android.graphics.Canvas(this._bitmap);
160148
}
161149

@@ -165,7 +153,6 @@ class Canvas {
165153
get(target: Canvas, name, receiver) {
166154
const native = this._native;
167155
if (canvasAugmentedMethods.indexOf(name) >= 0 || native[name]) {
168-
// assume methods live on the prototype
169156
return function (...args) {
170157
const methodName = name;
171158
for (let index = 0; index < args.length; index++) {
@@ -189,12 +176,10 @@ class Canvas {
189176
}
190177
} else if (methodName === 'getWidth' || methodName === 'getHeight') {
191178
if (!target._bitmap) {
192-
// return super.getWidth();
193179
return layout.toDeviceIndependentPixels(native[methodName]());
194180
}
195181
} else if (methodName === 'clear') {
196182
return native.drawColor(android.graphics.Color.TRANSPARENT);
197-
// return drawBitmapOnCanvas(native, args[0], args[1], args[2], args[3]);
198183
} else if (methodName === 'drawBitmap') {
199184
if (args[0] instanceof ImageSource) {
200185
args[0] = args[0].android;
@@ -203,10 +188,8 @@ class Canvas {
203188
return drawViewOnCanvas(native, args[0], args[1]);
204189
}
205190
return native[methodName](...args);
206-
// we now have access to both methodName and arguments
207191
};
208192
} else {
209-
// assume instance vars like on the target
210193
return Reflect.get(target, name, receiver);
211194
}
212195
}
@@ -230,23 +213,19 @@ export class Paint {
230213
_needsFontUpdate = true;
231214
getNative() {
232215
if (this._needsFontUpdate) {
233-
// const startTime = Date.now();
234216
this._needsFontUpdate = false;
235217
const font = this.font;
236218
const nTypeface = font.getAndroidTypeface();
237219
this._native.setTypeface(nTypeface);
238-
// console.log('[Paint]', 'setTypeface', font.fontFamily, nTypeface, Date.now() - startTime, 'ms');
239220
}
240221
return this._native;
241222
}
242223
constructor() {
243224
const native = (this._native = new android.graphics.Paint());
244225
native.setLinearText(true); // ensure we are drawing fonts correctly
245-
// native.setTypeface(this.font.getAndroidTypeface());
246226
return new Proxy(this, {
247227
get(target, name, receiver) {
248228
if (native[name]) {
249-
// assume methods live on the prototype
250229
return function (...args) {
251230
const methodName = name;
252231
for (let index = 0; index < args.length; index++) {
@@ -269,14 +248,11 @@ export class Paint {
269248
this.font['_typeface'] = args[0] as android.graphics.Typeface;
270249
}
271250
this._needsFontUpdate = true;
272-
// native.setTypeface(this.font.getAndroidTypeface());
273251
return this.fontInternal;
274252
}
275253
return native[methodName](...args);
276-
// we now have access to both methodName and arguments
277254
};
278255
} else {
279-
// assume instance vars like on the target
280256
return Reflect.get(target, name, receiver);
281257
}
282258
},
@@ -420,6 +396,9 @@ export class Path {
420396
}
421397
export class RadialGradient {
422398
_native: android.graphics.LinearGradient;
399+
getNative() {
400+
return this._native;
401+
}
423402
constructor(param0: number, param1: number, param2: number, param3: any, param4: any, param5: any) {
424403
this._native = new android.graphics.RadialGradient(param0, param1, param2, createColorParam(param3), param4 instanceof Array ? param4 : createColorParam(param4), param5);
425404
return new Proxy(this, this);
@@ -529,11 +508,6 @@ function initClasses() {
529508
PorterDuffXfermode = android.graphics.PorterDuffXfermode;
530509
}
531510

532-
// declare module '@nativescript/core/ui/core/view' {
533-
// interface View {
534-
// setOnLayoutChangeListener();
535-
// }
536-
// }
537511
@CSSType('CanvasView')
538512
class CanvasView extends CanvasBase {
539513
augmentedCanvas = new Canvas();
@@ -597,7 +571,6 @@ class CanvasView extends CanvasBase {
597571
startTime = Date.now();
598572
}
599573
const scale = this.density;
600-
// console.log('set canvas density', scale, Math.round(scale * 160), canvas.isHardwareAccelerated() );
601574
canvas.setDensity(Math.round(scale * 160));
602575
canvas.scale(scale, scale); // always scale to device density to work with dp
603576
this.augmentedCanvas._native = canvas;
@@ -629,11 +602,6 @@ class CanvasView extends CanvasBase {
629602
this.nativeViewProtected.invalidate();
630603
}
631604
}
632-
// public initNativeView() {
633-
// super.initNativeView();
634-
// // needed to update the cache canvas size on size change
635-
// this.setOnLayoutChangeListener();
636-
// }
637605
}
638606

639607
export function createImage(options: { width: number; height: number; scale?: number; config?: android.graphics.Bitmap.Config }) {

0 commit comments

Comments
 (0)