1
- import { CSSType , PercentLength , View , Screen , GestureStateTypes , Utils , Application } from '@nativescript/core' ;
2
- import { CanvasRenderingContext , TouchList } from '../common' ;
1
+ import { CSSType , PercentLength , View , Screen , GestureStateTypes , Utils , Application } from '@nativescript/core' ;
2
+ import { CanvasRenderingContext , TouchList } from '../common' ;
3
3
4
4
export interface ICanvasBase {
5
5
on ( eventName : 'ready' , callback : ( data : any ) => void , thisArg ?: any ) : void ;
@@ -37,36 +37,36 @@ export abstract class CanvasBase extends View implements ICanvasBase {
37
37
antialias : true ,
38
38
depth : true ,
39
39
failIfMajorPerformanceCaveat : false ,
40
- powerPreference : " default" ,
40
+ powerPreference : ' default' ,
41
41
premultipliedAlpha : true ,
42
42
preserveDrawingBuffer : false ,
43
43
stencil : false ,
44
44
desynchronized : false ,
45
- xrCompatible : false
45
+ xrCompatible : false ,
46
46
} ;
47
47
if ( ! contextOpts ) {
48
48
if ( type === '2d' ) {
49
49
return {
50
- alpha : true
51
- }
50
+ alpha : true ,
51
+ } ;
52
52
}
53
53
if ( type . indexOf ( 'webgl' ) > - 1 ) {
54
54
return defaultGLOptions ;
55
55
}
56
56
}
57
57
if ( type === '2d' ) {
58
- if ( contextOpts . alpha !== undefined && typeof contextOpts . alpha === " boolean" ) {
58
+ if ( contextOpts . alpha !== undefined && typeof contextOpts . alpha === ' boolean' ) {
59
59
return contextOpts ;
60
60
} else {
61
- return { alpha : true }
61
+ return { alpha : true } ;
62
62
}
63
63
}
64
64
const setIfDefined = ( prop , value ) => {
65
65
const property = defaultGLOptions [ prop ] ;
66
66
if ( property !== undefined && typeof value === typeof property ) {
67
67
defaultGLOptions [ prop ] = value ;
68
68
}
69
- }
69
+ } ;
70
70
if ( type . indexOf ( 'webgl' ) > - 1 ) {
71
71
setIfDefined ( 'alpha' , contextOpts . alpha ) ;
72
72
setIfDefined ( 'antialias' , contextOpts . antialias ) ;
@@ -101,10 +101,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
101
101
break ;
102
102
}
103
103
} else if ( event . eventName === 'pan' ) {
104
- if (
105
- event . state === GestureStateTypes . began ||
106
- event . state === GestureStateTypes . changed
107
- ) {
104
+ if ( event . state === GestureStateTypes . began || event . state === GestureStateTypes . changed ) {
108
105
this . _emitEvent ( 'touchmove' , event ) ;
109
106
}
110
107
}
@@ -197,10 +194,8 @@ export abstract class CanvasBase extends View implements ICanvasBase {
197
194
shiftKey : false ,
198
195
targetTouches : pointers ,
199
196
touches : pointers ,
200
- preventDefault : ( ) => {
201
- } ,
202
- stopPropagation : ( ) => {
203
- } ,
197
+ preventDefault : ( ) => { } ,
198
+ stopPropagation : ( ) => { } ,
204
199
target,
205
200
...activePointer ,
206
201
} ;
@@ -224,13 +219,30 @@ export abstract class CanvasBase extends View implements ICanvasBase {
224
219
if ( attrib === 'height' ) {
225
220
return this . height ;
226
221
}
222
+
223
+ if ( attrib === 'tabindex' ) {
224
+ return ( this [ 'tabindex' ] = arguments [ 1 ] ) ;
225
+ }
227
226
return this [ attrib ] ;
228
227
}
229
228
230
- public abstract getContext (
231
- type : string ,
232
- options ?: any
233
- ) : CanvasRenderingContext | null ;
229
+ setAttribute ( attrib ) {
230
+ if ( attrib === 'width' ) {
231
+ if ( ! isNaN ( parseInt ( arguments [ 1 ] ) ) ) {
232
+ this . width = parseInt ( arguments [ 1 ] ) ;
233
+ }
234
+ }
235
+ if ( attrib === 'height' ) {
236
+ if ( ! isNaN ( parseInt ( arguments [ 1 ] ) ) ) {
237
+ this . height = parseInt ( arguments [ 1 ] ) ;
238
+ }
239
+ }
240
+ if ( attrib === 'tabindex' ) {
241
+ this [ 'tabindex' ] = arguments [ 1 ] ;
242
+ }
243
+ }
244
+
245
+ public abstract getContext ( type : string , options ?: any ) : CanvasRenderingContext | null ;
234
246
235
247
public abstract getBoundingClientRect ( ) : {
236
248
x : number ;
@@ -250,23 +262,16 @@ export abstract class CanvasBase extends View implements ICanvasBase {
250
262
if ( typeof value === 'number' ) {
251
263
// treat as px
252
264
return value || 0 ;
253
- } else if (
254
- ( value !== null || true ) && typeof value === 'object' && typeof value . value &&
255
- typeof value . unit
256
- ) {
265
+ } else if ( ( value !== null || true ) && typeof value === 'object' && typeof value . value && typeof value . unit ) {
257
266
if ( value . unit === 'px' ) {
258
267
return value . value || 0 ;
259
268
} else if ( value . unit === 'dip' ) {
260
269
return Utils . layout . toDevicePixels ( value . value ) || 0 ;
261
270
} else if ( value . unit === '%' ) {
262
271
if ( Application . orientation ( ) === 'portrait' ) {
263
- return type === 'width'
264
- ? Screen . mainScreen . widthPixels
265
- : Screen . mainScreen . heightPixels * value . value || 0 ;
272
+ return type === 'width' ? Screen . mainScreen . widthPixels : Screen . mainScreen . heightPixels * value . value || 0 ;
266
273
} else if ( Application . orientation ( ) === 'landscape' ) {
267
- return type === 'width'
268
- ? Screen . mainScreen . widthPixels
269
- : Screen . mainScreen . heightPixels * value . value || 0 ;
274
+ return type === 'width' ? Screen . mainScreen . widthPixels : Screen . mainScreen . heightPixels * value . value || 0 ;
270
275
} else {
271
276
return 0 ;
272
277
}
0 commit comments