1+ import { ContentView } from "ui/content-view" ;
2+ import { Color } from "color" ;
3+
4+ declare var BEMCheckBox : any , CGRectMake : any , BEMBoxType : any , BEMAnimationType : any ;
5+
6+ export class CheckBox extends ContentView {
7+ private _ios : any ;
8+ private _checked : boolean ;
9+ private _lineWidth : number ;
10+ private _hideBox : boolean ;
11+ private _boxType : number ;
12+ private _tint : string ;
13+ private _onCheckColor : string ;
14+ private _onFillColor : string ;
15+ private _onTintColor : string ;
16+ private _animationDuration : number ;
17+ private _onAnimationType : number ;
18+ private _offAnimationType : number ;
19+
20+ constructor ( ) {
21+ super ( ) ;
22+ // just create with any width/height as XML view width/height is undefined at this point
23+ // we modify width/height later below in onLoaded
24+ this . _ios = BEMCheckBox . alloc ( ) . initWithFrame ( CGRectMake ( 0 , 0 , 50 , 50 ) ) ;
25+ }
26+
27+ get _nativeView ( ) : any {
28+ return this . _ios ;
29+ }
30+
31+ get checked ( ) : boolean {
32+ if ( this . _ios )
33+ return this . _ios . on ;
34+ else
35+ return false ;
36+ }
37+
38+ set checked ( value : boolean ) {
39+ if ( this . _ios )
40+ this . _ios . on = value ;
41+ else
42+ this . _checked = value ;
43+ }
44+
45+ set checkedAnimated ( value : boolean ) {
46+ if ( this . _ios )
47+ this . _ios . setOnAnimated ( value , true ) ;
48+ }
49+
50+ set lineWidth ( value : number ) {
51+ if ( this . _ios )
52+ this . _ios . lineWidth = value ;
53+ else
54+ this . _lineWidth = value ;
55+ }
56+
57+ set hideBox ( value : boolean ) {
58+ if ( this . _ios )
59+ this . _ios . hideBox = value ;
60+ else
61+ this . _hideBox = value ;
62+ }
63+
64+ set boxType ( value : number ) {
65+ let type = BEMBoxType . BEMBoxTypeCircle ;
66+ if ( value === 2 ) {
67+ type = BEMBoxType . BEMBoxTypeSquare ;
68+ }
69+ if ( this . _ios )
70+ this . _ios . boxType = type ;
71+ else
72+ this . _boxType = value ;
73+ }
74+
75+ set tint ( color : string ) {
76+ if ( this . _ios )
77+ this . _ios . tintColor = new Color ( color ) . ios ;
78+ else
79+ this . _tint = color ;
80+ }
81+
82+ set onCheckColor ( color : string ) {
83+ if ( this . _ios )
84+ this . _ios . onCheckColor = new Color ( color ) . ios ;
85+ else
86+ this . _onCheckColor = color ;
87+ }
88+
89+ set onFillColor ( color : string ) {
90+ if ( this . _ios )
91+ this . _ios . onFillColor = new Color ( color ) . ios ;
92+ else
93+ this . _onFillColor = color ;
94+ }
95+
96+ set onTintColor ( color : string ) {
97+ if ( this . _ios )
98+ this . _ios . onTintColor = new Color ( color ) . ios ;
99+ else
100+ this . _onTintColor = color ;
101+ }
102+
103+ set animationDuration ( value : number ) {
104+ if ( this . _ios )
105+ this . _ios . animationDuration = value ;
106+ else
107+ this . _animationDuration = value ;
108+ }
109+
110+ set onAnimationType ( value : number ) {
111+ if ( this . _ios )
112+ this . _ios . onAnimationType = this . getAnimationType ( value ) ;
113+ else
114+ this . _onAnimationType = value ;
115+ }
116+
117+ set offAnimationType ( value : number ) {
118+ if ( this . _ios )
119+ this . _ios . offAnimationType = this . getAnimationType ( value ) ;
120+ else
121+ this . _offAnimationType = value ;
122+ }
123+
124+ public reload ( value : boolean ) {
125+ this . _ios . reload ( ) ;
126+ }
127+
128+ public onLoaded ( ) {
129+ console . log ( `onLoaded` ) ;
130+ // Only here is where the view xml width/height is defined
131+ console . log ( this . width + ', ' + this . height ) ;
132+ this . _ios . frame . size . width = this . width ;
133+ this . _ios . frame . size . height = this . height ;
134+ // console.log(this._ios);
135+
136+ if ( typeof this . _checked !== 'undefined' ) {
137+ this . checked = this . _checked ;
138+ }
139+ if ( typeof this . _lineWidth !== 'undefined' ) {
140+ this . lineWidth = this . _lineWidth ;
141+ }
142+ if ( typeof this . _hideBox !== 'undefined' ) {
143+ this . hideBox = this . _hideBox ;
144+ }
145+ if ( typeof this . _boxType !== 'undefined' ) {
146+ this . boxType = this . _boxType ;
147+ }
148+ if ( typeof this . _tint !== 'undefined' ) {
149+ this . tint = this . _tint ;
150+ }
151+ if ( typeof this . _onCheckColor !== 'undefined' ) {
152+ this . onCheckColor = this . _onCheckColor ;
153+ }
154+ if ( typeof this . _onFillColor !== 'undefined' ) {
155+ this . onFillColor = this . _onFillColor ;
156+ }
157+ if ( typeof this . _onTintColor !== 'undefined' ) {
158+ this . onTintColor = this . _onTintColor ;
159+ }
160+ if ( typeof this . _animationDuration !== 'undefined' ) {
161+ this . animationDuration = this . _animationDuration ;
162+ }
163+ if ( typeof this . _onAnimationType !== 'undefined' ) {
164+ this . onAnimationType = this . _onAnimationType ;
165+ }
166+ if ( typeof this . _offAnimationType !== 'undefined' ) {
167+ this . offAnimationType = this . _offAnimationType ;
168+ }
169+ }
170+
171+ private getAnimationType ( value : number ) {
172+ switch ( value ) {
173+ case 1 :
174+ return BEMAnimationType . BEMAnimationTypeStroke ;
175+ case 2 :
176+ return BEMAnimationType . BEMAnimationTypeFill ;
177+ case 3 :
178+ return BEMAnimationType . BEMAnimationTypeBounce ;
179+ case 4 :
180+ return BEMAnimationType . BEMAnimationTypeFlat ;
181+ case 5 :
182+ return BEMAnimationType . BEMAnimationTypeOneStroke ;
183+ case 6 :
184+ return BEMAnimationType . BEMAnimationTypeFade ;
185+ }
186+ }
187+ }
0 commit comments