From f303a74570b3d17beea08e1781b75730b6917778 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Thu, 22 Dec 2016 16:50:45 +0200 Subject: [PATCH] Fixed Switch --- tns-core-modules/ui/switch/switch-common.ts | 12 +++++++++++- tns-core-modules/ui/switch/switch.android.ts | 14 ++++++-------- tns-core-modules/ui/switch/switch.ios.ts | 16 ++++++---------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/tns-core-modules/ui/switch/switch-common.ts b/tns-core-modules/ui/switch/switch-common.ts index 5f282702b..c4a340899 100644 --- a/tns-core-modules/ui/switch/switch-common.ts +++ b/tns-core-modules/ui/switch/switch-common.ts @@ -1 +1,11 @@ - \ No newline at end of file +import { Switch as SwitchDefinition } from "ui/switch"; +import { View, Property, booleanConverter } from "ui/core/view"; + +export * from "ui/core/view"; + +export class SwitchBase extends View implements SwitchDefinition { + public checked: boolean; +} + +export const checkedProperty = new Property({ name: "checked", defaultValue: false, valueConverter: booleanConverter }); +checkedProperty.register(SwitchBase); diff --git a/tns-core-modules/ui/switch/switch.android.ts b/tns-core-modules/ui/switch/switch.android.ts index 6979db1cc..16e25b529 100644 --- a/tns-core-modules/ui/switch/switch.android.ts +++ b/tns-core-modules/ui/switch/switch.android.ts @@ -1,7 +1,8 @@ -import { Switch as SwitchDefinition } from "ui/switch"; -import { View, Color, Property, colorProperty, backgroundColorProperty, backgroundInternalProperty, booleanConverter } from "ui/core/view"; +import { + SwitchBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, checkedProperty +} from "./switch-common"; -export * from "ui/core/view"; +export * from "./switch-common"; @Interfaces([android.widget.CompoundButton.OnCheckedChangeListener]) class CheckedChangeListener extends java.lang.Object implements android.widget.CompoundButton.OnCheckedChangeListener { @@ -18,7 +19,7 @@ class CheckedChangeListener extends java.lang.Object implements android.widget.C } } -export class Switch extends View implements SwitchDefinition { +export class Switch extends SwitchBase { private _android: android.widget.Switch; private listener: android.widget.CompoundButton.OnCheckedChangeListener; public checked: boolean; @@ -68,7 +69,4 @@ export class Switch extends View implements SwitchDefinition { set [backgroundInternalProperty.native](value: any) { // } -} - -export const checkedProperty = new Property({ name: "checked", defaultValue: false, valueConverter: booleanConverter }); -checkedProperty.register(Switch); \ No newline at end of file +} \ No newline at end of file diff --git a/tns-core-modules/ui/switch/switch.ios.ts b/tns-core-modules/ui/switch/switch.ios.ts index 1edcbdf06..6c15d7fea 100644 --- a/tns-core-modules/ui/switch/switch.ios.ts +++ b/tns-core-modules/ui/switch/switch.ios.ts @@ -1,7 +1,8 @@ -import { Switch as SwitchDefinition } from "ui/switch"; -import { View, layout, Color, Property, colorProperty, backgroundColorProperty, backgroundInternalProperty, booleanConverter } from "ui/core/view"; +import { + SwitchBase, layout, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, checkedProperty +} from "./switch-common"; -export * from "ui/core/view"; +export * from "./switch-common"; class SwitchChangeHandlerImpl extends NSObject { @@ -25,7 +26,7 @@ class SwitchChangeHandlerImpl extends NSObject { }; } -export class Switch extends View implements SwitchDefinition { +export class Switch extends SwitchBase { private _ios: UISwitch; private _handler: NSObject; @@ -37,8 +38,6 @@ export class Switch extends View implements SwitchDefinition { this._ios.addTargetActionForControlEvents(this._handler, "valueChanged", UIControlEvents.ValueChanged); } - public checked: boolean; - get ios(): UISwitch { return this._ios; } @@ -81,7 +80,4 @@ export class Switch extends View implements SwitchDefinition { set [backgroundInternalProperty.native](value: any) { // } -} - -export const checkedProperty = new Property({ name: "checked", defaultValue: false, valueConverter: booleanConverter }); -checkedProperty.register(Switch); \ No newline at end of file +} \ No newline at end of file