Files
NativeScript/tns-core-modules/ui/core/control-state-change.ios.ts
Panayot Cankov c1aeeb51a7 Inital by-type split
Split type.class from CssTypeSelector to CssCompositeSelector, probably support type#id.class selectors

Apply review comments, refactor css-selectors internally

Applied refactoring, all tests pass, button does not notify changes

Add tests for the css selectors parser.

Added tests for css-selectors

Added basic implementation of mayMatch and changeMap for css match state

Implemented TKUnit.assertDeepEqual to check key and key/values in Map and Set

Watch for property and pseudoClass changes

Add one child group test

Add typings for animations

Added mechanism to enable/disable listeners for pseudo classes

Count listeners instead of checking handlers, reverse subscription and unsubscription
2016-07-18 17:24:09 +03:00

69 lines
2.0 KiB
TypeScript

/* tslint:disable:no-unused-variable */
import definition = require("ui/core/control-state-change");
var ObserverClass = NSObject.extend(
{
observeValueForKeyPathOfObjectChangeContext: function (path: string, obj: Object, change: NSDictionary, 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.NSKeyValueObservingOptionNew, 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);
}
}