@@ -5,12 +5,8 @@ import { WebGLRenderingContext } from '../WebGL/WebGLRenderingContext';
5
5
import { WebGL2RenderingContext } from '../WebGL2/WebGL2RenderingContext' ;
6
6
import { Application , View , profile } from '@nativescript/core' ;
7
7
8
- declare var com ;
9
-
10
8
export function createSVGMatrix ( ) : DOMMatrix {
11
- return new DOMMatrix (
12
- com . github . triniwiz . canvas . CanvasView . createSVGMatrix ( )
13
- ) ;
9
+ return new DOMMatrix ( org . nativescript . canvas . TNSCanvas . createSVGMatrix ( ) ) ;
14
10
}
15
11
16
12
export * from './common' ;
@@ -30,9 +26,8 @@ export class Canvas extends CanvasBase {
30
26
useCpu = arguments [ 0 ] ;
31
27
}
32
28
}
33
- const activity =
34
- Application . android . foregroundActivity || Application . android . startActivity ;
35
- this . _canvas = new com . github . triniwiz . canvas . TNSCanvas ( activity , useCpu ) ;
29
+ const activity = Application . android . foregroundActivity || Application . android . startActivity ;
30
+ this . _canvas = new org . nativescript . canvas . TNSCanvas ( activity , useCpu ) ;
36
31
( global as any ) . __canvasLoaded = true ;
37
32
}
38
33
@@ -52,7 +47,7 @@ export class Canvas extends CanvasBase {
52
47
// @ts -ignore
53
48
get width ( ) {
54
49
if ( this . getMeasuredWidth ( ) > 0 ) {
55
- return this . getMeasuredWidth ( )
50
+ return this . getMeasuredWidth ( ) ;
56
51
}
57
52
const width = this . _canvas . getWidth ( ) ;
58
53
if ( width === 0 ) {
@@ -109,24 +104,24 @@ export class Canvas extends CanvasBase {
109
104
super . initNativeView ( ) ;
110
105
const ref = new WeakRef ( this ) ;
111
106
this . __handleGestures ( ) ;
112
- this . on ( View . layoutChangedEvent , args => {
107
+ this . on ( View . layoutChangedEvent , ( args ) => {
113
108
const parent = this . parent as any ;
114
109
// TODO change DIPs once implemented
115
110
if ( parent && parent . clientWidth === undefined && parent . clientHeight === undefined ) {
116
111
Object . defineProperty ( parent , 'clientWidth' , {
117
112
get : function ( ) {
118
113
return parent . getMeasuredWidth ( ) ;
119
- }
114
+ } ,
120
115
} ) ;
121
116
Object . defineProperty ( parent , 'clientHeight' , {
122
117
get : function ( ) {
123
118
return parent . getMeasuredHeight ( ) ;
124
- }
119
+ } ,
125
120
} ) ;
126
121
}
127
122
} ) ;
128
123
this . _canvas . setListener (
129
- new com . github . triniwiz . canvas . TNSCanvas . Listener ( {
124
+ new org . nativescript . canvas . TNSCanvas . Listener ( {
130
125
contextReady ( ) {
131
126
const owner = ref . get ( ) as any ;
132
127
if ( owner && ! owner . _ready ) {
@@ -180,10 +175,7 @@ export class Canvas extends CanvasBase {
180
175
181
176
_layoutNative ( ) {
182
177
if ( ! this . parent ) {
183
- if (
184
- ( typeof this . width === 'string' && this . width . indexOf ( '%' ) ) ||
185
- ( typeof this . height === 'string' && this . height . indexOf ( '%' ) )
186
- ) {
178
+ if ( ( typeof this . width === 'string' && this . width . indexOf ( '%' ) ) || ( typeof this . height === 'string' && this . height . indexOf ( '%' ) ) ) {
187
179
return ;
188
180
}
189
181
if ( ! this . _isCustom ) {
@@ -193,11 +185,7 @@ export class Canvas extends CanvasBase {
193
185
const size = this . _realSize ;
194
186
let rootParams = this . _canvas . getLayoutParams ( ) ;
195
187
196
- if (
197
- rootParams &&
198
- ( size . width || 0 ) === rootParams . width &&
199
- ( size . height || 0 ) === rootParams . height
200
- ) {
188
+ if ( rootParams && ( size . width || 0 ) === rootParams . width && ( size . height || 0 ) === rootParams . height ) {
201
189
return ;
202
190
}
203
191
@@ -207,7 +195,7 @@ export class Canvas extends CanvasBase {
207
195
}
208
196
rootParams . width = size . width ;
209
197
rootParams . height = size . height ;
210
- let surfaceParams // = this._canvas.getSurface().getLayoutParams();
198
+ let surfaceParams ; // = this._canvas.getSurface().getLayoutParams();
211
199
if ( ! surfaceParams ) {
212
200
surfaceParams = new android . widget . FrameLayout . LayoutParams ( 0 , 0 ) ;
213
201
}
@@ -217,28 +205,15 @@ export class Canvas extends CanvasBase {
217
205
this . _canvas . setLayoutParams ( rootParams ) ;
218
206
//this._canvas.getSurface().setLayoutParams(surfaceParams);
219
207
220
- const w = android . view . View . MeasureSpec . makeMeasureSpec (
221
- size . width ,
222
- android . view . View . MeasureSpec . EXACTLY
223
- ) ;
224
- const h = android . view . View . MeasureSpec . makeMeasureSpec (
225
- size . height ,
226
- android . view . View . MeasureSpec . EXACTLY
227
- ) ;
208
+ const w = android . view . View . MeasureSpec . makeMeasureSpec ( size . width , android . view . View . MeasureSpec . EXACTLY ) ;
209
+ const h = android . view . View . MeasureSpec . makeMeasureSpec ( size . height , android . view . View . MeasureSpec . EXACTLY ) ;
228
210
this . _canvas . measure ( w , h ) ;
229
211
this . _canvas . layout ( 0 , 0 , size . width || 0 , size . height || 0 ) ;
230
212
}
231
213
}
232
214
}
233
215
234
- getContext (
235
- type : string ,
236
- options ?: any
237
- ) :
238
- | CanvasRenderingContext2D
239
- | WebGLRenderingContext
240
- | WebGL2RenderingContext
241
- | null {
216
+ getContext ( type : string , options ?: any ) : CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext | null {
242
217
if ( ! this . _canvas ) {
243
218
return null ;
244
219
}
@@ -247,7 +222,7 @@ export class Canvas extends CanvasBase {
247
222
const opts = new java . util . HashMap ( ) ;
248
223
Object . keys ( jsOptions ) . forEach ( ( key ) => {
249
224
let val = jsOptions [ key ] ;
250
- if ( typeof val === " boolean" ) {
225
+ if ( typeof val === ' boolean' ) {
251
226
opts . put ( key , java . lang . Boolean . valueOf ( String ( val ) ) ) ;
252
227
} else {
253
228
opts . put ( key , val ) ;
@@ -262,9 +237,7 @@ export class Canvas extends CanvasBase {
262
237
return null ;
263
238
}
264
239
if ( ! this . _2dContext ) {
265
- this . _2dContext = new CanvasRenderingContext2D (
266
- this . _canvas . getContext ( type , getNativeOptions ( options ) )
267
- ) ;
240
+ this . _2dContext = new CanvasRenderingContext2D ( this . _canvas . getContext ( type , getNativeOptions ( options ) ) ) ;
268
241
// @ts -ignore
269
242
this . _2dContext . _canvas = this ;
270
243
} else {
@@ -278,26 +251,19 @@ export class Canvas extends CanvasBase {
278
251
return null ;
279
252
}
280
253
if ( ! this . _webglContext ) {
281
- this . _webglContext = new WebGLRenderingContext (
282
- this . _canvas . getContext ( 'webgl' , getNativeOptions ( options ) )
283
- ) ;
254
+ this . _webglContext = new WebGLRenderingContext ( this . _canvas . getContext ( 'webgl' , getNativeOptions ( options ) ) ) ;
284
255
this . _webglContext . _canvas = this ;
285
256
} else {
286
257
this . _canvas . getContext ( 'webgl' , getNativeOptions ( options ) ) ;
287
258
}
288
259
this . _webglContext . _type = 'webgl' ;
289
260
return this . _webglContext ;
290
- } else if (
291
- type &&
292
- ( type === 'webgl2' || type === 'experimental-webgl2' )
293
- ) {
261
+ } else if ( type && ( type === 'webgl2' || type === 'experimental-webgl2' ) ) {
294
262
if ( this . _2dContext || this . _webglContext ) {
295
263
return null ;
296
264
}
297
265
if ( ! this . _webgl2Context ) {
298
- this . _webgl2Context = new WebGL2RenderingContext (
299
- this . android . getContext ( 'webgl2' , getNativeOptions ( options ) )
300
- ) ;
266
+ this . _webgl2Context = new WebGL2RenderingContext ( this . android . getContext ( 'webgl2' , getNativeOptions ( options ) ) ) ;
301
267
( this . _webgl2Context as any ) . _canvas = this ;
302
268
} else {
303
269
this . android . getContext ( 'webgl2' , getNativeOptions ( options ) ) ;
0 commit comments