Skip to content

Commit 902de0d

Browse files
committed
chore: rename class members to allow mangling
1 parent 1272d62 commit 902de0d

File tree

5 files changed

+72
-121
lines changed

5 files changed

+72
-121
lines changed

src/canvas.android.ts

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ function drawViewOnCanvas(canvas: android.graphics.Canvas, view: View, rect?: an
121121
}
122122

123123
class ProxyClass<T> {
124-
_native: T;
124+
mNative: T;
125125
static augmentedMethods = [];
126126
getNative() {
127-
return this._native;
127+
return this.mNative;
128128
}
129129
constructor() {
130130
const proxy = new Proxy(this, this);
@@ -138,7 +138,7 @@ class ProxyClass<T> {
138138
const methodName = name;
139139
for (let index = 0; index < args.length; index++) {
140140
const element = args[index];
141-
if (element && element._native) {
141+
if (element && element.mNative) {
142142
args[index] = element.getNative();
143143
} else if (Array.isArray(element)) {
144144
args[index] = arrayToNativeArray(element);
@@ -175,7 +175,7 @@ class Canvas extends ProxyClass<android.graphics.Canvas> {
175175
this._shouldReleaseBitmap = true;
176176
this._bitmap = this._bitmap.copy(android.graphics.Bitmap.Config.ARGB_8888, true);
177177
}
178-
this._native = new android.graphics.Canvas(this._bitmap);
178+
this.mNative = new android.graphics.Canvas(this._bitmap);
179179
}
180180

181181
return this;
@@ -222,23 +222,23 @@ class Canvas extends ProxyClass<android.graphics.Canvas> {
222222
}
223223

224224
export class Paint extends ProxyClass<android.graphics.Paint> {
225-
_native: android.graphics.Paint;
226-
fontInternal: Font;
227-
_needsFontUpdate = false;
225+
mNative: android.graphics.Paint;
226+
mFontInternal: Font;
227+
mNeedsFontUpdate = false;
228228
handlesFont = false;
229229
getNative() {
230-
if (!this.handlesFont && this._needsFontUpdate) {
231-
this._needsFontUpdate = false;
230+
if (!this.handlesFont && this.mNeedsFontUpdate) {
231+
this.mNeedsFontUpdate = false;
232232
const font = this.font;
233233
const nTypeface = font.getAndroidTypeface();
234-
this._native.setTypeface(nTypeface);
234+
this.mNative.setTypeface(nTypeface);
235235
}
236-
return this._native;
236+
return this.mNative;
237237
}
238238
constructor() {
239239
super();
240-
this._native = new android.graphics.Paint();
241-
this._native.setLinearText(true); // ensure we are drawing fonts correctly
240+
this.mNative = new android.graphics.Paint();
241+
this.mNative.setLinearText(true); // ensure we are drawing fonts correctly
242242
return this;
243243
}
244244
handleCustomMethods(target, native, methodName: string, args: any[]): any {
@@ -251,27 +251,27 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
251251
args[0] = createColorParam(args[0]);
252252
} else if (methodName === 'setTypeface') {
253253
if (args[0] instanceof Font) {
254-
this.fontInternal = args[0];
254+
this.mFontInternal = args[0];
255255
} else {
256256
this.font['_typeface'] = args[0] as android.graphics.Typeface;
257257
}
258-
this._needsFontUpdate = true;
259-
return this.fontInternal;
258+
this.mNeedsFontUpdate = true;
259+
return this.mFontInternal;
260260
}
261261
}
262262
setFont(font: Font) {
263-
this.fontInternal = font;
263+
this.mFontInternal = font;
264264
if (this.handlesFont) {
265265
return;
266266
}
267-
this._native.setTextSize(font.fontSize);
268-
this._needsFontUpdate = true;
267+
this.mNative.setTextSize(font.fontSize);
268+
this.mNeedsFontUpdate = true;
269269
}
270270
getFont() {
271-
if (!this.fontInternal) {
272-
this.fontInternal = Font.default;
271+
if (!this.mFontInternal) {
272+
this.mFontInternal = Font.default;
273273
}
274-
return this.fontInternal;
274+
return this.mFontInternal;
275275
}
276276
get font() {
277277
return this.getFont();
@@ -290,9 +290,9 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
290290
}
291291
setFontFamily(familyName: string) {
292292
if (this.font.fontFamily !== familyName) {
293-
this.fontInternal = this.font.withFontFamily(familyName);
293+
this.mFontInternal = this.font.withFontFamily(familyName);
294294
if (!this.handlesFont) {
295-
this._needsFontUpdate = true;
295+
this.mNeedsFontUpdate = true;
296296
}
297297
}
298298
}
@@ -301,9 +301,9 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
301301
}
302302
setFontWeight(weight: FontWeight) {
303303
if (this.font.fontWeight !== weight) {
304-
this.fontInternal = this.font.withFontWeight(weight);
304+
this.mFontInternal = this.font.withFontWeight(weight);
305305
if (!this.handlesFont) {
306-
this._needsFontUpdate = true;
306+
this.mNeedsFontUpdate = true;
307307
}
308308
}
309309
}
@@ -312,49 +312,49 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
312312
}
313313
setFontStyle(style: FontStyle) {
314314
if (this.font.fontStyle !== style) {
315-
this.fontInternal = this.font.withFontStyle(style);
315+
this.mFontInternal = this.font.withFontStyle(style);
316316
if (!this.handlesFont) {
317-
this._needsFontUpdate = true;
317+
this.mNeedsFontUpdate = true;
318318
}
319319
}
320320
}
321321
set color(color) {
322322
(this as any).setColor(color);
323323
}
324324
set strokeWidth(value: number) {
325-
this._native.setStrokeWidth(value);
325+
this.mNative.setStrokeWidth(value);
326326
}
327327
set strokeCap(value: number) {
328-
this._native.setStrokeCap(value);
328+
this.mNative.setStrokeCap(value);
329329
}
330330
set strokeJoin(value: number) {
331-
this._native.setStrokeJoin(value);
331+
this.mNative.setStrokeJoin(value);
332332
}
333333
set style(value: number) {
334-
this._native.setStyle(value);
334+
this.mNative.setStyle(value);
335335
}
336336
set textSize(value: number) {
337-
this._native.setTextSize(value);
337+
this.mNative.setTextSize(value);
338338
}
339339
get textSize() {
340340
return this.getTextSize();
341341
}
342342
public getTextSize(): number {
343-
return this._native.getTextSize();
343+
return this.mNative.getTextSize();
344344
}
345345
public setTypeface(font: Font | android.graphics.Typeface): Font {
346346
if (font instanceof Font) {
347347
this.setFont(font);
348-
return this.fontInternal;
348+
return this.mFontInternal;
349349
} else if (font) {
350-
this.fontInternal['_typeface'] = font;
350+
this.mFontInternal['_typeface'] = font;
351351
} else {
352-
this.fontInternal = null;
352+
this.mFontInternal = null;
353353
}
354354
if (!this.handlesFont) {
355-
this._needsFontUpdate = true;
355+
this.mNeedsFontUpdate = true;
356356
}
357-
return this.fontInternal;
357+
return this.mFontInternal;
358358
}
359359
set typeface(typeface) {
360360
this.setTypeface(typeface);
@@ -364,30 +364,30 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
364364
export class DashPathEffect extends ProxyClass<android.graphics.DashPathEffect> {
365365
constructor(intervals: number[], phase: number) {
366366
super();
367-
this._native = new android.graphics.DashPathEffect(arrayToNativeArray(intervals), phase);
367+
this.mNative = new android.graphics.DashPathEffect(arrayToNativeArray(intervals), phase);
368368
return this;
369369
}
370370
}
371371

372372
export class Path extends ProxyClass<com.akylas.canvas.CanvasPath> {
373373
constructor(path?: com.akylas.canvas.CanvasPath) {
374374
super();
375-
this._native = path ? new com.akylas.canvas.CanvasPath(path) : new com.akylas.canvas.CanvasPath();
375+
this.mNative = path ? new com.akylas.canvas.CanvasPath(path) : new com.akylas.canvas.CanvasPath();
376376
return this;
377377
}
378378
}
379379
export class RadialGradient extends ProxyClass<android.graphics.RadialGradient> {
380380
constructor(param0: number, param1: number, param2: number, param3: any, param4: any, param5: any) {
381381
super();
382-
this._native = new android.graphics.RadialGradient(param0, param1, param2, createColorParam(param3), param4 instanceof Array ? param4 : createColorParam(param4), param5);
382+
this.mNative = new android.graphics.RadialGradient(param0, param1, param2, createColorParam(param3), param4 instanceof Array ? param4 : createColorParam(param4), param5);
383383
return this;
384384
}
385385
}
386386

387387
export class LinearGradient extends ProxyClass<android.graphics.LinearGradient> {
388-
_native: android.graphics.LinearGradient;
388+
mNative: android.graphics.LinearGradient;
389389
getNative() {
390-
return this._native;
390+
return this.mNative;
391391
}
392392
constructor(param0: number, param1: number, param2: number, param3: any, param4: any, param5: any, param6: any) {
393393
super();
@@ -409,19 +409,19 @@ export class LinearGradient extends ProxyClass<android.graphics.LinearGradient>
409409
param5 = createColorParam(param5);
410410
}
411411
}
412-
this._native = new android.graphics.LinearGradient(param0, param1, param2, param3, param4, param5, param6);
412+
this.mNative = new android.graphics.LinearGradient(param0, param1, param2, param3, param4, param5, param6);
413413
return this;
414414
}
415415
}
416416

417417
export class BitmapShader extends ProxyClass<android.graphics.BitmapShader> {
418-
_native: android.graphics.BitmapShader;
418+
mNative: android.graphics.BitmapShader;
419419
constructor(bitmap: any, tileX: any, tileY: any) {
420420
super();
421421
if (bitmap instanceof ImageSource) {
422422
bitmap = bitmap.android;
423423
}
424-
this._native = new android.graphics.BitmapShader(bitmap, tileX, tileY);
424+
this.mNative = new android.graphics.BitmapShader(bitmap, tileX, tileY);
425425
return this;
426426
}
427427
}
@@ -435,7 +435,7 @@ export class StaticLayout extends ProxyClass<android.text.StaticLayout> {
435435
// in case it is a number or a boolean
436436
text = text + '';
437437
}
438-
this._native = com.akylas.canvas.StaticLayout.createStaticLayout(text, paint, width, align, spacingmult, spacingadd, includepad);
438+
this.mNative = com.akylas.canvas.StaticLayout.createStaticLayout(text, paint, width, align, spacingmult, spacingadd, includepad);
439439

440440
return this;
441441
}
@@ -478,7 +478,7 @@ class CanvasView extends CanvasBase {
478478
}
479479
canvas.drawBitmap(shapeCanvas.getImage() as android.graphics.Bitmap, 0, 0, this.shapePaint);
480480
} else if (!this.cached) {
481-
const shapes = this._shapes;
481+
const shapes = this.mShapes;
482482
const width = canvas.getWidth();
483483
const height = canvas.getHeight();
484484
if (shapes && shapes.length > 0) {
@@ -524,7 +524,7 @@ class CanvasView extends CanvasBase {
524524
canvas.save();
525525
// canvas.setDensity(Math.round(scale * 160));
526526
canvas.scale(scale, scale); // always scale to device density to work with dp
527-
this.augmentedCanvas._native = canvas;
527+
this.augmentedCanvas.mNative = canvas;
528528
this.onDraw(this.augmentedCanvas as any);
529529
if (drawFameRate) {
530530
const end = Date.now();

src/canvas.common.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ export abstract class CanvasBase extends View {
4141
// Declare events as static variables, so that they can be set in NativeScript Core XML
4242
public static drawEvent = 'draw';
4343

44-
protected _shapes: ObservableArray<Shape>;
44+
protected mShapes: ObservableArray<Shape>;
4545

4646
callDrawBeforeShapes = false;
4747

4848
get shapes() {
49-
return this._shapes;
49+
return this.mShapes;
5050
}
5151
public cached;
5252
public density;
@@ -55,11 +55,11 @@ export abstract class CanvasBase extends View {
5555
drawFameRate = false;
5656

5757
getOrCreateShapes() {
58-
if (!this._shapes) {
59-
this._shapes = new ObservableArray<Shape>();
60-
this._shapes.addEventListener(ObservableArray.changeEvent, this.onShapesCollectionChanged, this);
58+
if (!this.mShapes) {
59+
this.mShapes = new ObservableArray<Shape>();
60+
this.mShapes.addEventListener(ObservableArray.changeEvent, this.onShapesCollectionChanged, this);
6161
}
62-
return this._shapes;
62+
return this.mShapes;
6363
}
6464

6565
requestDrawShapes() {
@@ -96,10 +96,10 @@ export abstract class CanvasBase extends View {
9696
}
9797

9898
public removeShape(shape: Shape) {
99-
if (this._shapes) {
100-
const index = this._shapes.indexOf(shape);
99+
if (this.mShapes) {
100+
const index = this.mShapes.indexOf(shape);
101101
if (index !== -1) {
102-
this._shapes.splice(index, 1);
102+
this.mShapes.splice(index, 1);
103103
}
104104
}
105105
}
@@ -129,7 +129,7 @@ export abstract class CanvasBase extends View {
129129
const shape = (eventData.object as ObservableArray<any>).getItem(eventData.index + i);
130130
// Then attach handlers - we skip the first nofitication because
131131
// we raise change for the whole instance.
132-
shape._parent = new WeakRef(this as any);
132+
shape.mParent = new WeakRef(this as any);
133133
this.addPropertyChangeHandler(shape);
134134
}
135135
}
@@ -140,13 +140,13 @@ export abstract class CanvasBase extends View {
140140
// First remove handlers so that we don't listen for changes
141141
// on inherited properties.
142142
this.removePropertyChangeHandler(shape);
143-
shape._parent = null;
143+
shape.mParent = null;
144144
this.redraw();
145145
}
146146
}
147147
}
148148
public onSizeChanged(w: number, h: number, oldw: number, oldh: number) {
149-
if (!!this._shapes && this._shapes.length > 0) {
149+
if (!!this.mShapes && this.mShapes.length > 0) {
150150
this.requestDrawShapes();
151151
}
152152
}
@@ -162,13 +162,13 @@ export abstract class CanvasBase extends View {
162162
}
163163

164164
[colorProperty.setNative](value) {
165-
if (!!this._shapes) {
165+
if (!!this.mShapes) {
166166
this.requestDrawShapes();
167167
}
168168
}
169169

170170
[densityProperty.setNative](value) {
171-
if (!!this._shapes) {
171+
if (!!this.mShapes) {
172172
this.requestDrawShapes();
173173
}
174174
}
@@ -180,10 +180,10 @@ export abstract class CanvasBase extends View {
180180
// this.shapesCanvas.release();
181181
this.shapesCanvas = null;
182182
}
183-
if (this._shapes && this._shapes.length > 0 && width > 0 && height > 0) {
183+
if (this.mShapes && this.mShapes.length > 0 && width > 0 && height > 0) {
184184
const canvas = (this.shapesCanvas = new Canvas(width, height));
185185
canvas.setDensity(this.density);
186-
this._shapes.forEach((s) => s.drawMyShapeOnCanvas(canvas, this as any, width, height));
186+
this.mShapes.forEach((s) => s.drawMyShapeOnCanvas(canvas, this as any, width, height));
187187
this.redraw();
188188
}
189189
}

0 commit comments

Comments
 (0)