Skip to content

Commit 1fdb2e9

Browse files
committed
Handled text change notifications for iOS label.
1 parent 9066166 commit 1fdb2e9

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

ui/core/observable.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export class Observable {
2222
// true to track the Changing phase, false otherwise
2323
private _trackChanging = false;
2424

25+
constructor(body?: any) {
26+
// TODO: Not implemented
27+
}
28+
2529
public addObserver(eventName: string, callback: (data: ChangeData) => void) {
2630
this.verifyCallback(callback);
2731
var list = this.getEventList(eventName, true);

ui/label/label.ios.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ export class Label extends view.View {
1212

1313
this._ios = new UIKit.UILabel();
1414

15-
//var extendsBody = Foundation.NSObject.extends(
16-
// {
17-
// onTextChanged: function (path, sender, change, context) {
18-
// }
19-
// },
20-
// {
21-
// exposedMethods: { "tick:": "v@:@" }
22-
// });
23-
24-
//this.changedHandler = new extendsBody();
15+
var that = this;
16+
var extendsBody = Foundation.NSObject.extends(
17+
{
18+
observeValueForKeyPathOfObjectChangeContext: function (path: string, sender: Foundation.NSObject, change: Foundation.NSDictionary, context) {
19+
that.updateTwoWayBinding(Label.textProperty, change.objectForKey("new"));
20+
}
21+
}, {});
22+
23+
this.changedHandler = new extendsBody();
24+
this._ios.addObserverForKeyPathOptionsContext(this.changedHandler, "text", Foundation.NSKeyValueObservingOptions.NSKeyValueObservingOptionNew, null);
2525
}
2626

2727
get ios(): UIKit.UILabel {
@@ -39,12 +39,8 @@ export class Label extends view.View {
3939
// TODO: Will this be a gigantic if-else switch?
4040
if (data.propertyName === Label.textProperty) {
4141
this._ios.text = data.value;
42+
this._ios.sizeToFit();
4243
} else if (true) {
4344
}
4445
}
45-
46-
public addToParent(parent: UIKit.UIView) {
47-
super.addToParent(parent);
48-
this._ios.sizeToFit();
49-
}
5046
}

0 commit comments

Comments
 (0)