mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
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);
|
|
|
|
var that = this;
|
|
this._android.setOnCheckedChangeListener(new android.widget.CompoundButton.OnCheckedChangeListener({
|
|
onCheckedChanged: function (sender, isChecked) {
|
|
that.updateTwoWayBinding(Switch.checkedProperty, sender.isChecked());
|
|
that.setProperty(Switch.checkedProperty, sender.isChecked());
|
|
}
|
|
}));
|
|
}
|
|
|
|
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) {
|
|
//
|
|
}
|
|
}
|
|
}
|