Initial prototype of Frame + Page + Navigation.

This commit is contained in:
atanasovg
2014-06-12 17:37:55 +03:00
parent ef7c3ce677
commit 2c4781db01
26 changed files with 520 additions and 80 deletions

View File

@@ -37,6 +37,11 @@ export class Bindable extends observable.Observable {
}
}
public setPropertyCore(data: observable.PropertyChangeData) {
super.setPropertyCore(data);
this.updateTwoWayBinding(data.propertyName, data.value);
}
public getBinding(propertyName: string) {
return this._bindings[propertyName];
}

View File

@@ -1 +0,0 @@


View File

@@ -31,6 +31,13 @@ export class Observable {
private _trackChanging = false;
constructor(body?: any) {
if (body) {
for (var key in body) {
// TODO: Is this correct
this[key] = body[key];
}
}
this.on = this.addEventListener = this.addObserver;
this.off = this.removeEventListener = this.removeObserver;
}

View File

@@ -4,6 +4,7 @@ import bindable = require("ui/core/bindable");
export class ProxyObject extends bindable.Bindable {
public setPropertyCore(data: observable.PropertyChangeData) {
this.setNativeProperty(data);
this.updateTwoWayBinding(data.propertyName, data.value);
}
public setNativeProperty(data: observable.PropertyChangeData) {

View File

@@ -1,11 +0,0 @@
import proxy = require("ui/core/proxy");
export class View extends proxy.ProxyObject {
public addToParent(parent: android.view.ViewGroup) {
var nativeInstance: android.view.View = this["android"];
if (nativeInstance) {
// TODO: Check for existing parent
parent.addView(nativeInstance);
}
}
}

7
ui/core/view.d.ts vendored
View File

@@ -1,7 +0,0 @@
import proxy = require("ui/core/proxy");
export declare class View extends proxy.ProxyObject {
public addToParent(parent: any);
android: any;
ios: any;
}

View File

@@ -1,11 +0,0 @@
import proxy = require("ui/core/proxy");
export class View extends proxy.ProxyObject {
public addToParent(parent: UIKit.UIView) {
var nativeInstance: UIKit.UIView = this["ios"];
if (nativeInstance) {
// TODO: Check for existing parent
parent.addSubview(nativeInstance);
}
}
}

99
ui/core/view.ts Normal file
View File

@@ -0,0 +1,99 @@
import proxy = require("ui/core/proxy");
import application = require("application");
export class View extends proxy.ProxyObject {
private _parent: Panel;
public onInitialized(content: android.content.Context) {
// TODO: This is used by Android, rethink this routine
}
public addToParent(native: any) {
// TODO: Temporary
if (application.ios && this.ios) {
native.addSubview(this.ios);
} else if (application.android && this.android) {
native.addView(this.android);
}
}
/**
* Gets the Panel instance that parents this view. This property is read-only.
*/
get parent(): Panel {
return this._parent;
}
/**
* Gets the android-specific native instance that lies behind this view. Will be available if running on an Android platform.
*/
get android(): any {
return undefined;
}
/**
* Gets the ios-specific native instance that lies behind this view. Will be available if running on an Android platform.
*/
get ios(): any {
return undefined;
}
// TODO: Should these be public?
public onAddedToParent(parent: Panel) {
this._parent = parent;
// TODO: Attach to parent - e.g. update data context, bindings, styling, etc.
}
public onRemovedFromParent() {
this._parent = null;
// TODO: Detach from parent.
}
}
/**
* The Panel class represents an extended View which can have other views as children.
*/
export class Panel extends View {
private _children: Array<View>;
constructor() {
super();
this._children = new Array<View>();
}
public addChild(child: View) {
// Validate child is not parented
if (child.parent) {
var message;
if (child.parent === this) {
message = "View already added to this panel.";
} else {
message = "View is already a child of another panel.";
}
throw new Error(message);
}
this._children.push(child);
child.onAddedToParent(this);
}
public removeChild(child: View) {
if (!child) {
return;
}
if (child.parent !== this) {
throw new Error("View is not parented by this panel.");
}
var index = this._children.indexOf(child);
if (index < 0) {
throw new Error("View not found in children collection.");
}
this._children.splice(index, 1);
child.onRemovedFromParent();
}
}