1
1
/// <reference path="BEMCheckBox.d.ts" /> Needed for autocompletion and compilation.
2
2
3
- import { CheckBoxInterface } from "./" ;
3
+ import { CheckBoxInterface } from "./" ;
4
4
import { View } from "ui/core/view" ;
5
- import { ContentView } from "ui/content-view" ;
5
+ import { ContentView } from "ui/content-view" ;
6
6
import { Property , PropertyChangeData } from "ui/core/dependency-observable" ;
7
7
import { PropertyMetadata } from "ui/core/proxy" ;
8
- import { Color } from "color" ;
9
- import { Label } from "ui/label" ;
10
- import { Button } from "ui/button" ;
11
- import { StackLayout } from "ui/layouts/stack-layout" ;
12
- import style = require( "ui/styling/style" ) ;
8
+ import { Color } from "color" ;
9
+ import { Label } from "ui/label" ;
10
+ import { Button } from "ui/button" ;
11
+ import { StackLayout } from "ui/layouts/stack-layout" ;
13
12
14
13
15
14
declare var CGRectMake : any , CGPointMake : any ;
16
15
17
16
export class CheckBox extends Button implements CheckBoxInterface {
18
17
public static checkedProperty = new Property ( "checked" , "CheckBox" , new PropertyMetadata ( false ) ) ;
19
-
20
18
private _iosCheckbox : BEMCheckBox ;
21
19
private _delegate : BEMCheckBoxDelegateImpl ;
22
- private _checked : boolean ;
23
20
private _fillColor : string = "#0075ff" ;
24
21
private _tintColor : string = "#0075ff" ;
25
22
private _lineWidth : number = 1 ;
@@ -41,26 +38,26 @@ export class CheckBox extends Button implements CheckBoxInterface {
41
38
this . _tintColor = "#0075ff" ;
42
39
this . _onAnimationType = 2 ;
43
40
this . _offAnimationType = 2 ;
44
-
45
41
this . _iosCheckbox = < BEMCheckBox > BEMCheckBox . alloc ( ) . initWithFrame ( CGRectMake ( 0 , 0 , 21 , 21 ) ) ;
46
42
this . _delegate = BEMCheckBoxDelegateImpl . initWithOwner ( new WeakRef ( this ) ) ;
47
- }
43
+ }
48
44
49
45
get checked ( ) : boolean {
50
- return this . _getValue ( CheckBox . checkedProperty ) ;
46
+ return this . _getValue ( CheckBox . checkedProperty ) ;
51
47
}
48
+
52
49
set checked ( value : boolean ) {
53
50
this . _setValue ( CheckBox . checkedProperty , value ) ;
54
51
}
55
52
56
53
set fillColor ( color : string ) {
57
- this . _iosCheckbox . onFillColor = new Color ( color ) . ios ;
58
- this . _fillColor = color ;
54
+ this . _iosCheckbox . onFillColor = new Color ( color ) . ios ;
55
+ this . _fillColor = color ;
59
56
}
60
57
61
58
set tintColor ( color : string ) {
62
- this . _tintColor = color ;
63
- this . _iosCheckbox . onTintColor = new Color ( color ) . ios ;
59
+ this . _tintColor = color ;
60
+ this . _iosCheckbox . onTintColor = new Color ( color ) . ios ;
64
61
}
65
62
66
63
/* NATIVE PROPERTIES */
@@ -136,19 +133,25 @@ export class CheckBox extends Button implements CheckBoxInterface {
136
133
public reload ( value : boolean ) {
137
134
this . _iosCheckbox . reload ( ) ;
138
135
}
136
+
139
137
/* END NATIVE PROPERTIES */
140
138
141
139
142
140
public onLoaded ( ) {
143
141
super . onLoaded ( ) ;
144
142
145
- var fontSize = this . style . fontSize ;
143
+ var fontSize ;
144
+
145
+ if ( ! this . style . fontSize ) {
146
+ fontSize = 15 ;
147
+ } else {
148
+ fontSize = this . style . fontSize ;
149
+ }
146
150
this . _iosCheckbox . delegate = this . _delegate ;
151
+ // //Positioning
152
+ this . _iosCheckbox . frame = CGRectMake ( 0 , 0 , fontSize , fontSize ) ;
153
+ this . _iosCheckbox . center = CGPointMake ( this . _iosCheckbox . center . x , ( fontSize / 2 ) + 3 ) ;
147
154
148
- //Positioning
149
- this . _iosCheckbox . frame = CGRectMake ( 0 , 0 , fontSize , fontSize ) ;
150
- this . _iosCheckbox . center = CGPointMake ( this . _iosCheckbox . center . x , ( fontSize / 2 ) + 3 ) ;
151
-
152
155
this . style . paddingLeft = fontSize + ( fontSize > 20 ? 10 : 5 ) ;
153
156
this . style . textAlignment = "left" ;
154
157
@@ -158,11 +161,11 @@ export class CheckBox extends Button implements CheckBoxInterface {
158
161
159
162
160
163
//Allow label click to change the textbox
161
- this . addEventListener ( "tap" , function ( args ) {
162
- var checkbox = < CheckBox > args . object ;
163
- checkbox . checked = ! checkbox . checked ;
164
- } ) ;
165
-
164
+ this . addEventListener ( "tap" , function ( args ) {
165
+ var checkbox = < CheckBox > args . object ;
166
+ checkbox . checked = ! checkbox . checked ;
167
+ } ) ;
168
+
166
169
if ( typeof this . _lineWidth !== 'undefined' ) {
167
170
this . lineWidth = this . _lineWidth ;
168
171
}
@@ -196,12 +199,12 @@ export class CheckBox extends Button implements CheckBoxInterface {
196
199
}
197
200
198
201
public onUnloaded ( ) {
199
- this . _iosCheckbox . delegate = null ;
200
- super . onUnloaded ( ) ;
201
- }
202
+ this . _iosCheckbox . delegate = null ;
203
+ super . onUnloaded ( ) ;
204
+ }
202
205
203
206
204
- public toggle ( ) {
207
+ public toggle ( ) {
205
208
this . checked = ! this . checked ;
206
209
}
207
210
@@ -223,15 +226,15 @@ export class CheckBox extends Button implements CheckBoxInterface {
223
226
}
224
227
225
228
public _onCheckedPropertyChanged ( data : PropertyChangeData ) {
226
- if ( this . _iosCheckbox ) {
227
- this . _iosCheckbox . setOnAnimated ( data . newValue , true ) ;
228
- }
229
+ if ( this . _iosCheckbox ) {
230
+ this . _iosCheckbox . setOnAnimated ( data . newValue , true ) ;
231
+ }
229
232
}
230
233
}
231
234
232
235
function onCheckedPropertyChanged ( data : PropertyChangeData ) {
233
- var checkbox = < CheckBox > data . object ;
234
- checkbox . _onCheckedPropertyChanged ( data ) ;
236
+ var checkbox = < CheckBox > data . object ;
237
+ checkbox . _onCheckedPropertyChanged ( data ) ;
235
238
}
236
239
237
240
@@ -240,33 +243,33 @@ function onCheckedPropertyChanged(data: PropertyChangeData) {
240
243
241
244
242
245
class BEMCheckBoxDelegateImpl extends NSObject implements BEMCheckBoxDelegate {
243
- public static ObjCProtocols = [ BEMCheckBoxDelegate ] ;
244
- /*public static ObjCExposedMethods = {
245
- "didTapCheckBox": { returns: interop.types.void, params: [NSObject] }
246
- };*/
246
+ public static ObjCProtocols = [ BEMCheckBoxDelegate ] ;
247
+ /*public static ObjCExposedMethods = {
248
+ "didTapCheckBox": { returns: interop.types.void, params: [NSObject] }
249
+ };*/
247
250
248
- private _owner : WeakRef < CheckBox > ;
251
+ private _owner : WeakRef < CheckBox > ;
249
252
250
- public static initWithOwner ( owner : WeakRef < CheckBox > ) : BEMCheckBoxDelegateImpl {
251
- let delegate = < BEMCheckBoxDelegateImpl > BEMCheckBoxDelegateImpl . new ( ) ;
252
- delegate . _owner = owner ;
253
- return delegate ;
254
- }
253
+ public static initWithOwner ( owner : WeakRef < CheckBox > ) : BEMCheckBoxDelegateImpl {
254
+ let delegate = < BEMCheckBoxDelegateImpl > BEMCheckBoxDelegateImpl . new ( ) ;
255
+ delegate . _owner = owner ;
256
+ return delegate ;
257
+ }
255
258
256
- public animationDidStopForCheckBox ( checkBox : BEMCheckBox ) : void {
257
- //TODO: Maybe trigger event later?
258
- }
259
+ public animationDidStopForCheckBox ( checkBox : BEMCheckBox ) : void {
260
+ //TODO: Maybe trigger event later?
261
+ }
259
262
260
- public didTapCheckBox ( checkBox : BEMCheckBox ) : void {
261
- let owner = this . _owner . get ( ) ;
262
- if ( owner ) {
263
- var eventData = {
264
- eventName : "tap" ,
265
- object : owner
266
- } ;
267
-
268
- owner . notify ( eventData ) ;
269
- owner . _onPropertyChangedFromNative ( CheckBox . checkedProperty , checkBox . on ) ;
270
- }
263
+ public didTapCheckBox ( checkBox : BEMCheckBox ) : void {
264
+ let owner = this . _owner . get ( ) ;
265
+ if ( owner ) {
266
+ var eventData = {
267
+ eventName : "tap" ,
268
+ object : owner
269
+ } ;
270
+
271
+ owner . notify ( eventData ) ;
272
+ owner . _onPropertyChangedFromNative ( CheckBox . checkedProperty , checkBox . on ) ;
271
273
}
274
+ }
272
275
}
0 commit comments