@@ -63,11 +63,9 @@ export class Canvas extends CanvasBase {
63
63
this . _canvas = new org . nativescript . canvas . NSCCanvas ( activity ) ;
64
64
}
65
65
66
- const textureView = this . _canvas . getChildAt ( 0 ) as android . view . TextureView ;
67
-
68
- const matrix = new android . graphics . Matrix ( ) ;
69
- matrix . setScale ( Screen . mainScreen . scale , Screen . mainScreen . scale ) ;
70
- //textureView.setTransform(matrix);
66
+ // default canvas size
67
+ this . _canvas . setSurfaceWidth ( 300 ) ;
68
+ this . _canvas . setSurfaceHeight ( 150 ) ;
71
69
72
70
( global as any ) . __canvasLoaded = true ;
73
71
const ref = new WeakRef ( this ) ;
@@ -95,39 +93,61 @@ export class Canvas extends CanvasBase {
95
93
}
96
94
97
95
get clientWidth ( ) {
98
- return this . width ;
96
+ return this . getMeasuredWidth ( ) / Screen . mainScreen . scale ;
99
97
}
100
98
101
99
get clientHeight ( ) {
102
- return this . height ;
100
+ return this . getMeasuredHeight ( ) / Screen . mainScreen . scale ;
103
101
}
104
102
105
103
get drawingBufferHeight ( ) {
104
+ if ( this . _canvas === undefined || this . _canvas === null ) {
105
+ return 0 ;
106
+ }
106
107
return this . _canvas . getDrawingBufferHeight ( ) ;
107
108
}
108
109
109
110
get drawingBufferWidth ( ) {
111
+ if ( this . _canvas === undefined || this . _canvas === null ) {
112
+ return 0 ;
113
+ }
110
114
return this . _canvas . getDrawingBufferWidth ( ) ;
111
115
}
112
116
113
117
// @ts -ignore
114
- get width ( ) : any {
115
- return this . _logicalSize . width ;
118
+ get width ( ) : number {
119
+ if ( this . _canvas === undefined || this . _canvas === null ) {
120
+ return 0 ;
121
+ }
122
+ return this . _canvas . getSurfaceWidth ( ) ;
116
123
}
117
124
118
- set width ( value ) {
119
- this . _didLayout = false ;
120
- this . _layoutNative ( ) ;
125
+ set width ( value : number ) {
126
+ if ( this . _canvas === undefined || this . _canvas === null ) {
127
+ return ;
128
+ }
129
+ if ( typeof value !== 'number' ) {
130
+ return ;
131
+ }
132
+ this . _canvas . setSurfaceWidth ( value ) ;
121
133
}
122
134
123
135
// @ts -ignore
124
- get height ( ) : any {
125
- return this . _logicalSize . height ;
136
+ get height ( ) : number {
137
+ if ( this . _canvas === undefined || this . _canvas === null ) {
138
+ return 0 ;
139
+ }
140
+ return this . _canvas . getSurfaceHeight ( ) ;
126
141
}
127
142
128
- set height ( value ) {
129
- this . _didLayout = false ;
130
- this . _layoutNative ( ) ;
143
+ set height ( value : number ) {
144
+ if ( this . _canvas === undefined || this . _canvas === null ) {
145
+ return ;
146
+ }
147
+ if ( typeof value !== 'number' ) {
148
+ return ;
149
+ }
150
+ this . _canvas . setSurfaceHeight ( value ) ;
131
151
}
132
152
133
153
static createCustomView ( ) {
@@ -243,13 +263,12 @@ export class Canvas extends CanvasBase {
243
263
return ;
244
264
}
245
265
246
- const size = this . _physicalSize ;
247
- console . log ( size ) ;
248
- org . nativescript . canvas . NSCCanvas . layoutView ( size . width || 0 , size . height || 0 , this . _canvas ) ;
266
+ // const size = this._physicalSize;
267
+ // org.nativescript.canvas.NSCCanvas.layoutView(size.width || 0, size.height || 0, this._canvas);
249
268
250
- if ( this . _is2D ) {
251
- this . _2dContext . native . __resize ( size . width , size . height ) ;
252
- }
269
+ // if (this._is2D) {
270
+ // this._2dContext.native.__resize(size.width, size.height);
271
+ // }
253
272
254
273
this . _didLayout = true ;
255
274
}
0 commit comments