mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00

- Remove unknown properties in object literals. - Don't use module-level `delete` statements.
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import common = require("ui/switch/switch-common");
|
|
import dependencyObservable = require("ui/core/dependency-observable");
|
|
import proxy = require("ui/core/proxy");
|
|
|
|
function onCheckedPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
|
var swtch = <Switch>data.object;
|
|
if (!swtch.android) {
|
|
return;
|
|
}
|
|
|
|
swtch.android.setChecked(data.newValue);
|
|
}
|
|
|
|
// register the setNativeValue callbacks
|
|
(<proxy.PropertyMetadata>common.Switch.checkedProperty.metadata).onSetNativeValue = onCheckedPropertyChanged;
|
|
|
|
global.moduleMerge(common, exports);
|
|
|
|
interface Owned {
|
|
owner: any;
|
|
}
|
|
|
|
export class Switch extends common.Switch {
|
|
private _android: android.widget.Switch;
|
|
|
|
get android(): android.widget.Switch {
|
|
return this._android;
|
|
}
|
|
|
|
public _createUI() {
|
|
this._android = new android.widget.Switch(this._context);
|
|
|
|
var that = new WeakRef(this);
|
|
|
|
this._android.setOnCheckedChangeListener(new android.widget.CompoundButton.OnCheckedChangeListener(<Owned & android.widget.CompoundButton.IOnCheckedChangeListener>{
|
|
get owner() {
|
|
return that.get();
|
|
},
|
|
|
|
onCheckedChanged: function (sender, isChecked) {
|
|
if (this.owner) {
|
|
this.owner._onPropertyChangedFromNative(common.Switch.checkedProperty, isChecked);
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
}
|