Files
NativeScript/tns-core-modules/ui/core/control-state-change.ios.ts
Panayot Cankov 1236f66f44 Add npm script that generates ios .d.ts-es from the tests app
Less than 30 erros left, let's hope it still works

Added lib.*.d.ts from typescript, removed lib and dom stuff, added by hand XHR, alert etc. .d.ts-es for polyfills

Roll back some changes involved in separating UIEvent for dom and ios

Test combined dts-es will now use lib, while internally we will not to avoid UIEvent conflict with dom stuff
2016-08-29 09:58:17 +03:00

66 lines
1.9 KiB
TypeScript

/* tslint:disable:no-unused-variable */
import definition = require("ui/core/control-state-change");
class ObserverClass extends NSObject {
observeValueForKeyPathOfObjectChangeContext(path: string, obj: Object, change: NSDictionary<any, any>, context: any) {
if (path === "selected") {
this["_owner"]._onSelectedChanged();
} else if (path === "enabled") {
this["_owner"]._onEnabledChanged();
} else if (path === "highlighted") {
this["_owner"]._onHighlightedChanged();
}
}
}
export class ControlStateChangeListener implements definition.ControlStateChangeListener {
private _observer: NSObject;
private _states: string[];
private _control: UIControl;
private _observing: boolean = false;
private _callback: (state: string) => void;
constructor(control: UIControl, callback: (state: string) => void) {
this._observer = ObserverClass.alloc();
this._observer["_owner"] = this;
this._control = control;
this._callback = callback;
}
public start() {
if (!this._observing) {
this._control.addObserverForKeyPathOptionsContext(this._observer, "highlighted", NSKeyValueObservingOptions.New, null);
this._observing = true;
this._updateState();
}
}
public stop() {
if (this._observing) {
this._observing = false;
this._control.removeObserverForKeyPath(this._observer, "highlighted");
}
}
private _onEnabledChanged() {
this._updateState();
}
private _onSelectedChanged() {
this._updateState();
}
private _onHighlightedChanged() {
this._updateState();
}
private _updateState() {
var state = "normal";
if (this._control.highlighted) {
state = "highlighted";
}
this._callback(state);
}
}