@@ -8,12 +8,12 @@ import {Label} from "ui/label";
8
8
import { StackLayout } from "ui/layouts/stack-layout" ;
9
9
import { Style , properties as styleProps } from 'ui/styling' ;
10
10
11
- declare var CGRectMake : any ;
11
+ declare var CGRectMake : any , CGPointMake : any ;
12
+
13
+ export class CheckBox extends Label {
14
+ public static checkedProperty = new Property ( "checked" , "CheckBox" , new PropertyMetadata ( true ) ) ;
12
15
13
- export class CheckBox extends ContentView {
14
- private _initalizing : boolean = true ;
15
16
private _iosCheckbox : BEMCheckBox ;
16
- private _iosLabel : UILabel ;
17
17
private _delegate : BEMCheckBoxDelegateImpl ;
18
18
private _checked : boolean ;
19
19
private _lineWidth : number ;
@@ -29,43 +29,27 @@ export class CheckBox extends ContentView{
29
29
30
30
constructor ( ) {
31
31
super ( ) ;
32
-
32
+ debugger ;
33
33
// just create with any width/height as XML view width/height is undefined at this point
34
34
// we modify width/height later below in onLoaded
35
- this . _iosCheckbox = < BEMCheckBox > BEMCheckBox . alloc ( ) . initWithFrame ( CGRectMake ( 0 , 0 , 25 , 25 ) ) ;
36
- this . _iosLabel = UILabel . alloc ( ) . initWithFrame ( CGRectMake ( 30 , 0 , 300 , 30 ) ) ;
35
+ this . _onCheckColor = "#ffffff" ;
36
+ this . _onFillColor = "#0075ff" ;
37
+ this . _onTintColor = "#0075ff" ;
38
+ this . _onAnimationType = 2 ;
39
+ this . _offAnimationType = 2 ;
40
+
41
+ this . _iosCheckbox = < BEMCheckBox > BEMCheckBox . alloc ( ) . initWithFrame ( CGRectMake ( 0 , 0 , 21 , 21 ) ) ;
37
42
this . _delegate = BEMCheckBoxDelegateImpl . initWithOwner ( new WeakRef ( this ) ) ;
38
43
}
39
44
40
- public static checkedProperty = new Property (
41
- "checked" ,
42
- "CheckBox" ,
43
- new PropertyMetadata ( false )
44
- ) ;
45
-
46
- public static textProperty = new Property (
47
- "text" ,
48
- "CheckBox" ,
49
- new PropertyMetadata ( false )
50
- ) ;
51
-
52
- get _nativeView ( ) : any {
53
- return this . _iosCheckbox ;
54
- }
55
45
get checked ( ) : boolean {
56
46
return this . _getValue ( CheckBox . checkedProperty ) ;
57
47
}
58
48
set checked ( value : boolean ) {
59
49
this . _setValue ( CheckBox . checkedProperty , value ) ;
60
50
}
61
51
62
- get text ( ) : string {
63
- return this . _getValue ( CheckBox . textProperty ) ;
64
- }
65
- set text ( value : string ) {
66
- this . _setValue ( CheckBox . textProperty , value ) ;
67
- }
68
-
52
+ /* NATIVE PROPERTIES */
69
53
set checkedAnimated ( value : boolean ) {
70
54
if ( this . _iosCheckbox )
71
55
this . _iosCheckbox . setOnAnimated ( value , true ) ;
@@ -144,22 +128,31 @@ export class CheckBox extends ContentView{
144
128
else
145
129
this . _offAnimationType = value ;
146
130
}
147
-
131
+
148
132
public reload ( value : boolean ) {
149
133
this . _iosCheckbox . reload ( ) ;
150
134
}
135
+ /* END NATIVE PROPERTIES */
136
+
151
137
152
138
public onLoaded ( ) {
139
+ super . onLoaded ( ) ;
140
+
153
141
this . _iosCheckbox . delegate = this . _delegate ;
154
- // Only here is where the view xml width/height is defined
155
- this . _iosCheckbox . frame . size . width = this . width ;
156
- this . _iosCheckbox . frame . size . height = this . height ;
157
-
158
- this . _iosLabel . text = this . text ;
159
- this . _iosCheckbox . addSubview ( this . _iosLabel ) ;
142
+ this . _iosCheckbox . frame = CGRectMake ( 0 , 0 , 21 , 21 ) ;
143
+ this . ios . addSubview ( this . _iosCheckbox ) ;
144
+ this . style . paddingLeft = 30 ;
145
+
146
+ //Allow label click to change the textbox
147
+ /*
148
+ this.addEventListener("tap", args =>{
149
+ this.toggle();
150
+ });
151
+ */
152
+ this . ios . addSubview ( this . _iosCheckbox ) ;
160
153
161
154
this . _iosCheckbox . on = this . checked ;
162
-
155
+
163
156
if ( typeof this . _lineWidth !== 'undefined' ) {
164
157
this . lineWidth = this . _lineWidth ;
165
158
}
@@ -190,10 +183,14 @@ export class CheckBox extends ContentView{
190
183
if ( typeof this . _offAnimationType !== 'undefined' ) {
191
184
this . offAnimationType = this . _offAnimationType ;
192
185
}
193
-
194
- this . _initalizing = false ;
195
186
}
196
187
188
+ public onUnloaded ( ) {
189
+ this . _iosCheckbox . delegate = null ;
190
+ super . onUnloaded ( ) ;
191
+ }
192
+
193
+
197
194
public toggle ( ) {
198
195
this . checked = ! this . checked ;
199
196
}
@@ -214,29 +211,26 @@ export class CheckBox extends ContentView{
214
211
return BEMAnimationType . Fade ;
215
212
}
216
213
}
217
- }
218
214
219
- function onCheckedPropertyChanged ( data : PropertyChangeData ) {
220
- if ( ! this . _initalizing ) {
221
- if ( this . _ios ) {
222
- this . _ios . on = data . newValue ;
215
+ public _onCheckedPropertyChanged ( data : PropertyChangeData ) {
216
+ console . log ( "_onCheckedPropertyChanged" ) ;
217
+ debugger ;
218
+ if ( this . _iosCheckbox ) {
219
+ this . _iosCheckbox . setOnAnimated ( data . newValue , true ) ;
223
220
}
224
- }
221
+ }
225
222
}
226
223
227
- // register the setNativeValue callbacks
228
- ( < PropertyMetadata > CheckBox . checkedProperty . metadata ) . onSetNativeValue = onCheckedPropertyChanged ;
229
-
230
-
231
- function onTextPropertyChanged ( data : PropertyChangeData ) {
232
- if ( ! this . _initalizing ) {
233
- if ( this . _iosLabel )
234
- this . _iosLabel . text = this . text ;
235
- }
224
+ function onCheckedPropertyChanged ( data : PropertyChangeData ) {
225
+ console . log ( "onCheckedPropertyChanged" ) ;
226
+ debugger ;
227
+ var checkbox = < CheckBox > data . object ;
228
+ checkbox . _onCheckedPropertyChanged ( data ) ;
236
229
}
237
230
231
+
238
232
// register the setNativeValue callbacks
239
- ( < PropertyMetadata > CheckBox . textProperty . metadata ) . onSetNativeValue = onTextPropertyChanged ;
233
+ ( < PropertyMetadata > CheckBox . checkedProperty . metadata ) . onSetNativeValue = onCheckedPropertyChanged ;
240
234
241
235
242
236
class BEMCheckBoxDelegateImpl extends NSObject implements BEMCheckBoxDelegate {
@@ -247,15 +241,19 @@ class BEMCheckBoxDelegateImpl extends NSObject implements BEMCheckBoxDelegate {
247
241
public static initWithOwner ( owner : WeakRef < CheckBox > ) : BEMCheckBoxDelegateImpl {
248
242
let delegate = < BEMCheckBoxDelegateImpl > BEMCheckBoxDelegateImpl . new ( ) ;
249
243
delegate . _owner = owner ;
250
-
251
244
return delegate ;
252
245
}
253
246
254
247
public animationDidStopForCheckBox ( checkBox : BEMCheckBox ) : void {
255
- //TODO: Maybe trigger event
248
+ //TODO: Maybe trigger event later?
256
249
}
257
250
258
251
public didTapCheckBox ( checkBox : BEMCheckBox ) : void {
259
- this . _owner . get ( ) . checked = checkBox . on ;
252
+ debugger ;
253
+ console . log ( "delegate check" ) ;
254
+ let owner = this . _owner . get ( ) ;
255
+ if ( owner ) {
256
+ owner . _onPropertyChangedFromNative ( CheckBox . checkedProperty , checkBox . on ) ;
257
+ }
260
258
}
261
259
}
0 commit comments