mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Initial prototype of Frame + Page + Navigation.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
7
ui/core/view.d.ts
vendored
@@ -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;
|
||||
}
|
||||
@@ -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
99
ui/core/view.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user