11/// <reference path="BEMCheckBox.d.ts" /> Needed for autocompletion and compilation.
22
3- import { CheckBoxInterface } from "./" ;
3+ import { CheckBoxInterface } from "./" ;
44import { View } from "ui/core/view" ;
5- import { ContentView } from "ui/content-view" ;
5+ import { ContentView } from "ui/content-view" ;
66import { Property , PropertyChangeData } from "ui/core/dependency-observable" ;
77import { 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" ;
1312
1413
1514declare var CGRectMake : any , CGPointMake : any ;
1615
1716export class CheckBox extends Button implements CheckBoxInterface {
1817 public static checkedProperty = new Property ( "checked" , "CheckBox" , new PropertyMetadata ( false ) ) ;
19-
2018 private _iosCheckbox : BEMCheckBox ;
2119 private _delegate : BEMCheckBoxDelegateImpl ;
22- private _checked : boolean ;
2320 private _fillColor : string = "#0075ff" ;
2421 private _tintColor : string = "#0075ff" ;
2522 private _lineWidth : number = 1 ;
@@ -41,26 +38,26 @@ export class CheckBox extends Button implements CheckBoxInterface {
4138 this . _tintColor = "#0075ff" ;
4239 this . _onAnimationType = 2 ;
4340 this . _offAnimationType = 2 ;
44-
4541 this . _iosCheckbox = < BEMCheckBox > BEMCheckBox . alloc ( ) . initWithFrame ( CGRectMake ( 0 , 0 , 21 , 21 ) ) ;
4642 this . _delegate = BEMCheckBoxDelegateImpl . initWithOwner ( new WeakRef ( this ) ) ;
47- }
43+ }
4844
4945 get checked ( ) : boolean {
50- return this . _getValue ( CheckBox . checkedProperty ) ;
46+ return this . _getValue ( CheckBox . checkedProperty ) ;
5147 }
48+
5249 set checked ( value : boolean ) {
5350 this . _setValue ( CheckBox . checkedProperty , value ) ;
5451 }
5552
5653 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 ;
5956 }
6057
6158 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 ;
6461 }
6562
6663 /* NATIVE PROPERTIES */
@@ -136,19 +133,25 @@ export class CheckBox extends Button implements CheckBoxInterface {
136133 public reload ( value : boolean ) {
137134 this . _iosCheckbox . reload ( ) ;
138135 }
136+
139137 /* END NATIVE PROPERTIES */
140138
141139
142140 public onLoaded ( ) {
143141 super . onLoaded ( ) ;
144142
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+ }
146150 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 ) ;
147154
148- //Positioning
149- this . _iosCheckbox . frame = CGRectMake ( 0 , 0 , fontSize , fontSize ) ;
150- this . _iosCheckbox . center = CGPointMake ( this . _iosCheckbox . center . x , ( fontSize / 2 ) + 3 ) ;
151-
152155 this . style . paddingLeft = fontSize + ( fontSize > 20 ? 10 : 5 ) ;
153156 this . style . textAlignment = "left" ;
154157
@@ -158,11 +161,11 @@ export class CheckBox extends Button implements CheckBoxInterface {
158161
159162
160163 //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+
166169 if ( typeof this . _lineWidth !== 'undefined' ) {
167170 this . lineWidth = this . _lineWidth ;
168171 }
@@ -196,12 +199,12 @@ export class CheckBox extends Button implements CheckBoxInterface {
196199 }
197200
198201 public onUnloaded ( ) {
199- this . _iosCheckbox . delegate = null ;
200- super . onUnloaded ( ) ;
201- }
202+ this . _iosCheckbox . delegate = null ;
203+ super . onUnloaded ( ) ;
204+ }
202205
203206
204- public toggle ( ) {
207+ public toggle ( ) {
205208 this . checked = ! this . checked ;
206209 }
207210
@@ -223,15 +226,15 @@ export class CheckBox extends Button implements CheckBoxInterface {
223226 }
224227
225228 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+ }
229232 }
230233}
231234
232235function onCheckedPropertyChanged ( data : PropertyChangeData ) {
233- var checkbox = < CheckBox > data . object ;
234- checkbox . _onCheckedPropertyChanged ( data ) ;
236+ var checkbox = < CheckBox > data . object ;
237+ checkbox . _onCheckedPropertyChanged ( data ) ;
235238}
236239
237240
@@ -240,33 +243,33 @@ function onCheckedPropertyChanged(data: PropertyChangeData) {
240243
241244
242245class 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+ };*/
247250
248- private _owner : WeakRef < CheckBox > ;
251+ private _owner : WeakRef < CheckBox > ;
249252
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+ }
255258
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+ }
259262
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 ) ;
271273 }
274+ }
272275}
0 commit comments