Skip to content

Commit a289ba5

Browse files
committed
fix(ios): ios fix
1 parent 62e4666 commit a289ba5

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

src/checkbox.ios.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class CheckBox extends Button implements CheckBoxInterface {
7676
_tintColor: string;
7777
_onFillColor: string;
7878
_fillColor: string;
79-
nativeViewProtected: BEMCheckBox;
79+
_iosCheckbox: BEMCheckBox;
8080
private _delegate: BEMCheckBoxDelegateImpl;
8181
private _lineWidth: number = 1;
8282
private _hideBox: boolean;
@@ -87,44 +87,47 @@ export class CheckBox extends Button implements CheckBoxInterface {
8787
private _offAnimationType: number;
8888

8989
createNativeView() {
90-
return BEMCheckBox.alloc().initWithFrame(
90+
const view = super.createNativeView() as UIButton;
91+
this._iosCheckbox = BEMCheckBox.alloc().initWithFrame(
9192
CGRectMake(0, 0, 80, 80)
9293
) as BEMCheckBox;
94+
view.addSubview(this._iosCheckbox);
95+
return view;
9396
}
9497

9598
set fillColor(color: string) {
9699
this._fillColor = color;
97-
this.nativeViewProtected.onFillColor = new Color(color).ios;
100+
this._iosCheckbox.onFillColor = new Color(color).ios;
98101
}
99102

100103
set onFillColor(color: string) {
101104
this._onFillColor = color;
102-
this.nativeViewProtected.onFillColor = new Color(color).ios;
105+
this._iosCheckbox.onFillColor = new Color(color).ios;
103106
}
104107

105108
set tintColor(color: string) {
106109
this._tintColor = color;
107-
this.nativeViewProtected.tintColor = new Color(color).ios;
110+
this._iosCheckbox.tintColor = new Color(color).ios;
108111
}
109112

110113
set onTintColor(color: string) {
111114
this._onTintColor = color;
112-
this.nativeViewProtected.onTintColor = new Color(color).ios;
115+
this._iosCheckbox.onTintColor = new Color(color).ios;
113116
}
114117

115118
set checkBoxBackgroundColor(color: any) {
116119
this._checkBoxBackgroundColor = color;
117-
this.nativeViewProtected.offFillColor = new Color(color).ios;
120+
this._iosCheckbox.offFillColor = new Color(color).ios;
118121
}
119122

120123
set onCheckColor(color: string) {
121124
this._onCheckColor = color;
122-
this.nativeViewProtected.onCheckColor = new Color(color).ios;
125+
this._iosCheckbox.onCheckColor = new Color(color).ios;
123126
}
124127

125128
[boxTypeProperty.setNative](value: any) {
126129
if (this.nativeViewProtected) {
127-
this.nativeViewProtected.boxType = value;
130+
this._iosCheckbox.boxType = value;
128131
}
129132
}
130133

@@ -133,45 +136,45 @@ export class CheckBox extends Button implements CheckBoxInterface {
133136
}
134137

135138
[checkedProperty.setNative](value: boolean) {
136-
this.nativeViewProtected.setOnAnimated(value, true);
139+
this._iosCheckbox.setOnAnimated(value, true);
137140
}
138141

139142
set checkedAnimated(value: boolean) {
140-
this.nativeViewProtected.setOnAnimated(value, true);
143+
this._iosCheckbox.setOnAnimated(value, true);
141144
}
142145

143146
set lineWidth(value: number) {
144-
this.nativeViewProtected.lineWidth = value;
147+
this._iosCheckbox.lineWidth = value;
145148
this._lineWidth = value;
146149
}
147150

148151
set hideBox(value: boolean) {
149-
this.nativeViewProtected.hideBox = value;
152+
this._iosCheckbox.hideBox = value;
150153
this._hideBox = value;
151154
}
152155

153156
set animationDuration(value: number) {
154-
this.nativeViewProtected.animationDuration = value;
157+
this._iosCheckbox.animationDuration = value;
155158
this._animationDuration = value;
156159
}
157160

158161
set onAnimationType(value: number) {
159-
if (this.nativeViewProtected)
160-
this.nativeViewProtected.onAnimationType = this._getAnimationType(value);
162+
if (this._iosCheckbox)
163+
this._iosCheckbox.onAnimationType = this._getAnimationType(value);
161164
else this._onAnimationType = value;
162165
}
163166

164167
set offAnimationType(value: number) {
165-
this.nativeViewProtected.offAnimationType = this._getAnimationType(value);
168+
this._iosCheckbox.offAnimationType = this._getAnimationType(value);
166169
this._offAnimationType = value;
167170
}
168171

169172
get nativeiOSCheckBox() {
170-
return this.nativeViewProtected;
173+
return this._iosCheckbox;
171174
}
172175

173176
reload(value: boolean) {
174-
this.nativeViewProtected.reload();
177+
this._iosCheckbox.reload();
175178
}
176179
tapTimeout
177180
initNativeView() {
@@ -197,37 +200,36 @@ export class CheckBox extends Button implements CheckBoxInterface {
197200
fontSize = this.style.fontSize;
198201
}
199202

200-
this.nativeViewProtected.delegate = this._delegate;
203+
this._iosCheckbox.delegate = this._delegate;
201204
// positioning
202-
this.nativeViewProtected.frame = CGRectMake(0, 0, fontSize, fontSize);
203-
this.nativeViewProtected.center = CGPointMake(
204-
this.nativeViewProtected.center.x,
205+
this._iosCheckbox.frame = CGRectMake(0, 0, fontSize, fontSize);
206+
this._iosCheckbox.center = CGPointMake(
207+
this._iosCheckbox.center.x,
205208
fontSize / 2 + 3
206209
);
207210
this.style.paddingLeft = fontSize + (fontSize > 20 ? 10 : 5);
208211
this.style.textAlignment = 'left';
209212

210213
if (this._onCheckColor) {
211-
this.nativeViewProtected.onCheckColor = new Color(this._onCheckColor).ios;
214+
this._iosCheckbox.onCheckColor = new Color(this._onCheckColor).ios;
212215
}
213216

214217
if (this._onFillColor) {
215-
this.nativeViewProtected.onFillColor = new Color(this._onFillColor).ios;
218+
this._iosCheckbox.onFillColor = new Color(this._onFillColor).ios;
216219
}
217220

218221
if (this._onTintColor) {
219-
this.nativeViewProtected.onTintColor = new Color(this._onTintColor).ios;
222+
this._iosCheckbox.onTintColor = new Color(this._onTintColor).ios;
220223
}
221224

222225
if (this._fillColor) {
223-
this.nativeViewProtected.onFillColor = new Color(this._fillColor).ios;
226+
this._iosCheckbox.onFillColor = new Color(this._fillColor).ios;
224227
}
225228

226229
if (this._tintColor) {
227-
this.nativeViewProtected.tintColor = new Color(this._tintColor).ios;
230+
this._iosCheckbox.tintColor = new Color(this._tintColor).ios;
228231
}
229232

230-
this.nativeView.addSubview(this.nativeViewProtected);
231233

232234
if (typeof this._lineWidth !== 'undefined') {
233235
this.lineWidth = this._lineWidth;
@@ -250,7 +252,8 @@ export class CheckBox extends Button implements CheckBoxInterface {
250252
}
251253

252254
disposeNativeView() {
253-
this.nativeViewProtected.delegate = null;
255+
this._iosCheckbox.delegate = null;
256+
this._iosCheckbox = null;
254257
this.removeEventListener('tap');
255258
}
256259

@@ -278,7 +281,7 @@ export class CheckBox extends Button implements CheckBoxInterface {
278281
}
279282

280283
_onCheckedPropertyChanged(checkbox: CheckBox, oldValue, newValue) {
281-
if (!this.nativeView) {
284+
if (!this._iosCheckbox) {
282285
return;
283286
}
284287
checkedProperty.nativeValueChange(this, newValue);

0 commit comments

Comments
 (0)