forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.ios.ts
More file actions
53 lines (41 loc) · 1.61 KB
/
switch.ios.ts
File metadata and controls
53 lines (41 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
swtch.ios.on = data.newValue;
}
// register the setNativeValue callbacks
(<proxy.PropertyMetadata>common.Switch.checkedProperty.metadata).onSetNativeValue = onCheckedPropertyChanged;
// merge the exports of the common file with the exports of this file
declare var exports;
require("utils/module-merge").merge(common, exports);
class SwitchChangeHandlerImpl extends NSObject {
static new(): SwitchChangeHandlerImpl {
return <SwitchChangeHandlerImpl>super.new();
}
private _owner: Switch;
public initWithOwner(owner: Switch): SwitchChangeHandlerImpl {
this._owner = owner;
return this;
}
public valueChanged(sender: UISwitch) {
this._owner._onPropertyChangedFromNative(common.Switch.checkedProperty, sender.on);
}
public static ObjCExposedMethods = {
'valueChanged': { returns: interop.types.void, params: [UISwitch] }
};
}
export class Switch extends common.Switch {
private _ios: UISwitch;
private _handler: NSObject;
constructor() {
super();
this._ios = new UISwitch();
this._handler = SwitchChangeHandlerImpl.new().initWithOwner(this);
this._ios.addTargetActionForControlEvents(this._handler, "valueChanged", UIControlEvents.UIControlEventValueChanged);
}
get ios(): UISwitch {
return this._ios;
}
}