diff --git a/README.md b/README.md index fbcada3..6f7c0ce 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ export class SomeComponent { ## Css Styling - **color** - set the text label color -- **font-size** - checkbox is sized to text from here +- **font-size** - checkbox is sized to text from here : default 15 - **border-width** - set the line width of the checkbox element: iOS only ## Demo Setup diff --git a/checkbox.android.ts b/checkbox.android.ts index 8ff3e54..e1ce155 100644 --- a/checkbox.android.ts +++ b/checkbox.android.ts @@ -53,19 +53,19 @@ export class CheckBox extends View implements CheckBoxInterface { this._setValue(CheckBox.textProperty, value); } - get fillColor() : string { + get fillColor(): string { return this._fillColor; } set fillColor(color: string) { this._fillColor = color; - if(this._android && device.sdkVersion >= "21") + if (this._android && device.sdkVersion >= "21") this._android.setButtonTintList(android.content.res.ColorStateList.valueOf(new Color(this._fillColor).android)); } //There is no difference between tint and fill on the android widget - get tintColor() : string { + get tintColor(): string { return this.fillColor; } @@ -81,10 +81,13 @@ export class CheckBox extends View implements CheckBoxInterface { if (this.text) { this._android.setText(this.text); } + if (!this.style.fontSize) { + this.style.fontSize = 15; + } + - - if(this._android){ - if(this.fillColor && device.sdkVersion >= "21"){ + if (this._android) { + if (this.fillColor && device.sdkVersion >= "21") { //Set bound colors this._android.setButtonTintList(android.content.res.ColorStateList.valueOf(new Color(this._fillColor).android)); } @@ -141,14 +144,14 @@ function onTextPropertyChanged(data: PropertyChangeData) { export class CheckBoxStyler implements style.Styler { - private static setColorLabelProperty(view: any, newValue: any) { + private static setColorLabelProperty(view: any, newValue: any) { var cb = view._nativeView; - if (cb) { + if (cb) { (cb).setTextColor(new Color(newValue).android); } } -// font + // font private static setFontInternalProperty(view: any, newValue: any, nativeValue?: any) { var tv = view._nativeView; var fontValue = newValue; diff --git a/checkbox.ios.ts b/checkbox.ios.ts index 0d88586..ff47af2 100644 --- a/checkbox.ios.ts +++ b/checkbox.ios.ts @@ -1,25 +1,22 @@ /// Needed for autocompletion and compilation. -import {CheckBoxInterface} from "./"; +import { CheckBoxInterface } from "./"; import { View } from "ui/core/view"; -import {ContentView} from "ui/content-view"; +import { ContentView } from "ui/content-view"; import { Property, PropertyChangeData } from "ui/core/dependency-observable"; import { PropertyMetadata } from "ui/core/proxy"; -import {Color} from "color"; -import {Label} from "ui/label"; -import {Button} from "ui/button"; -import {StackLayout} from "ui/layouts/stack-layout"; -import style = require("ui/styling/style"); +import { Color } from "color"; +import { Label } from "ui/label"; +import { Button } from "ui/button"; +import { StackLayout } from "ui/layouts/stack-layout"; declare var CGRectMake: any, CGPointMake: any; export class CheckBox extends Button implements CheckBoxInterface { public static checkedProperty = new Property("checked", "CheckBox", new PropertyMetadata(false)); - private _iosCheckbox: BEMCheckBox; private _delegate: BEMCheckBoxDelegateImpl; - private _checked: boolean; private _fillColor: string = "#0075ff"; private _tintColor: string = "#0075ff"; private _lineWidth: number = 1; @@ -41,26 +38,26 @@ export class CheckBox extends Button implements CheckBoxInterface { this._tintColor = "#0075ff"; this._onAnimationType = 2; this._offAnimationType = 2; - this._iosCheckbox = BEMCheckBox.alloc().initWithFrame(CGRectMake(0, 0, 21, 21)); this._delegate = BEMCheckBoxDelegateImpl.initWithOwner(new WeakRef(this)); - } + } get checked(): boolean { - return this._getValue(CheckBox.checkedProperty); + return this._getValue(CheckBox.checkedProperty); } + set checked(value: boolean) { this._setValue(CheckBox.checkedProperty, value); } set fillColor(color: string) { - this._iosCheckbox.onFillColor = new Color(color).ios; - this._fillColor = color; + this._iosCheckbox.onFillColor = new Color(color).ios; + this._fillColor = color; } set tintColor(color: string) { - this._tintColor = color; - this._iosCheckbox.onTintColor = new Color(color).ios; + this._tintColor = color; + this._iosCheckbox.onTintColor = new Color(color).ios; } /* NATIVE PROPERTIES */ @@ -136,19 +133,25 @@ export class CheckBox extends Button implements CheckBoxInterface { public reload(value: boolean) { this._iosCheckbox.reload(); } + /* END NATIVE PROPERTIES */ public onLoaded() { super.onLoaded(); - var fontSize = this.style.fontSize; + var fontSize; + + if (!this.style.fontSize) { + fontSize = 15; + } else { + fontSize = this.style.fontSize; + } this._iosCheckbox.delegate = this._delegate; + // //Positioning + this._iosCheckbox.frame = CGRectMake(0, 0, fontSize, fontSize); + this._iosCheckbox.center = CGPointMake(this._iosCheckbox.center.x, (fontSize / 2) + 3); - //Positioning - this._iosCheckbox.frame = CGRectMake(0,0,fontSize,fontSize); - this._iosCheckbox.center = CGPointMake( this._iosCheckbox.center.x, (fontSize / 2) + 3); - this.style.paddingLeft = fontSize + (fontSize > 20 ? 10 : 5); this.style.textAlignment = "left"; @@ -158,11 +161,11 @@ export class CheckBox extends Button implements CheckBoxInterface { //Allow label click to change the textbox - this.addEventListener("tap", function(args){ - var checkbox = args.object; - checkbox.checked = !checkbox.checked; - }); - + this.addEventListener("tap", function (args) { + var checkbox = args.object; + checkbox.checked = !checkbox.checked; + }); + if (typeof this._lineWidth !== 'undefined') { this.lineWidth = this._lineWidth; } @@ -196,12 +199,12 @@ export class CheckBox extends Button implements CheckBoxInterface { } public onUnloaded() { - this._iosCheckbox.delegate = null; - super.onUnloaded(); - } + this._iosCheckbox.delegate = null; + super.onUnloaded(); + } - public toggle(){ + public toggle() { this.checked = !this.checked; } @@ -223,15 +226,15 @@ export class CheckBox extends Button implements CheckBoxInterface { } public _onCheckedPropertyChanged(data: PropertyChangeData) { - if(this._iosCheckbox){ - this._iosCheckbox.setOnAnimated(data.newValue, true); - } + if (this._iosCheckbox) { + this._iosCheckbox.setOnAnimated(data.newValue, true); + } } } function onCheckedPropertyChanged(data: PropertyChangeData) { - var checkbox = data.object; - checkbox._onCheckedPropertyChanged(data); + var checkbox = data.object; + checkbox._onCheckedPropertyChanged(data); } @@ -240,33 +243,33 @@ function onCheckedPropertyChanged(data: PropertyChangeData) { class BEMCheckBoxDelegateImpl extends NSObject implements BEMCheckBoxDelegate { - public static ObjCProtocols = [BEMCheckBoxDelegate]; - /*public static ObjCExposedMethods = { - "didTapCheckBox": { returns: interop.types.void, params: [NSObject] } - };*/ + public static ObjCProtocols = [BEMCheckBoxDelegate]; + /*public static ObjCExposedMethods = { + "didTapCheckBox": { returns: interop.types.void, params: [NSObject] } + };*/ - private _owner: WeakRef; + private _owner: WeakRef; - public static initWithOwner(owner: WeakRef): BEMCheckBoxDelegateImpl { - let delegate = BEMCheckBoxDelegateImpl.new(); - delegate._owner = owner; - return delegate; - } + public static initWithOwner(owner: WeakRef): BEMCheckBoxDelegateImpl { + let delegate = BEMCheckBoxDelegateImpl.new(); + delegate._owner = owner; + return delegate; + } - public animationDidStopForCheckBox(checkBox: BEMCheckBox): void { - //TODO: Maybe trigger event later? - } + public animationDidStopForCheckBox(checkBox: BEMCheckBox): void { + //TODO: Maybe trigger event later? + } - public didTapCheckBox(checkBox: BEMCheckBox): void { - let owner = this._owner.get(); - if (owner) { - var eventData = { - eventName: "tap", - object: owner - }; - - owner.notify(eventData); - owner._onPropertyChangedFromNative(CheckBox.checkedProperty, checkBox.on); - } + public didTapCheckBox(checkBox: BEMCheckBox): void { + let owner = this._owner.get(); + if (owner) { + var eventData = { + eventName: "tap", + object: owner + }; + + owner.notify(eventData); + owner._onPropertyChangedFromNative(CheckBox.checkedProperty, checkBox.on); } + } } diff --git a/index.d.ts b/index.d.ts index aaf7ad6..99fceff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -27,7 +27,7 @@ export declare class CheckBox { } export interface CheckBoxInterface { - text: string; + text?: string; checked: boolean; fillColor: string; tintColor: string; diff --git a/platforms/ios/nativescriptcheckbox/app/App_Resources/iOS/Info.plist b/platforms/ios/nativescriptcheckbox/app/App_Resources/iOS/Info.plist deleted file mode 100644 index ea3e3ea..0000000 --- a/platforms/ios/nativescriptcheckbox/app/App_Resources/iOS/Info.plist +++ /dev/null @@ -1,47 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleDisplayName - ${PRODUCT_NAME} - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1.0 - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIRequiresFullScreen - - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - -