|
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"; |
4 | 4 |
|
5 | 5 | import * as utils from "tns-core-modules/utils/utils"; |
6 | 6 | import * as TKUnit from "../../TKUnit"; |
7 | 7 | import * as def from "./layout-helper"; |
8 | 8 |
|
9 | 9 | var DELTA = 0.1; |
10 | 10 |
|
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) { |
15 | 13 | super(context); |
16 | | - this.owner = owner; |
17 | 14 | return global.__native(this); |
18 | 15 | } |
19 | 16 |
|
@@ -31,11 +28,8 @@ class NativeButton extends android.widget.Button { |
31 | 28 | } |
32 | 29 |
|
33 | 30 | class 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) { |
37 | 32 | super(context); |
38 | | - this.owner = owner; |
39 | 33 | return global.__native(this); |
40 | 34 | } |
41 | 35 |
|
@@ -53,11 +47,8 @@ class NativeStackLayout extends org.nativescript.widgets.StackLayout { |
53 | 47 | } |
54 | 48 |
|
55 | 49 | class 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) { |
59 | 51 | super(context); |
60 | | - this.owner = owner; |
61 | 52 | return global.__native(this); |
62 | 53 | } |
63 | 54 |
|
@@ -75,19 +66,18 @@ class NativeGridLayout extends org.nativescript.widgets.GridLayout { |
75 | 66 | } |
76 | 67 |
|
77 | 68 | export class MyButton extends Button implements def.MyButton { |
78 | | - private _layout: android.view.View; |
| 69 | + nativeView: NativeButton; |
79 | 70 |
|
80 | | - get android(): android.view.View { |
81 | | - return this._layout; |
| 71 | + public createNativeView() { |
| 72 | + return new NativeButton(this._context, this); |
82 | 73 | } |
83 | 74 |
|
84 | | - get _nativeView(): android.view.View { |
85 | | - return this._layout; |
| 75 | + public initNativeView(): void { |
| 76 | + this.nativeView.owner = this; |
86 | 77 | } |
87 | 78 |
|
88 | | - public _createNativeView() { |
89 | | - this._layout = new NativeButton(this._context, this); |
90 | | - return this._layout; |
| 79 | + public disposeNativeView() { |
| 80 | + this.nativeView.owner = undefined; |
91 | 81 | } |
92 | 82 |
|
93 | 83 | public measureCount: number = 0; |
@@ -112,36 +102,35 @@ export class MyButton extends Button implements def.MyButton { |
112 | 102 | } |
113 | 103 |
|
114 | 104 | get layoutWidth(): number { |
115 | | - return this._layout.getWidth(); |
| 105 | + return this.nativeView.getWidth(); |
116 | 106 | } |
117 | 107 |
|
118 | 108 | get layoutHeight(): number { |
119 | | - return this._layout.getHeight(); |
| 109 | + return this.nativeView.getHeight(); |
120 | 110 | } |
121 | 111 |
|
122 | 112 | get layoutLeft(): number { |
123 | | - return this._layout.getLeft(); |
| 113 | + return this.nativeView.getLeft(); |
124 | 114 | } |
125 | 115 |
|
126 | 116 | get layoutTop(): number { |
127 | | - return this._layout.getTop(); |
| 117 | + return this.nativeView.getTop(); |
128 | 118 | } |
129 | 119 | } |
130 | 120 |
|
131 | 121 | export class MyStackLayout extends StackLayout implements def.MyStackLayout { |
132 | | - private _layout: android.view.View; |
| 122 | + nativeView: NativeStackLayout; |
133 | 123 |
|
134 | | - get android(): android.view.View { |
135 | | - return this._layout; |
| 124 | + public createNativeView() { |
| 125 | + return new NativeStackLayout(this._context, this); |
136 | 126 | } |
137 | 127 |
|
138 | | - get _nativeView(): android.view.View { |
139 | | - return this._layout; |
| 128 | + public initNativeView(): void { |
| 129 | + this.nativeView.owner = this; |
140 | 130 | } |
141 | 131 |
|
142 | | - public _createNativeView() { |
143 | | - this._layout = new NativeStackLayout(this._context, this); |
144 | | - return this._layout; |
| 132 | + public disposeNativeView() { |
| 133 | + this.nativeView.owner = undefined; |
145 | 134 | } |
146 | 135 |
|
147 | 136 | public measureCount: number = 0; |
@@ -166,36 +155,35 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout { |
166 | 155 | } |
167 | 156 |
|
168 | 157 | get layoutWidth(): number { |
169 | | - return this._layout.getWidth(); |
| 158 | + return this.nativeView.getWidth(); |
170 | 159 | } |
171 | 160 |
|
172 | 161 | get layoutHeight(): number { |
173 | | - return this._layout.getHeight(); |
| 162 | + return this.nativeView.getHeight(); |
174 | 163 | } |
175 | 164 |
|
176 | 165 | get layoutLeft(): number { |
177 | | - return this._layout.getLeft(); |
| 166 | + return this.nativeView.getLeft(); |
178 | 167 | } |
179 | 168 |
|
180 | 169 | get layoutTop(): number { |
181 | | - return this._layout.getTop(); |
| 170 | + return this.nativeView.getTop(); |
182 | 171 | } |
183 | 172 | } |
184 | 173 |
|
185 | 174 | export class MyGridLayout extends GridLayout implements def.MyGridLayout { |
186 | | - private _layout: android.view.View; |
| 175 | + nativeView: NativeGridLayout; |
187 | 176 |
|
188 | | - get android(): android.view.View { |
189 | | - return this._layout; |
| 177 | + public createNativeView() { |
| 178 | + return new NativeGridLayout(this._context, this); |
190 | 179 | } |
191 | 180 |
|
192 | | - get _nativeView(): android.view.View { |
193 | | - return this._layout; |
| 181 | + public initNativeView(): void { |
| 182 | + this.nativeView.owner = this; |
194 | 183 | } |
195 | 184 |
|
196 | | - public _createNativeView() { |
197 | | - this._layout = new NativeGridLayout(this._context, this); |
198 | | - return this._layout; |
| 185 | + public disposeNativeView() { |
| 186 | + this.nativeView.owner = undefined; |
199 | 187 | } |
200 | 188 |
|
201 | 189 | public measureCount: number = 0; |
@@ -220,19 +208,19 @@ export class MyGridLayout extends GridLayout implements def.MyGridLayout { |
220 | 208 | } |
221 | 209 |
|
222 | 210 | get layoutWidth(): number { |
223 | | - return this._layout.getWidth(); |
| 211 | + return this.nativeView.getWidth(); |
224 | 212 | } |
225 | 213 |
|
226 | 214 | get layoutHeight(): number { |
227 | | - return this._layout.getHeight(); |
| 215 | + return this.nativeView.getHeight(); |
228 | 216 | } |
229 | 217 |
|
230 | 218 | get layoutLeft(): number { |
231 | | - return this._layout.getLeft(); |
| 219 | + return this.nativeView.getLeft(); |
232 | 220 | } |
233 | 221 |
|
234 | 222 | get layoutTop(): number { |
235 | | - return this._layout.getTop(); |
| 223 | + return this.nativeView.getTop(); |
236 | 224 | } |
237 | 225 | } |
238 | 226 |
|
@@ -258,4 +246,4 @@ export function dp(value: number): number { |
258 | 246 |
|
259 | 247 | export function dip(value: number): number { |
260 | 248 | return utils.layout.toDevicePixels(value); |
261 | | -} |
| 249 | +} |