Skip to content

Commit 58243f6

Browse files
committed
Fix for #18
1 parent d3165a3 commit 58243f6

File tree

5 files changed

+76
-117
lines changed

5 files changed

+76
-117
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class SomeComponent {
9696
## Css Styling
9797

9898
- **color** - set the text label color
99-
- **font-size** - checkbox is sized to text from here
99+
- **font-size** - checkbox is sized to text from here : default 15
100100
- **border-width** - set the line width of the checkbox element: iOS only
101101

102102
## Demo Setup

checkbox.android.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ export class CheckBox extends View implements CheckBoxInterface {
5353
this._setValue(CheckBox.textProperty, value);
5454
}
5555

56-
get fillColor() : string {
56+
get fillColor(): string {
5757
return this._fillColor;
5858
}
5959

6060
set fillColor(color: string) {
6161
this._fillColor = color;
6262

63-
if(this._android && device.sdkVersion >= "21")
63+
if (this._android && device.sdkVersion >= "21")
6464
this._android.setButtonTintList(android.content.res.ColorStateList.valueOf(new Color(this._fillColor).android));
6565
}
6666

6767
//There is no difference between tint and fill on the android widget
68-
get tintColor() : string {
68+
get tintColor(): string {
6969
return this.fillColor;
7070
}
7171

@@ -81,10 +81,13 @@ export class CheckBox extends View implements CheckBoxInterface {
8181
if (this.text) {
8282
this._android.setText(this.text);
8383
}
84+
if (!this.style.fontSize) {
85+
this.style.fontSize = 15;
86+
}
87+
8488

85-
86-
if(this._android){
87-
if(this.fillColor && device.sdkVersion >= "21"){
89+
if (this._android) {
90+
if (this.fillColor && device.sdkVersion >= "21") {
8891
//Set bound colors
8992
this._android.setButtonTintList(android.content.res.ColorStateList.valueOf(new Color(this._fillColor).android));
9093
}
@@ -141,14 +144,14 @@ function onTextPropertyChanged(data: PropertyChangeData) {
141144

142145

143146
export class CheckBoxStyler implements style.Styler {
144-
private static setColorLabelProperty(view: any, newValue: any) {
147+
private static setColorLabelProperty(view: any, newValue: any) {
145148
var cb = <android.widget.CheckBox>view._nativeView;
146-
if (cb) {
149+
if (cb) {
147150
(<any>cb).setTextColor(new Color(newValue).android);
148151
}
149152
}
150153

151-
// font
154+
// font
152155
private static setFontInternalProperty(view: any, newValue: any, nativeValue?: any) {
153156
var tv = <android.widget.CheckBox>view._nativeView;
154157
var fontValue = <Font>newValue;

checkbox.ios.ts

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
/// <reference path="BEMCheckBox.d.ts" /> Needed for autocompletion and compilation.
22

3-
import {CheckBoxInterface} from "./";
3+
import { CheckBoxInterface } from "./";
44
import { View } from "ui/core/view";
5-
import {ContentView} from "ui/content-view";
5+
import { ContentView } from "ui/content-view";
66
import { Property, PropertyChangeData } from "ui/core/dependency-observable";
77
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";
1312

1413

1514
declare var CGRectMake: any, CGPointMake: any;
1615

1716
export 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

232235
function 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

242245
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+
};*/
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
}

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export declare class CheckBox {
2727
}
2828

2929
export interface CheckBoxInterface {
30-
text: string;
30+
text?: string;
3131
checked: boolean;
3232
fillColor: string;
3333
tintColor: string;

platforms/ios/nativescriptcheckbox/app/App_Resources/iOS/Info.plist

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)