@@ -3,7 +3,7 @@ import { DOMMatrix } from '../Canvas2D';
3
3
import { CanvasRenderingContext2D } from '../Canvas2D/CanvasRenderingContext2D' ;
4
4
import { WebGLRenderingContext } from '../WebGL/WebGLRenderingContext' ;
5
5
import { WebGL2RenderingContext } from '../WebGL2/WebGL2RenderingContext' ;
6
- import { Utils , profile } from " @nativescript/core" ;
6
+ import { Utils , profile } from ' @nativescript/core' ;
7
7
8
8
declare var TNSCanvas , TNSCanvasListener ;
9
9
@@ -22,30 +22,29 @@ export class Canvas extends CanvasBase {
22
22
23
23
constructor ( useCpu = false ) {
24
24
super ( ) ;
25
- this . _canvas = TNSCanvas . alloc ( ) . initWithFrameUseCpu (
26
- CGRectZero ,
27
- useCpu
28
- ) ;
29
- console . dir ( this . _canvas ) ;
25
+ this . _canvas = TNSCanvas . alloc ( ) . initWithFrameUseCpu ( CGRectZero , useCpu ) ;
30
26
const ref = new WeakRef ( this ) ;
31
- const listener = ( NSObject as any ) . extend ( {
32
- contextReady ( ) {
33
- if ( ! this . _isReady ) {
34
- const owner = ref . get ( ) ;
35
- if ( owner ) {
36
- owner . _readyEvent ( ) ;
37
- this . _isReady = true ;
27
+ const listener = ( NSObject as any ) . extend (
28
+ {
29
+ contextReady ( ) {
30
+ if ( ! this . _isReady ) {
31
+ const owner = ref . get ( ) ;
32
+ if ( owner ) {
33
+ owner . _readyEvent ( ) ;
34
+ this . _isReady = true ;
35
+ }
38
36
}
39
- }
37
+ } ,
38
+ } ,
39
+ {
40
+ protocols : [ TNSCanvasListener ] ,
40
41
}
41
- } , {
42
- protocols : [ TNSCanvasListener ]
43
- } ) ;
42
+ ) ;
44
43
this . _readyListener = listener . new ( ) ;
45
44
this . _canvas . setListener ( this . _readyListener ) ;
46
45
}
47
46
48
- [ ignorePixelScalingProperty . setNative ] ( value : boolean ) {
47
+ [ ignorePixelScalingProperty . setNative ] ( value : boolean ) {
49
48
this . _canvas . ignorePixelScaling = value ;
50
49
}
51
50
@@ -128,12 +127,12 @@ export class Canvas extends CanvasBase {
128
127
Object . defineProperty ( parent , 'clientWidth' , {
129
128
get : function ( ) {
130
129
return parent . getMeasuredWidth ( ) ;
131
- }
130
+ } ,
132
131
} ) ;
133
132
Object . defineProperty ( parent , 'clientHeight' , {
134
133
get : function ( ) {
135
134
return parent . getMeasuredHeight ( ) ;
136
- }
135
+ } ,
137
136
} ) ;
138
137
}
139
138
}
@@ -178,10 +177,7 @@ export class Canvas extends CanvasBase {
178
177
179
178
_layoutNative ( ) {
180
179
if ( ! this . parent ) {
181
- if (
182
- ( typeof this . style . width === 'string' && this . style . width . indexOf ( '%' ) ) ||
183
- ( typeof this . style . height === 'string' && this . style . height . indexOf ( '%' ) )
184
- ) {
180
+ if ( ( typeof this . style . width === 'string' && this . style . width . indexOf ( '%' ) ) || ( typeof this . style . height === 'string' && this . style . height . indexOf ( '%' ) ) ) {
185
181
return ;
186
182
}
187
183
if ( ! this . _isCustom ) {
@@ -201,27 +197,14 @@ export class Canvas extends CanvasBase {
201
197
}
202
198
203
199
const frame_origin = this . _canvas . frame . origin ;
204
- const frame = CGRectMake (
205
- frame_origin . x ,
206
- frame_origin . y ,
207
- width ,
208
- height
209
- ) ;
200
+ const frame = CGRectMake ( frame_origin . x , frame_origin . y , width , height ) ;
210
201
this . _canvas . frame = frame ;
211
202
this . _canvas . setNeedsLayout ( ) ;
212
203
this . _canvas . layoutIfNeeded ( ) ;
213
204
}
214
205
}
215
206
216
-
217
- getContext (
218
- type : string ,
219
- options ?: any
220
- ) :
221
- | CanvasRenderingContext2D
222
- | WebGLRenderingContext
223
- | WebGL2RenderingContext
224
- | null {
207
+ getContext ( type : string , options ?: any ) : CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext | null {
225
208
if ( ! this . _canvas ) {
226
209
return null ;
227
210
}
@@ -230,9 +213,7 @@ export class Canvas extends CanvasBase {
230
213
return null ;
231
214
}
232
215
if ( ! this . _2dContext ) {
233
- this . _2dContext = new CanvasRenderingContext2D (
234
- this . _canvas . getContextContextAttributes ( type , this . _handleContextOptions ( type , options ) )
235
- ) ;
216
+ this . _2dContext = new CanvasRenderingContext2D ( this . _canvas . getContextContextAttributes ( type , this . _handleContextOptions ( type , options ) ) ) ;
236
217
this . _2dContext . _canvas = this ;
237
218
} else {
238
219
this . _canvas . getContextContextAttributes ( type , this . _handleContextOptions ( type , options ) ) ;
@@ -244,9 +225,7 @@ export class Canvas extends CanvasBase {
244
225
return null ;
245
226
}
246
227
if ( ! this . _webglContext ) {
247
- this . _webglContext = new WebGLRenderingContext (
248
- this . _canvas . getContextContextAttributes ( 'webgl' , this . _handleContextOptions ( type , options ) )
249
- ) ;
228
+ this . _webglContext = new WebGLRenderingContext ( this . _canvas . getContextContextAttributes ( 'webgl' , this . _handleContextOptions ( type , options ) ) ) ;
250
229
this . _webglContext . _canvas = this ;
251
230
} else {
252
231
this . _canvas . getContextContextAttributes ( 'webgl' , this . _handleContextOptions ( type , options ) ) ;
@@ -258,9 +237,7 @@ export class Canvas extends CanvasBase {
258
237
return null ;
259
238
}
260
239
if ( ! this . _webgl2Context ) {
261
- this . _webgl2Context = new WebGL2RenderingContext (
262
- this . _canvas . getContextContextAttributes ( 'webgl2' , this . _handleContextOptions ( type , options ) )
263
- ) ;
240
+ this . _webgl2Context = new WebGL2RenderingContext ( this . _canvas . getContextContextAttributes ( 'webgl2' , this . _handleContextOptions ( type , options ) ) ) ;
264
241
( this . _webgl2Context as any ) . _canvas = this ;
265
242
} else {
266
243
this . _canvas . getContextContextAttributes ( 'webgl2' , this . _handleContextOptions ( type , options ) ) ;
0 commit comments