mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Added text-field.ios implementation
This commit is contained in:
@ -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<View>();
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
declare var module, require;
|
||||
module.exports = require("ui/text-input/text-input");
|
||||
module.exports = require("ui/text-field/text-field");
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
8
ui/text-field/text-field.d.ts
vendored
8
ui/text-field/text-field.d.ts
vendored
@ -1 +1,7 @@
|
||||
|
||||
declare module "ui/text-field" {
|
||||
import view = require("ui/core/view");
|
||||
|
||||
export class TextField extends view.View {
|
||||
public text: string;
|
||||
}
|
||||
}
|
@ -1 +1,53 @@
|
||||
|
||||
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) {
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user