Switch added

This commit is contained in:
Vladimir Enchev
2014-06-16 09:51:49 +03:00
parent 5b5f5bad85
commit 173d352a5d
5 changed files with 90 additions and 0 deletions

View File

@ -283,6 +283,14 @@
<TypeScriptCompile Include="ui\slider\slider.android.ts" /> <TypeScriptCompile Include="ui\slider\slider.android.ts" />
<TypeScriptCompile Include="ui\slider\slider.d.ts" /> <TypeScriptCompile Include="ui\slider\slider.d.ts" />
<TypeScriptCompile Include="ui\slider\slider.ios.ts" /> <TypeScriptCompile Include="ui\slider\slider.ios.ts" />
<TypeScriptCompile Include="ui\switch\switch.d.ts" />
<TypeScriptCompile Include="ui\switch\index.ts" />
<TypeScriptCompile Include="ui\switch\switch.android.ts">
<DependentUpon>switch.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="ui\switch\switch.ios.ts">
<DependentUpon>switch.d.ts</DependentUpon>
</TypeScriptCompile>
<Content Include="_references.ts" /> <Content Include="_references.ts" />
<Content Include="image-source\Readme.md" /> <Content Include="image-source\Readme.md" />
<Content Include="http\Readme.md" /> <Content Include="http\Readme.md" />

2
ui/switch/index.ts Normal file
View File

@ -0,0 +1,2 @@
declare var module, require;
module.exports = require("ui/switch/switch");

View File

@ -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) {
//
}
}
}

5
ui/switch/switch.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
declare module "ui/switch" {
class Switch {
checked: boolean;
}
}

43
ui/switch/switch.ios.ts Normal file
View File

@ -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) {
//
}
}
}