diff --git a/ui/core/view.ts b/ui/core/view.ts index 1e47acfcb..afd6467f1 100644 --- a/ui/core/view.ts +++ b/ui/core/view.ts @@ -4,7 +4,7 @@ import application = require("application"); export class View extends proxy.ProxyObject { private _parent: Panel; - public onInitialized(content: android.content.Context) { + public onInitialized(context: android.content.Context) { // TODO: This is used by Android, rethink this routine } @@ -12,6 +12,7 @@ export class View extends proxy.ProxyObject { // TODO: Temporary if (application.ios && this.ios) { native.addSubview(this.ios); + this.ios.sizeToFit(); } else if (application.android && this.android) { native.addView(this.android); } @@ -62,6 +63,16 @@ export class Panel extends View { this._children = new Array(); } + public onInitialized(context: android.content.Context) { + super.onInitialized(context); + + // delegate the initialized event to the children + var i; + for (i = 0; i < this._children.length; i++) { + this._children[i].onInitialized(context); + } + } + public addChild(child: View) { // Validate child is not parented if (child.parent) { @@ -96,4 +107,8 @@ export class Panel extends View { this._children.splice(index, 1); child.onRemovedFromParent(); } +} + +export class StackPanel extends Panel { + } \ No newline at end of file diff --git a/ui/frame/frame.android.ts b/ui/frame/frame.android.ts index 850f1624f..9a23ea899 100644 --- a/ui/frame/frame.android.ts +++ b/ui/frame/frame.android.ts @@ -5,7 +5,7 @@ import application = require("application"); export class Frame extends frameCommon.Frame { public navigateCore(context: any) { - if (this.backStack.length === 0) { + if (!this.currentPage) { // When navigating for the very first time we do not want to start an activity // TODO: Revisit/polish this behavior return; diff --git a/ui/pages/page.android.ts b/ui/pages/page.android.ts index 9f3bdaf90..8faa8fdf6 100644 --- a/ui/pages/page.android.ts +++ b/ui/pages/page.android.ts @@ -41,8 +41,8 @@ class AndroidPage implements definition.AndroidPage { } public getActivityExtends(): any { - if (!this._body) { - this.rebuildBody(); + if (!this._activityExtends) { + this.rebuildExtends(); } return this._activityExtends; @@ -53,26 +53,29 @@ class AndroidPage implements definition.AndroidPage { this._activityExtends = null; } - private rebuildBody() { - var that = this; - this._body = { - onCreate: function () { - that._activity = this; - this.super.onCreate(null); + private rebuildExtends() { + // we may have a body set externally + if (!this._body) { + var that = this; + this._body = { + onCreate: function () { + that._activity = this; + this.super.onCreate(null); - var view = that._ownerPage.contentView; - if (view) { - // TODO: Notify the entire visual tree for being initialized - view.onInitialized(that._activity); - that._activity.setContentView(view.android); + var view = that._ownerPage.contentView; + if (view) { + // TODO: Notify the entire visual tree for being initialized + view.onInitialized(that._activity); + that._activity.setContentView(view.android); + } } } - } - if (this._ownerPage.onLoaded) { - this._body.onStart = function () { - this.super.onStart(); - that._ownerPage.onLoaded(); + if (this._ownerPage.onLoaded) { + this._body.onStart = function () { + this.super.onStart(); + that._ownerPage.onLoaded(); + } } } diff --git a/ui/text-field/index.ts b/ui/text-field/index.ts index 5fce8f31b..0eb59f929 100644 --- a/ui/text-field/index.ts +++ b/ui/text-field/index.ts @@ -1,2 +1,2 @@ declare var module, require; -module.exports = require("ui/text-input/text-input"); \ No newline at end of file +module.exports = require("ui/text-field/text-field"); \ No newline at end of file diff --git a/ui/text-field/text-field.android.ts b/ui/text-field/text-field.android.ts index 92c307bcb..e423bf149 100644 --- a/ui/text-field/text-field.android.ts +++ b/ui/text-field/text-field.android.ts @@ -1,16 +1,58 @@ import observable = require("ui/core/observable"); import view = require("ui/core/view"); import application = require("application"); +import definition = require("ui/text-field"); -export class TextInput extends view.View { +var TEXT = "text"; +// this is the name of the property to store text locally until attached to a valid Context +var TEXTPRIVATE = "_text"; + +export class TextField extends view.View implements definition.TextField { private _android: android.widget.EditText; - private static textProperty = "text"; constructor() { super(); + } - var context = application.android.currentContext; + public onInitialized(context: android.content.Context) { + if (!this._android) { + // TODO: We need to decide whether we will support context switching and if yes - to implement it. + this.createUI(context); + } + } + + get android(): android.widget.EditText { + return this._android; + } + + get text(): string { + if (!this._android) { + return this[TEXTPRIVATE]; + } + return this._android.getText().toString(); + } + set text(value: string) { + this.setProperty(TEXT, value); + } + + public setNativeProperty(data: observable.PropertyChangeData) { + // TODO: Will this be a gigantic if-else switch? + if (data.propertyName === TEXT) { + if (this._android) { + this._android.setText(data.value, android.widget.TextView.BufferType.EDITABLE); + } else { + this[TEXTPRIVATE] = data.value; + } + } else if (true) { + } + } + + private createUI(context: android.content.Context) { this._android = new android.widget.EditText(context); + if (this[TEXTPRIVATE]) { + this._android.setText(this[TEXTPRIVATE]); + delete this[TEXTPRIVATE]; + } // TODO: This code is same for Label, extract base class or derive from Label var that = this; @@ -20,28 +62,9 @@ export class TextInput extends view.View { onTextChanged: function (text: string, start: number, before: number, count: number) { }, afterTextChanged: function (editable: android.text.IEditable) { - that.updateTwoWayBinding(TextInput.textProperty, editable.toString()); + that.updateTwoWayBinding(TEXT, editable.toString()); } }); this._android.addTextChangedListener(textWatcher); } - - get android(): android.widget.EditText { - return this._android; - } - - get text(): string { - return this._android.getText().toString(); - } - set text(value: string) { - this.setProperty(TextInput.textProperty, value); - } - - public setNativeProperty(data: observable.PropertyChangeData) { - // TODO: Will this be a gigantic if-else switch? - if (data.propertyName === TextInput.textProperty) { - this._android.setText(data.value, android.widget.TextView.BufferType.EDITABLE); - } else if (true) { - } - } } \ No newline at end of file diff --git a/ui/text-field/text-field.d.ts b/ui/text-field/text-field.d.ts index 19a76f130..623788042 100644 --- a/ui/text-field/text-field.d.ts +++ b/ui/text-field/text-field.d.ts @@ -1 +1,7 @@ - \ No newline at end of file +declare module "ui/text-field" { + import view = require("ui/core/view"); + + export class TextField extends view.View { + public text: string; + } +} \ No newline at end of file diff --git a/ui/text-field/text-field.ios.ts b/ui/text-field/text-field.ios.ts index 19a76f130..e6246809c 100644 --- a/ui/text-field/text-field.ios.ts +++ b/ui/text-field/text-field.ios.ts @@ -1 +1,53 @@ - \ No newline at end of file +import observable = require("ui/core/observable"); +import view = require("ui/core/view"); +import application = require("application"); +import definition = require("ui/text-field"); + +var TEXT = "text"; + +export class TextField extends view.View implements definition.TextField { + private _ios: UIKit.UITextField; + private _delegate: any; + + constructor() { + super(); + + this._ios = new UIKit.UITextField(); + + var that = this; + var protocolImplementation = Foundation.NSObject.extends({}, {}).implements({ + protocol: "UITextFieldDelegate", + implementation: { + textFieldDidEndEditing: function (field: UIKit.UITextField) { + that.updateTwoWayBinding(TEXT, field.text); + console.log("TextField end edit"); + } + } + }); + + this._delegate = new protocolImplementation(); + this._ios.delegate = this._delegate; + + var frame = CoreGraphics.CGRectMake(100, 100, 50, 30); + } + + get ios(): UIKit.UITextField { + return this._ios; + } + + get text(): string { + return this.ios.text; + } + set text(value: string) { + this.setProperty(TEXT, value); + } + + public setNativeProperty(data: observable.PropertyChangeData) { + // TODO: Will this be a gigantic if-else switch? + if (data.propertyName === TEXT) { + this._ios.text = data.value; + this._ios.sizeToFit(); + } else if (true) { + } + } +} \ No newline at end of file