diff --git a/BCL.csproj b/BCL.csproj index d422f85f1..6c630c1b5 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -283,6 +283,14 @@ + + + + switch.d.ts + + + switch.d.ts + diff --git a/ui/switch/index.ts b/ui/switch/index.ts new file mode 100644 index 000000000..cb0dfbfea --- /dev/null +++ b/ui/switch/index.ts @@ -0,0 +1,2 @@ +declare var module, require; +module.exports = require("ui/switch/switch"); \ No newline at end of file diff --git a/ui/switch/switch.android.ts b/ui/switch/switch.android.ts new file mode 100644 index 000000000..c6b329bed --- /dev/null +++ b/ui/switch/switch.android.ts @@ -0,0 +1,32 @@ +import observable = require("ui/core/observable"); +import view = require("ui/core/view"); +import application = require("application"); + +export class Switch extends view.View { + private static checkedProperty = "checked"; + private _android: android.widget.Switch; + + constructor() { + super(); + this._android = new android.widget.Switch(application.android.currentContext); + } + + get android(): android.widget.Switch { + return this._android; + } + + get checked(): boolean { + return this.android.isChecked(); + } + set checked(value: boolean) { + this.setProperty(Switch.checkedProperty, value); + } + + public setNativeProperty(data: observable.PropertyChangeData) { + if (data.propertyName === Switch.checkedProperty) { + this.android.setChecked(data.value); + } else if (true) { + // + } + } +} \ No newline at end of file diff --git a/ui/switch/switch.d.ts b/ui/switch/switch.d.ts new file mode 100644 index 000000000..3086b1b9c --- /dev/null +++ b/ui/switch/switch.d.ts @@ -0,0 +1,5 @@ +declare module "ui/switch" { + class Switch { + checked: boolean; + } +} \ No newline at end of file diff --git a/ui/switch/switch.ios.ts b/ui/switch/switch.ios.ts new file mode 100644 index 000000000..3cd218bd4 --- /dev/null +++ b/ui/switch/switch.ios.ts @@ -0,0 +1,43 @@ +import observable = require("ui/core/observable"); +import view = require("ui/core/view"); +import application = require("application"); + +export class Switch extends view.View { + private static checkedProperty = "checked"; + private _ios: UIKit.UISwitch; + private _handler: Foundation.NSObject; + + constructor() { + super(); + this._ios = new UIKit.UISwitch(); + + var that = this; + var target = Foundation.NSObject.extends({ + valueChange: (sender: UIKit.UISwitch) => { + that.updateTwoWayBinding(Switch.checkedProperty, sender.on); + that.setProperty(Switch.checkedProperty, sender.on); + } + }, { exposedMethods: { "valueChange": "v@:@" } }); + this._handler = new target(); + this._ios.addTargetActionForControlEvents(this._handler, "valueChange", UIKit.UIControlEvents.UIControlEventValueChanged); + } + + get ios(): UIKit.UISwitch { + return this._ios; + } + + get checked(): boolean { + return this.ios.on + } + set checked(value: boolean) { + this.setProperty(Switch.checkedProperty, value); + } + + public setNativeProperty(data: observable.PropertyChangeData) { + if (data.propertyName === Switch.checkedProperty) { + this.ios.on = data.value; + } else if (true) { + // + } + } +} \ No newline at end of file