@@ -75,10 +75,6 @@ export function parseDashEffect(value: string) {
75
75
const array = value . split ( ' ' ) . map ( parseFloat ) ;
76
76
const length = array . length ;
77
77
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
- // }
82
78
const result = new DashPathEffect ( array , phase ) ;
83
79
return result ;
84
80
}
@@ -135,27 +131,19 @@ class Canvas {
135
131
_bitmap : android . graphics . Bitmap ;
136
132
_shouldReleaseBitmap = false ;
137
133
constructor ( imageOrWidth ?: ImageSource | android . graphics . Bitmap | number , height ?: number ) {
138
- // if no args must be a canvas wrapper
139
134
if ( imageOrWidth ) {
140
135
if ( imageOrWidth instanceof ImageSource ) {
141
136
this . _bitmap = imageOrWidth . android ;
142
137
} else if ( imageOrWidth instanceof android . graphics . Bitmap ) {
143
138
this . _bitmap = imageOrWidth ;
144
139
} else {
145
140
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');
151
141
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);
153
142
}
154
143
if ( ! this . _bitmap . isMutable ( ) ) {
155
144
this . _shouldReleaseBitmap = true ;
156
145
this . _bitmap = this . _bitmap . copy ( android . graphics . Bitmap . Config . ARGB_8888 , true ) ;
157
146
}
158
- // this.setBitmap(this._bitmap);
159
147
this . _native = new android . graphics . Canvas ( this . _bitmap ) ;
160
148
}
161
149
@@ -165,7 +153,6 @@ class Canvas {
165
153
get ( target : Canvas , name , receiver ) {
166
154
const native = this . _native ;
167
155
if ( canvasAugmentedMethods . indexOf ( name ) >= 0 || native [ name ] ) {
168
- // assume methods live on the prototype
169
156
return function ( ...args ) {
170
157
const methodName = name ;
171
158
for ( let index = 0 ; index < args . length ; index ++ ) {
@@ -189,12 +176,10 @@ class Canvas {
189
176
}
190
177
} else if ( methodName === 'getWidth' || methodName === 'getHeight' ) {
191
178
if ( ! target . _bitmap ) {
192
- // return super.getWidth();
193
179
return layout . toDeviceIndependentPixels ( native [ methodName ] ( ) ) ;
194
180
}
195
181
} else if ( methodName === 'clear' ) {
196
182
return native . drawColor ( android . graphics . Color . TRANSPARENT ) ;
197
- // return drawBitmapOnCanvas(native, args[0], args[1], args[2], args[3]);
198
183
} else if ( methodName === 'drawBitmap' ) {
199
184
if ( args [ 0 ] instanceof ImageSource ) {
200
185
args [ 0 ] = args [ 0 ] . android ;
@@ -203,10 +188,8 @@ class Canvas {
203
188
return drawViewOnCanvas ( native , args [ 0 ] , args [ 1 ] ) ;
204
189
}
205
190
return native [ methodName ] ( ...args ) ;
206
- // we now have access to both methodName and arguments
207
191
} ;
208
192
} else {
209
- // assume instance vars like on the target
210
193
return Reflect . get ( target , name , receiver ) ;
211
194
}
212
195
}
@@ -230,23 +213,19 @@ export class Paint {
230
213
_needsFontUpdate = true ;
231
214
getNative ( ) {
232
215
if ( this . _needsFontUpdate ) {
233
- // const startTime = Date.now();
234
216
this . _needsFontUpdate = false ;
235
217
const font = this . font ;
236
218
const nTypeface = font . getAndroidTypeface ( ) ;
237
219
this . _native . setTypeface ( nTypeface ) ;
238
- // console.log('[Paint]', 'setTypeface', font.fontFamily, nTypeface, Date.now() - startTime, 'ms');
239
220
}
240
221
return this . _native ;
241
222
}
242
223
constructor ( ) {
243
224
const native = ( this . _native = new android . graphics . Paint ( ) ) ;
244
225
native . setLinearText ( true ) ; // ensure we are drawing fonts correctly
245
- // native.setTypeface(this.font.getAndroidTypeface());
246
226
return new Proxy ( this , {
247
227
get ( target , name , receiver ) {
248
228
if ( native [ name ] ) {
249
- // assume methods live on the prototype
250
229
return function ( ...args ) {
251
230
const methodName = name ;
252
231
for ( let index = 0 ; index < args . length ; index ++ ) {
@@ -269,14 +248,11 @@ export class Paint {
269
248
this . font [ '_typeface' ] = args [ 0 ] as android . graphics . Typeface ;
270
249
}
271
250
this . _needsFontUpdate = true ;
272
- // native.setTypeface(this.font.getAndroidTypeface());
273
251
return this . fontInternal ;
274
252
}
275
253
return native [ methodName ] ( ...args ) ;
276
- // we now have access to both methodName and arguments
277
254
} ;
278
255
} else {
279
- // assume instance vars like on the target
280
256
return Reflect . get ( target , name , receiver ) ;
281
257
}
282
258
} ,
@@ -420,6 +396,9 @@ export class Path {
420
396
}
421
397
export class RadialGradient {
422
398
_native : android . graphics . LinearGradient ;
399
+ getNative ( ) {
400
+ return this . _native ;
401
+ }
423
402
constructor ( param0 : number , param1 : number , param2 : number , param3 : any , param4 : any , param5 : any ) {
424
403
this . _native = new android . graphics . RadialGradient ( param0 , param1 , param2 , createColorParam ( param3 ) , param4 instanceof Array ? param4 : createColorParam ( param4 ) , param5 ) ;
425
404
return new Proxy ( this , this ) ;
@@ -529,11 +508,6 @@ function initClasses() {
529
508
PorterDuffXfermode = android . graphics . PorterDuffXfermode ;
530
509
}
531
510
532
- // declare module '@nativescript/core/ui/core/view' {
533
- // interface View {
534
- // setOnLayoutChangeListener();
535
- // }
536
- // }
537
511
@CSSType ( 'CanvasView' )
538
512
class CanvasView extends CanvasBase {
539
513
augmentedCanvas = new Canvas ( ) ;
@@ -597,7 +571,6 @@ class CanvasView extends CanvasBase {
597
571
startTime = Date . now ( ) ;
598
572
}
599
573
const scale = this . density ;
600
- // console.log('set canvas density', scale, Math.round(scale * 160), canvas.isHardwareAccelerated() );
601
574
canvas . setDensity ( Math . round ( scale * 160 ) ) ;
602
575
canvas . scale ( scale , scale ) ; // always scale to device density to work with dp
603
576
this . augmentedCanvas . _native = canvas ;
@@ -629,11 +602,6 @@ class CanvasView extends CanvasBase {
629
602
this . nativeViewProtected . invalidate ( ) ;
630
603
}
631
604
}
632
- // public initNativeView() {
633
- // super.initNativeView();
634
- // // needed to update the cache canvas size on size change
635
- // this.setOnLayoutChangeListener();
636
- // }
637
605
}
638
606
639
607
export function createImage ( options : { width : number ; height : number ; scale ?: number ; config ?: android . graphics . Bitmap . Config } ) {
0 commit comments