From 1fdb2e99d2d341bef80ac430aaaba6eb10ff10c9 Mon Sep 17 00:00:00 2001 From: atanasovg Date: Fri, 6 Jun 2014 18:46:02 +0300 Subject: [PATCH] Handled text change notifications for iOS label. --- ui/core/observable.ts | 4 ++++ ui/label/label.ios.ts | 24 ++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ui/core/observable.ts b/ui/core/observable.ts index 485d60579..2418f9c64 100644 --- a/ui/core/observable.ts +++ b/ui/core/observable.ts @@ -22,6 +22,10 @@ export class Observable { // true to track the Changing phase, false otherwise private _trackChanging = false; + constructor(body?: any) { + // TODO: Not implemented + } + public addObserver(eventName: string, callback: (data: ChangeData) => void) { this.verifyCallback(callback); var list = this.getEventList(eventName, true); diff --git a/ui/label/label.ios.ts b/ui/label/label.ios.ts index a9e998eb2..8b242082d 100644 --- a/ui/label/label.ios.ts +++ b/ui/label/label.ios.ts @@ -12,16 +12,16 @@ export class Label extends view.View { this._ios = new UIKit.UILabel(); - //var extendsBody = Foundation.NSObject.extends( - // { - // onTextChanged: function (path, sender, change, context) { - // } - // }, - // { - // exposedMethods: { "tick:": "v@:@" } - // }); + 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.changedHandler = new extendsBody(); + this._ios.addObserverForKeyPathOptionsContext(this.changedHandler, "text", Foundation.NSKeyValueObservingOptions.NSKeyValueObservingOptionNew, null); } get ios(): UIKit.UILabel { @@ -39,12 +39,8 @@ export class Label extends view.View { // 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) { } } - - public addToParent(parent: UIKit.UIView) { - super.addToParent(parent); - this._ios.sizeToFit(); - } } \ No newline at end of file