1- import { Button } from "tns-core-modules/ui/button" ;
2- import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout" ;
3- import { GridLayout } from "tns-core-modules/ui/layouts/grid-layout" ;
1+ import { Button } from "tns-core-modules/ui/button" ;
2+ import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout" ;
3+ import { GridLayout } from "tns-core-modules/ui/layouts/grid-layout" ;
44
55import * as utils from "tns-core-modules/utils/utils" ;
66import * as TKUnit from "../../TKUnit" ;
77import * as def from "./layout-helper" ;
88
99var DELTA = 0.1 ;
1010
11- class NativeButton extends android . widget . Button {
12- private owner : def . MeasuredView ;
13-
14- constructor ( context : android . content . Context , owner : def . MeasuredView ) {
11+ class NativeButton extends android . widget . Button {
12+ constructor ( context : android . content . Context , public owner : def . MeasuredView ) {
1513 super ( context ) ;
16- this . owner = owner ;
1714 return global . __native ( this ) ;
1815 }
1916
@@ -31,11 +28,8 @@ class NativeButton extends android.widget.Button {
3128}
3229
3330class NativeStackLayout extends org . nativescript . widgets . StackLayout {
34- private owner : def . MeasuredView ;
35-
36- constructor ( context : android . content . Context , owner : def . MeasuredView ) {
31+ constructor ( context : android . content . Context , public owner : def . MeasuredView ) {
3732 super ( context ) ;
38- this . owner = owner ;
3933 return global . __native ( this ) ;
4034 }
4135
@@ -53,11 +47,8 @@ class NativeStackLayout extends org.nativescript.widgets.StackLayout {
5347}
5448
5549class NativeGridLayout extends org . nativescript . widgets . GridLayout {
56- private owner : def . MeasuredView ;
57-
58- constructor ( context : android . content . Context , owner : def . MeasuredView ) {
50+ constructor ( context : android . content . Context , public owner : def . MeasuredView ) {
5951 super ( context ) ;
60- this . owner = owner ;
6152 return global . __native ( this ) ;
6253 }
6354
@@ -75,19 +66,18 @@ class NativeGridLayout extends org.nativescript.widgets.GridLayout {
7566}
7667
7768export class MyButton extends Button implements def . MyButton {
78- private _layout : android . view . View ;
69+ nativeView : NativeButton ;
7970
80- get android ( ) : android . view . View {
81- return this . _layout ;
71+ public createNativeView ( ) {
72+ return new NativeButton ( this . _context , this ) ;
8273 }
8374
84- get _nativeView ( ) : android . view . View {
85- return this . _layout ;
75+ public initNativeView ( ) : void {
76+ this . nativeView . owner = this ;
8677 }
8778
88- public _createNativeView ( ) {
89- this . _layout = new NativeButton ( this . _context , this ) ;
90- return this . _layout ;
79+ public disposeNativeView ( ) {
80+ this . nativeView . owner = undefined ;
9181 }
9282
9383 public measureCount : number = 0 ;
@@ -112,36 +102,35 @@ export class MyButton extends Button implements def.MyButton {
112102 }
113103
114104 get layoutWidth ( ) : number {
115- return this . _layout . getWidth ( ) ;
105+ return this . nativeView . getWidth ( ) ;
116106 }
117107
118108 get layoutHeight ( ) : number {
119- return this . _layout . getHeight ( ) ;
109+ return this . nativeView . getHeight ( ) ;
120110 }
121111
122112 get layoutLeft ( ) : number {
123- return this . _layout . getLeft ( ) ;
113+ return this . nativeView . getLeft ( ) ;
124114 }
125115
126116 get layoutTop ( ) : number {
127- return this . _layout . getTop ( ) ;
117+ return this . nativeView . getTop ( ) ;
128118 }
129119}
130120
131121export class MyStackLayout extends StackLayout implements def . MyStackLayout {
132- private _layout : android . view . View ;
122+ nativeView : NativeStackLayout ;
133123
134- get android ( ) : android . view . View {
135- return this . _layout ;
124+ public createNativeView ( ) {
125+ return new NativeStackLayout ( this . _context , this ) ;
136126 }
137127
138- get _nativeView ( ) : android . view . View {
139- return this . _layout ;
128+ public initNativeView ( ) : void {
129+ this . nativeView . owner = this ;
140130 }
141131
142- public _createNativeView ( ) {
143- this . _layout = new NativeStackLayout ( this . _context , this ) ;
144- return this . _layout ;
132+ public disposeNativeView ( ) {
133+ this . nativeView . owner = undefined ;
145134 }
146135
147136 public measureCount : number = 0 ;
@@ -166,36 +155,35 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout {
166155 }
167156
168157 get layoutWidth ( ) : number {
169- return this . _layout . getWidth ( ) ;
158+ return this . nativeView . getWidth ( ) ;
170159 }
171160
172161 get layoutHeight ( ) : number {
173- return this . _layout . getHeight ( ) ;
162+ return this . nativeView . getHeight ( ) ;
174163 }
175164
176165 get layoutLeft ( ) : number {
177- return this . _layout . getLeft ( ) ;
166+ return this . nativeView . getLeft ( ) ;
178167 }
179168
180169 get layoutTop ( ) : number {
181- return this . _layout . getTop ( ) ;
170+ return this . nativeView . getTop ( ) ;
182171 }
183172}
184173
185174export class MyGridLayout extends GridLayout implements def . MyGridLayout {
186- private _layout : android . view . View ;
175+ nativeView : NativeGridLayout ;
187176
188- get android ( ) : android . view . View {
189- return this . _layout ;
177+ public createNativeView ( ) {
178+ return new NativeGridLayout ( this . _context , this ) ;
190179 }
191180
192- get _nativeView ( ) : android . view . View {
193- return this . _layout ;
181+ public initNativeView ( ) : void {
182+ this . nativeView . owner = this ;
194183 }
195184
196- public _createNativeView ( ) {
197- this . _layout = new NativeGridLayout ( this . _context , this ) ;
198- return this . _layout ;
185+ public disposeNativeView ( ) {
186+ this . nativeView . owner = undefined ;
199187 }
200188
201189 public measureCount : number = 0 ;
@@ -220,19 +208,19 @@ export class MyGridLayout extends GridLayout implements def.MyGridLayout {
220208 }
221209
222210 get layoutWidth ( ) : number {
223- return this . _layout . getWidth ( ) ;
211+ return this . nativeView . getWidth ( ) ;
224212 }
225213
226214 get layoutHeight ( ) : number {
227- return this . _layout . getHeight ( ) ;
215+ return this . nativeView . getHeight ( ) ;
228216 }
229217
230218 get layoutLeft ( ) : number {
231- return this . _layout . getLeft ( ) ;
219+ return this . nativeView . getLeft ( ) ;
232220 }
233221
234222 get layoutTop ( ) : number {
235- return this . _layout . getTop ( ) ;
223+ return this . nativeView . getTop ( ) ;
236224 }
237225}
238226
@@ -258,4 +246,4 @@ export function dp(value: number): number {
258246
259247export function dip ( value : number ) : number {
260248 return utils . layout . toDevicePixels ( value ) ;
261- }
249+ }
0 commit comments