mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Switch added
This commit is contained in:
@ -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
2
ui/switch/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
declare var module, require;
|
||||||
|
module.exports = require("ui/switch/switch");
|
32
ui/switch/switch.android.ts
Normal file
32
ui/switch/switch.android.ts
Normal 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
5
ui/switch/switch.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
declare module "ui/switch" {
|
||||||
|
class Switch {
|
||||||
|
checked: boolean;
|
||||||
|
}
|
||||||
|
}
|
43
ui/switch/switch.ios.ts
Normal file
43
ui/switch/switch.ios.ts
Normal 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) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user