mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
/* tslint:disable:no-empty */
|
||||
import { ControlStateChangeListener as ControlStateChangeListenerDefinition } from "./control-state-change";
|
||||
|
||||
export class ControlStateChangeListener
|
||||
implements ControlStateChangeListenerDefinition {
|
||||
constructor(
|
||||
control: any /* UIControl */,
|
||||
callback: (state: string) => void
|
||||
) {
|
||||
console.log(
|
||||
"ControlStateChangeListener is intended for IOS usage only."
|
||||
);
|
||||
}
|
||||
public start() {}
|
||||
public stop() {}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/**
|
||||
* An utility class used for supporting styling infrastructure.
|
||||
* WARNING: This class is intended for IOS only.
|
||||
*/
|
||||
export class ControlStateChangeListener {
|
||||
/**
|
||||
* Initializes an instance of ControlStateChangeListener class.
|
||||
* @param control An instance of the UIControl which state will be watched.
|
||||
* @param callback A callback called when a visual state of the UIControl is changed.
|
||||
*/
|
||||
constructor(
|
||||
control: any /* UIControl */,
|
||||
callback: (state: string) => void
|
||||
);
|
||||
|
||||
start();
|
||||
stop();
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
import { ControlStateChangeListener as ControlStateChangeListenerDefinition } from ".";
|
||||
|
||||
class ObserverClass extends NSObject {
|
||||
// NOTE: Refactor this - use Typescript property instead of strings....
|
||||
observeValueForKeyPathOfObjectChangeContext(path: string) {
|
||||
if (path === "selected") {
|
||||
this["_owner"]._onSelectedChanged();
|
||||
} else if (path === "enabled") {
|
||||
this["_owner"]._onEnabledChanged();
|
||||
} else if (path === "highlighted") {
|
||||
this["_owner"]._onHighlightedChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ControlStateChangeListener
|
||||
implements ControlStateChangeListenerDefinition {
|
||||
private _observer: NSObject;
|
||||
private _control: UIControl;
|
||||
private _observing: boolean = false;
|
||||
|
||||
private _callback: (state: string) => void;
|
||||
|
||||
constructor(control: UIControl, callback: (state: string) => void) {
|
||||
this._observer = ObserverClass.alloc().init();
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
private _onEnabledChanged() {
|
||||
this._updateState();
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
private _onSelectedChanged() {
|
||||
this._updateState();
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
private _onHighlightedChanged() {
|
||||
this._updateState();
|
||||
}
|
||||
|
||||
private _updateState() {
|
||||
let state = "normal";
|
||||
if (this._control.highlighted) {
|
||||
state = "highlighted";
|
||||
}
|
||||
this._callback(state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
/* tslint:disable:no-empty */
|
||||
import { ControlStateChangeListener as ControlStateChangeListenerDefinition } from '.';
|
||||
|
||||
export class ControlStateChangeListener implements ControlStateChangeListenerDefinition {
|
||||
constructor(control: any /* UIControl */, callback: (state: string) => void) {
|
||||
console.log('ControlStateChangeListener is intended for IOS usage only.');
|
||||
}
|
||||
public start() {}
|
||||
public stop() {}
|
||||
}
|
||||
15
nativescript-core/ui/core/control-state-change/index.d.ts
vendored
Normal file
15
nativescript-core/ui/core/control-state-change/index.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* An utility class used for supporting styling infrastructure.
|
||||
* WARNING: This class is intended for IOS only.
|
||||
*/
|
||||
export class ControlStateChangeListener {
|
||||
/**
|
||||
* Initializes an instance of ControlStateChangeListener class.
|
||||
* @param control An instance of the UIControl which state will be watched.
|
||||
* @param callback A callback called when a visual state of the UIControl is changed.
|
||||
*/
|
||||
constructor(control: any /* UIControl */, callback: (state: string) => void);
|
||||
|
||||
start();
|
||||
stop();
|
||||
}
|
||||
68
nativescript-core/ui/core/control-state-change/index.ios.ts
Normal file
68
nativescript-core/ui/core/control-state-change/index.ios.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
import { ControlStateChangeListener as ControlStateChangeListenerDefinition } from '.';
|
||||
|
||||
class ObserverClass extends NSObject {
|
||||
// NOTE: Refactor this - use Typescript property instead of strings....
|
||||
observeValueForKeyPathOfObjectChangeContext(path: string) {
|
||||
if (path === 'selected') {
|
||||
this['_owner']._onSelectedChanged();
|
||||
} else if (path === 'enabled') {
|
||||
this['_owner']._onEnabledChanged();
|
||||
} else if (path === 'highlighted') {
|
||||
this['_owner']._onHighlightedChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ControlStateChangeListener implements ControlStateChangeListenerDefinition {
|
||||
private _observer: NSObject;
|
||||
private _control: UIControl;
|
||||
private _observing: boolean = false;
|
||||
|
||||
private _callback: (state: string) => void;
|
||||
|
||||
constructor(control: UIControl, callback: (state: string) => void) {
|
||||
this._observer = ObserverClass.alloc().init();
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
private _onEnabledChanged() {
|
||||
this._updateState();
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
private _onSelectedChanged() {
|
||||
this._updateState();
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
private _onHighlightedChanged() {
|
||||
this._updateState();
|
||||
}
|
||||
|
||||
private _updateState() {
|
||||
let state = 'normal';
|
||||
if (this._control.highlighted) {
|
||||
state = 'highlighted';
|
||||
}
|
||||
this._callback(state);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "control-state-change",
|
||||
"main": "control-state-change",
|
||||
"types": "control-state-change.d.ts"
|
||||
}
|
||||
Reference in New Issue
Block a user