From 038440e39d7c2dad52bf87119c3d545c03a066f6 Mon Sep 17 00:00:00 2001 From: Brad Martin Date: Wed, 14 Jun 2017 11:04:54 -0500 Subject: [PATCH] closes #44 --- checkbox.android.ts | 453 ++++++++++++++++++++++------------------ checkbox.ios.ts | 496 ++++++++++++++++++++++---------------------- package.json | 2 +- 3 files changed, 498 insertions(+), 453 deletions(-) diff --git a/checkbox.android.ts b/checkbox.android.ts index b525787..6e5843b 100644 --- a/checkbox.android.ts +++ b/checkbox.android.ts @@ -1,259 +1,310 @@ import { Color } from "tns-core-modules/color"; import { device } from "tns-core-modules/platform"; import app = require("tns-core-modules/application"); -import {CheckBoxInterface} from "."; +import { CheckBoxInterface } from "."; import { - View, - Property, - CssProperty, - Style, - booleanConverter + View, + Property, + CssProperty, + Style, + booleanConverter } from "tns-core-modules/ui/core/view"; declare const android: any; export const checkedProperty = new Property({ - name: 'checked', - defaultValue: false, - valueConverter: booleanConverter, - valueChanged: onCheckedPropertyChanged + name: "checked", + defaultValue: false, + valueConverter: booleanConverter, + valueChanged: onCheckedPropertyChanged }); export const textProperty = new Property({ - name: 'text', - defaultValue: '', - valueChanged: onTextPropertyChanged + name: "text", + defaultValue: "", + valueChanged: onTextPropertyChanged }); export const fillColorProperty = new CssProperty({ - name: 'fillColor', - cssName: 'fill-color', - valueConverter: (v) => { - return String(v) - } + name: "fillColor", + cssName: "fill-color", + valueConverter: v => { + return String(v); + } }); export const tintColorProperty = new CssProperty({ - name: 'tintColor', - cssName: 'tint-color', - defaultValue: '#0075ff', - valueConverter: (v) => { - return String(v) - } + name: "tintColor", + cssName: "tint-color", + defaultValue: "#0075ff", + valueConverter: v => { + return String(v); + } }); export class CheckBox extends View implements CheckBoxInterface { - private _android: any; /// android.widget.CheckBox - private _checkStyle: string; - private _checkPadding: string; - private _checkPaddingLeft: string; - private _checkPaddingTop: string; - private _checkPaddingRight: string; - private _checkPaddingBottom: string; - public checked:boolean; - constructor() { - super(); - } - - get android() { - return this._android; + private _android: any; /// android.widget.CheckBox + private _checkStyle: string; + private _checkPadding: string; + private _checkPaddingLeft: string; + private _checkPaddingTop: string; + private _checkPaddingRight: string; + private _checkPaddingBottom: string; + public checked: boolean; + constructor() { + super(); + } + + get android() { + return this._android; + } + + get checkStyle() { + return this._checkStyle; + } + + set checkStyle(style) { + this._checkStyle = style; + } + + set checkPadding(padding) { + this._checkPadding = padding; + } + + get checkPadding() { + return this._checkPadding; + } + + set checkPaddingLeft(padding) { + this._checkPaddingLeft = padding; + } + + get checkPaddingLeft() { + return this._checkPaddingLeft; + } + + set checkPaddingTop(padding) { + this._checkPaddingTop = padding; + } + + get checkPaddingTop() { + return this._checkPaddingTop; + } + + set checkPaddingRight(padding) { + this._checkPaddingRight = padding; + } + + get checkPaddingRight() { + return this._checkPaddingRight; + } + + set checkPaddingBottom(padding) { + this._checkPaddingBottom = padding; + } + + get checkPaddingBottom() { + return this._checkPaddingBottom; + } + [checkedProperty.getDefault](): boolean { + return false; + } + [checkedProperty.setNative](value: boolean) { + this.nativeView.setChecked(Boolean(value)); + } + [textProperty.getDefault](): string { + return ""; + } + [textProperty.setNative](value: string) { + this.nativeView.setText(value); + } + + get fillColor(): string { + return (this.style).fillColor; + } + set fillColor(color: string) { + (this.style).fillColor = color; + if (this._android && device.sdkVersion >= "21") { + this._android.setButtonTintList( + android.content.res.ColorStateList.valueOf(new Color(color).android) + ); } - - get checkStyle() { - return this._checkStyle; - } - - set checkStyle(style) { - this._checkStyle = style; + } + + // there is no difference between tint and fill on the android widget + get tintColor(): string { + return (this.style).fillColor; + } + + set tintColor(color: string) { + (this.style).fillColor = color; + } + + public createNativeView() { + this._android = new android.support.v7.widget.AppCompatCheckBox( + this._context, + null + ); + if (this.checkPaddingLeft) { + this._android.setPadding( + parseInt(this.checkPaddingLeft), + this._android.getPaddingTop(), + this._android.getPaddingRight(), + this._android.getPaddingBottom() + ); } - set checkPadding(padding) { - this._checkPadding = padding; + if (this.checkPaddingTop) { + this._android.setPadding( + this._android.getPaddingLeft(), + parseInt(this.checkPaddingTop), + this._android.getPaddingRight(), + this._android.getPaddingBottom() + ); } - get checkPadding() { - return this._checkPadding; + if (this.checkPaddingRight) { + this._android.setPadding( + this._android.getPaddingLeft(), + this._android.getPaddingTop(), + parseInt(this.checkPaddingRight), + this._android.getPaddingBottom() + ); } - set checkPaddingLeft(padding) { - this._checkPaddingLeft = padding; + if (this.checkPaddingBottom) { + this._android.setPadding( + this._android.getPaddingLeft(), + this._android.getPaddingTop(), + this._android.getPaddingRight(), + parseInt(this.checkPaddingBottom) + ); } - get checkPaddingLeft() { - return this._checkPaddingLeft; + if (this.checkPadding) { + let pads = this.checkPadding.toString().split(","); + switch (pads.length) { + case 1: + this._android.setPadding( + parseInt(pads[0]), + parseInt(pads[0]), + parseInt(pads[0]), + parseInt(pads[0]) + ); + break; + case 2: + this._android.setPadding( + parseInt(pads[0]), + parseInt(pads[1]), + parseInt(pads[0]), + parseInt(pads[1]) + ); + break; + case 3: + this._android.setPadding( + parseInt(pads[0]), + parseInt(pads[1]), + parseInt(pads[2]), + parseInt(pads[1]) + ); + break; + case 4: + this._android.setPadding( + parseInt(pads[0]), + parseInt(pads[1]), + parseInt(pads[2]), + parseInt(pads[3]) + ); + break; + } } - - set checkPaddingTop(padding) { - this._checkPaddingTop = padding; + if (this.style.color) { + this._android.setTextColor(this.style.color.android); } - get checkPaddingTop() { - return this._checkPaddingTop; + if (!this.style.fontSize) { + this.style.fontSize = 15; } - set checkPaddingRight(padding) { - this._checkPaddingRight = padding; - } + this._android.setTextSize(this.style.fontSize); - get checkPaddingRight() { - return this._checkPaddingRight; + var typeface = this.style.fontInternal.getAndroidTypeface(); + if (typeface) { + this._android.setTypeface(typeface); } - set checkPaddingBottom(padding) { - this._checkPaddingBottom = padding; + if (this._checkStyle) { + const drawable = app.android.context + .getResources() + .getIdentifier( + this._checkStyle, + "drawable", + app.android.context.getPackageName() + ); + this._android.setButtonDrawable(drawable); } - get checkPaddingBottom() { - return this._checkPaddingBottom; - } - [checkedProperty.getDefault](): boolean { - return false; - } - [checkedProperty.setNative](value: boolean) { - this.nativeView.setChecked(Boolean(value)); + if (this._android) { + if (this.fillColor) { + android.support.v4.widget.CompoundButtonCompat.setButtonTintList( + this._android, + android.content.res.ColorStateList.valueOf( + new Color(this.fillColor).android + ) + ); + } } - [textProperty.getDefault](): string { - return ''; - } - [textProperty.setNative](value: string) { - this.nativeView.setText(value); - } - - get fillColor():string{ - return (this.style).fillColor; - } - set fillColor(color:string){ - (this.style).fillColor = color; - if (this._android && device.sdkVersion >= "21") { - this._android.setButtonTintList(android.content.res.ColorStateList.valueOf(new Color(color).android)); - } - } - - // There is no difference between tint and fill on the android widget - get tintColor(): string { - return (this.style).fillColor; - } - - set tintColor(color: string) { - (this.style).fillColor = color; - } - - public createNativeView() { - - this._android = new android.support.v7.widget.AppCompatCheckBox(this._context, null); - if (this.checkPaddingLeft) { - this._android.setPadding(parseInt(this.checkPaddingLeft), this._android.getPaddingTop(), this._android.getPaddingRight(), this._android.getPaddingBottom()); - } - - if (this.checkPaddingTop) { - this._android.setPadding(this._android.getPaddingLeft(), parseInt(this.checkPaddingTop), this._android.getPaddingRight(), this._android.getPaddingBottom()); - } - - if (this.checkPaddingRight) { - this._android.setPadding(this._android.getPaddingLeft(), this._android.getPaddingTop(), parseInt(this.checkPaddingRight), this._android.getPaddingBottom()); - } - - if (this.checkPaddingBottom) { - this._android.setPadding(this._android.getPaddingLeft(), this._android.getPaddingTop(), this._android.getPaddingRight(), parseInt(this.checkPaddingBottom)); - } - - if (this.checkPadding) { - let pads = this.checkPadding.toString().split(','); - switch (pads.length) { - case 1: - this._android.setPadding(parseInt(pads[0]), parseInt(pads[0]), parseInt(pads[0]), parseInt(pads[0])); - break; - case 2: - this._android.setPadding(parseInt(pads[0]), parseInt(pads[1]), parseInt(pads[0]), parseInt(pads[1])); - break; - case 3: - this._android.setPadding(parseInt(pads[0]), parseInt(pads[1]), parseInt(pads[2]), parseInt(pads[1])); - break; - case 4: - this._android.setPadding(parseInt(pads[0]), parseInt(pads[1]), parseInt(pads[2]), parseInt(pads[3])); - break; - } - } - - - if(this.style.color){ - this._android.setTextColor(this.style.color.android); - } - if (!this.style.fontSize) { - this.style.fontSize = 15; + return this._android; + } + + public initNativeView() { + var that = new WeakRef(this); + this.nativeView.setOnCheckedChangeListener( + new android.widget.CompoundButton.OnCheckedChangeListener({ + get owner(): CheckBox { + return that.get(); + }, + + onCheckedChanged: function(sender, isChecked) { + if (this.owner) { + checkedProperty.nativeValueChange(this.owner, isChecked); + } } + }) + ); + } - this._android.setTextSize(this.style.fontSize); - - var typeface = this.style.fontInternal.getAndroidTypeface(); - if (typeface) { - this._android.setTypeface(typeface); - } + public disposeNativeView() { + this.nativeView.setOnCheckedChangeListener(null); + } - if (this._checkStyle) { - const drawable = app.android.context.getResources().getIdentifier(this._checkStyle, "drawable", app.android.context.getPackageName()); - this._android.setButtonDrawable(drawable); - } - - - if (this._android) { - if (this.fillColor) { - android.support.v4.widget.CompoundButtonCompat.setButtonTintList(this._android, android.content.res.ColorStateList.valueOf(new Color(this.fillColor).android)); - } - } + public toggle(): void { + this.nativeView.toggle(); + } - return this._android; + _onCheckedPropertyChanged(checkbox: CheckBox, oldValue, newValue) { + if (!this.nativeView) { + return; } - - public initNativeView() { - var that = new WeakRef(this); - this.nativeView.setOnCheckedChangeListener(new android.widget.CompoundButton.OnCheckedChangeListener({ - get owner(): CheckBox { - return that.get(); - }, - - onCheckedChanged: function (sender, isChecked) { - if (this.owner) { - checkedProperty.nativeValueChange(this.owner, isChecked); - } - } - })); - } - - public disposeNativeView() { - this.nativeView.setOnCheckedChangeListener(null); + checkedProperty.nativeValueChange(this, newValue); + } + _onTextPropertyChanged(checkbox: CheckBox, oldValue, newValue) { + if (!this.nativeView) { + return; } - - public toggle(): void { - this.nativeView.toggle(); - } - - _onCheckedPropertyChanged(checkbox: CheckBox, oldValue, newValue) { - if (!this.nativeView) { - return - } - checkedProperty.nativeValueChange(this, newValue); - } - _onTextPropertyChanged(checkbox: CheckBox, oldValue, newValue) { - if (!this.nativeView) { - return - } - textProperty.nativeValueChange(this, newValue); - } - + textProperty.nativeValueChange(this, newValue); + } } - function onCheckedPropertyChanged(checkbox: CheckBox, oldValue, newValue) { - checkbox._onCheckedPropertyChanged(checkbox, oldValue, newValue); + checkbox._onCheckedPropertyChanged(checkbox, oldValue, newValue); } function onTextPropertyChanged(checkbox: CheckBox, oldValue, newValue) { - checkbox._onTextPropertyChanged(checkbox, oldValue, newValue); + checkbox._onTextPropertyChanged(checkbox, oldValue, newValue); } - checkedProperty.register(CheckBox); textProperty.register(CheckBox); fillColorProperty.register(Style); -tintColorProperty.register(Style); \ No newline at end of file +tintColorProperty.register(Style); diff --git a/checkbox.ios.ts b/checkbox.ios.ts index a26b8f6..835ee53 100644 --- a/checkbox.ios.ts +++ b/checkbox.ios.ts @@ -1,312 +1,306 @@ import { CheckBoxInterface } from "./index"; import { - Property, - CssProperty, - Style, - booleanConverter, + Property, + CssProperty, + Style, + booleanConverter } from "tns-core-modules/ui/core/view"; import { Color } from "tns-core-modules/color"; import { Button } from "tns-core-modules/ui/button"; declare const CGRectMake: any, CGPointMake: any; const checkBoxBackgroundColorProperty = new CssProperty({ - name: 'checkBoxBackgroundColor', - cssName: 'checkbox-background-color', - valueConverter: v => { - return String(v) - } + name: "checkBoxBackgroundColor", + cssName: "checkbox-background-color", + valueConverter: v => { + return String(v); + } }); const onCheckColorProperty = new CssProperty({ - name: 'onCheckColor', - cssName: 'on-check-color', - defaultValue: '#ffffff', - valueConverter: v => { - return String(v) - } + name: "onCheckColor", + cssName: "on-check-color", + defaultValue: "#ffffff", + valueConverter: v => { + return String(v); + } }); const tintColorProperty = new CssProperty({ - name: 'tintColor', - cssName: 'tint-color', - defaultValue: '#0075ff', - valueConverter: v => { - return String(v) - } + name: "tintColor", + cssName: "tint-color", + // defaultValue: "#0075ff", + valueConverter: v => { + return String(v); + } }); const onTintColorProperty = new CssProperty({ - name: 'onTintColor', - cssName: 'on-tint-color', - valueConverter: v => { - return String(v) - } + name: "onTintColor", + cssName: "on-tint-color", + valueConverter: v => { + return String(v); + } }); const fillColorProperty = new CssProperty({ - name: 'fillColor', - cssName: 'fill-color', - valueConverter: v => { - return String(v) - } + name: "fillColor", + cssName: "fill-color", + valueConverter: v => { + return String(v); + } }); const checkedProperty = new Property({ - name: 'checked', - defaultValue: false, - valueConverter: booleanConverter, - valueChanged: onCheckedPropertyChanged + name: "checked", + defaultValue: false, + valueConverter: booleanConverter, + valueChanged: onCheckedPropertyChanged }); export class CheckBox extends Button implements CheckBoxInterface { - _onCheckColor: string; - _checkBoxBackgroundColor: any; - _onTintColor: string; - _tintColor: string; - _onFillColor: string; - _fillColor: string; - private _iosCheckbox: BEMCheckBox; - private _delegate: BEMCheckBoxDelegateImpl; - private _lineWidth: number = 1; - private _hideBox: boolean; - private _boxType: number; - private _tint: string; - private _animationDuration: number; - private _onAnimationType: number; - private _offAnimationType: number; - public checked: boolean; - - constructor() { - super(); - // just create with any width/height as XML view width/height is undefined at this point - // we modify width/height later below in onLoaded - this._iosCheckbox = BEMCheckBox.alloc().initWithFrame(CGRectMake(0, 0, 21, 21)); - } - - - set fillColor(color: string) { - this._fillColor = color; - this._iosCheckbox.onFillColor = new Color(color).ios; - }; - - set onFillColor(color: string) { - this._onFillColor = color; - this._iosCheckbox.onFillColor = new Color(color).ios; - }; - - set tintColor(color: string) { - this._tintColor = color; - (this._iosCheckbox).tintColor = new Color(color).ios; - }; - - set onTintColor(color: string) { - this._onTintColor = color; - this._iosCheckbox.onTintColor = new Color(color).ios; - }; - - set checkBoxBackgroundColor(color: any) { - this._checkBoxBackgroundColor = color; - (this._iosCheckbox).offFillColor = new Color(color).ios; - }; - - - set onCheckColor(color: string) { - this._onCheckColor = color; - this._iosCheckbox.onCheckColor = new Color(color).ios; - } - - [checkedProperty.getDefault](): boolean { - return false; + _onCheckColor: string; + _checkBoxBackgroundColor: any; + _onTintColor: string; + _tintColor: string; + _onFillColor: string; + _fillColor: string; + private _iosCheckbox: BEMCheckBox; + private _delegate: BEMCheckBoxDelegateImpl; + private _lineWidth: number = 1; + private _hideBox: boolean; + private _boxType: number; + private _tint: string; + private _animationDuration: number; + private _onAnimationType: number; + private _offAnimationType: number; + public checked: boolean; + + constructor() { + super(); + // just create with any width/height as XML view width/height is undefined at this point + // we modify width/height later below in onLoaded + this._iosCheckbox = BEMCheckBox.alloc().initWithFrame( + CGRectMake(0, 0, 21, 21) + ); + } + + set fillColor(color: string) { + this._fillColor = color; + this._iosCheckbox.onFillColor = new Color(color).ios; + } + + set onFillColor(color: string) { + this._onFillColor = color; + this._iosCheckbox.onFillColor = new Color(color).ios; + } + + set tintColor(color: string) { + this._tintColor = color; + (this._iosCheckbox).tintColor = new Color(color).ios; + } + + set onTintColor(color: string) { + this._onTintColor = color; + this._iosCheckbox.onTintColor = new Color(color).ios; + } + + set checkBoxBackgroundColor(color: any) { + this._checkBoxBackgroundColor = color; + (this._iosCheckbox).offFillColor = new Color(color).ios; + } + + set onCheckColor(color: string) { + this._onCheckColor = color; + this._iosCheckbox.onCheckColor = new Color(color).ios; + } + + [checkedProperty.getDefault](): boolean { + return false; + } + + [checkedProperty.setNative](value: boolean) { + this._iosCheckbox.setOnAnimated(value, true); + } + + set checkedAnimated(value: boolean) { + this._iosCheckbox.setOnAnimated(value, true); + } + + set lineWidth(value: number) { + this._iosCheckbox.lineWidth = value; + this._lineWidth = value; + } + + set hideBox(value: boolean) { + this._iosCheckbox.hideBox = value; + this._hideBox = value; + } + + set boxType(value: number) { + let type = BEMBoxType.Circle; + if (value === 2) { + type = BEMBoxType.Square; } - - [checkedProperty.setNative](value: boolean) { - this._iosCheckbox.setOnAnimated(value, true); + if (this._iosCheckbox) this._iosCheckbox.boxType = type; + else this._boxType = value; + } + + set animationDuration(value: number) { + this._iosCheckbox.animationDuration = value; + this._animationDuration = value; + } + + set onAnimationType(value: number) { + if (this._iosCheckbox) + this._iosCheckbox.onAnimationType = this.getAnimationType(value); + else this._onAnimationType = value; + } + + set offAnimationType(value: number) { + this._iosCheckbox.offAnimationType = this.getAnimationType(value); + this._offAnimationType = value; + } + + get nativeiOSCheckBox() { + return this._iosCheckbox; + } + + public reload(value: boolean) { + this._iosCheckbox.reload(); + } + + public initNativeView() { + // allow label click to change the textbox + this.addEventListener("tap", args => { + const checkbox = args.object; + checkbox.checked = !checkbox.checked; + }); + + this._onAnimationType = 2; + this._offAnimationType = 2; + + this._delegate = BEMCheckBoxDelegateImpl.initWithOwner(new WeakRef(this)); + var fontSize; + + if (!this.style.fontSize) { + fontSize = 15; + } else { + fontSize = this.style.fontSize; } - - set checkedAnimated(value: boolean) { - this._iosCheckbox.setOnAnimated(value, true); + 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 + ); + this.style.paddingLeft = fontSize + (fontSize > 20 ? 10 : 5); + this.style.textAlignment = "left"; + + if (this._onCheckColor) { + this._iosCheckbox.onCheckColor = new Color(this._onCheckColor).ios; } - set lineWidth(value: number) { - this._iosCheckbox.lineWidth = value; - this._lineWidth = value; + if (this._onFillColor) { + this._iosCheckbox.onFillColor = new Color(this._onFillColor).ios; } - set hideBox(value: boolean) { - this._iosCheckbox.hideBox = value; - this._hideBox = value; + if (this._onTintColor) { + this._iosCheckbox.onTintColor = new Color(this._onTintColor).ios; } - set boxType(value: number) { - let type = BEMBoxType.Circle; - if (value === 2) { - type = BEMBoxType.Square; - } - if (this._iosCheckbox) - this._iosCheckbox.boxType = type; - else - this._boxType = value; + if (this._fillColor) { + this._iosCheckbox.onFillColor = new Color(this._fillColor).ios; } - - set animationDuration(value: number) { - this._iosCheckbox.animationDuration = value; - this._animationDuration = value; + if (this._tintColor) { + this._iosCheckbox.tintColor = new Color(this._tintColor).ios; } - set onAnimationType(value: number) { - if (this._iosCheckbox) - this._iosCheckbox.onAnimationType = this.getAnimationType(value); - else - this._onAnimationType = value; - } + this.nativeView.addSubview(this._iosCheckbox); - set offAnimationType(value: number) { - this._iosCheckbox.offAnimationType = this.getAnimationType(value); - this._offAnimationType = value; + if (typeof this._lineWidth !== "undefined") { + this.lineWidth = this._lineWidth; } - - get nativeiOSCheckBox() { - return this._iosCheckbox; + if (typeof this._hideBox !== "undefined") { + this.hideBox = this._hideBox; } - - public reload(value: boolean) { - this._iosCheckbox.reload(); + if (typeof this._boxType !== "undefined") { + this.boxType = this._boxType; } - - public initNativeView() { - - - //Allow label click to change the textbox - this.addEventListener("tap", (args) => { - const checkbox = args.object; - checkbox.checked = !checkbox.checked; - }); - - this._onAnimationType = 2; - this._offAnimationType = 2; - - this._delegate = BEMCheckBoxDelegateImpl.initWithOwner(new WeakRef(this)); - 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); - this.style.paddingLeft = fontSize + (fontSize > 20 ? 10 : 5); - this.style.textAlignment = "left"; - - if (this._onCheckColor) { - this._iosCheckbox.onCheckColor = new Color(this._onCheckColor).ios; - } - - if (this._onFillColor) { - this._iosCheckbox.onFillColor = new Color(this._onFillColor).ios; - } - - if (this._onTintColor) { - this._iosCheckbox.onTintColor = new Color(this._onTintColor).ios; - } - - if (this._fillColor) { - this._iosCheckbox.onFillColor = new Color(this._fillColor).ios; - } - - if (this._tintColor) { - this._iosCheckbox.tintColor = new Color(this._tintColor).ios; - } - - - this.nativeView.addSubview(this._iosCheckbox); - - if (typeof this._lineWidth !== 'undefined') { - this.lineWidth = this._lineWidth; - } - if (typeof this._hideBox !== 'undefined') { - this.hideBox = this._hideBox; - } - if (typeof this._boxType !== 'undefined') { - this.boxType = this._boxType; - } - - if (typeof this._animationDuration !== 'undefined') { - this.animationDuration = this._animationDuration; - } - if (typeof this._onAnimationType !== 'undefined') { - this.onAnimationType = this._onAnimationType; - } - if (typeof this._offAnimationType !== 'undefined') { - this.offAnimationType = this._offAnimationType; - } + if (typeof this._animationDuration !== "undefined") { + this.animationDuration = this._animationDuration; } - - public disposeNativeView() { - this._iosCheckbox.delegate = null; - this.removeEventListener("tap"); + if (typeof this._onAnimationType !== "undefined") { + this.onAnimationType = this._onAnimationType; } - - - public toggle() { - this.checked = !this.checked; + if (typeof this._offAnimationType !== "undefined") { + this.offAnimationType = this._offAnimationType; } - - private getAnimationType(value: number) { - switch (value) { - case 1: - return BEMAnimationType.Stroke; - case 2: - return BEMAnimationType.Fill; - case 3: - return BEMAnimationType.Bounce; - case 4: - return BEMAnimationType.Flat; - case 5: - return BEMAnimationType.Stroke; - case 6: - return BEMAnimationType.Fade; - } + } + + public disposeNativeView() { + this._iosCheckbox.delegate = null; + this.removeEventListener("tap"); + } + + public toggle() { + this.checked = !this.checked; + } + + private getAnimationType(value: number) { + switch (value) { + case 1: + return BEMAnimationType.Stroke; + case 2: + return BEMAnimationType.Fill; + case 3: + return BEMAnimationType.Bounce; + case 4: + return BEMAnimationType.Flat; + case 5: + return BEMAnimationType.Stroke; + case 6: + return BEMAnimationType.Fade; } + } - _onCheckedPropertyChanged(checkbox: CheckBox, oldValue, newValue) { - if (!this.nativeView) { - return - } - checkedProperty.nativeValueChange(this, newValue); + _onCheckedPropertyChanged(checkbox: CheckBox, oldValue, newValue) { + if (!this.nativeView) { + return; } + checkedProperty.nativeValueChange(this, newValue); + } } class BEMCheckBoxDelegateImpl extends NSObject implements BEMCheckBoxDelegate { - public static ObjCProtocols = [BEMCheckBoxDelegate]; - /*public static ObjCExposedMethods = { + 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) { - checkedProperty.nativeValueChange(owner, checkBox.on); - } + public didTapCheckBox(checkBox: BEMCheckBox): void { + let owner = this._owner.get(); + if (owner) { + checkedProperty.nativeValueChange(owner, checkBox.on); } + } } - function onCheckedPropertyChanged(checkbox: CheckBox, oldValue, newValue) { - checkbox._onCheckedPropertyChanged(checkbox, oldValue, newValue); + checkbox._onCheckedPropertyChanged(checkbox, oldValue, newValue); } checkedProperty.register(CheckBox); diff --git a/package.json b/package.json index 7063165..22ac2cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-checkbox", - "version": "2.1.4", + "version": "2.1.5", "description": "NativeScript plugin for checkbox widget.", "main": "checkbox", "typings": "index.d.ts",