mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import observable = require("ui/core/observable");
|
|
import view = require("ui/core/view");
|
|
import application = require("application");
|
|
|
|
export class Label extends view.View {
|
|
private static textProperty = "text";
|
|
private _ios: UIKit.UILabel;
|
|
private changedHandler: Foundation.NSObject;
|
|
|
|
constructor() {
|
|
super();
|
|
|
|
this._ios = new UIKit.UILabel();
|
|
|
|
var that = this;
|
|
var extendsBody = Foundation.NSObject.extends(
|
|
{
|
|
observeValueForKeyPathOfObjectChangeContext: function (path: string, sender: Foundation.NSObject, change: Foundation.NSDictionary, context) {
|
|
that.updateTwoWayBinding(Label.textProperty, change.objectForKey("new"));
|
|
}
|
|
}, {});
|
|
|
|
this.changedHandler = new extendsBody();
|
|
this._ios.addObserverForKeyPathOptionsContext(this.changedHandler, "text", Foundation.NSKeyValueObservingOptions.NSKeyValueObservingOptionNew, null);
|
|
}
|
|
|
|
get ios(): UIKit.UILabel {
|
|
return this._ios;
|
|
}
|
|
|
|
get text(): string {
|
|
return this._ios.text;
|
|
}
|
|
set text(value: string) {
|
|
this.setProperty(Label.textProperty, value);
|
|
}
|
|
|
|
public setNativeProperty(data: observable.PropertyChangeData) {
|
|
// TODO: Will this be a gigantic if-else switch?
|
|
if (data.propertyName === Label.textProperty) {
|
|
this._ios.text = data.value;
|
|
this._ios.sizeToFit();
|
|
} else if (true) {
|
|
}
|
|
}
|
|
}
|