Skip to content

Commit 2c4781d

Browse files
committed
Initial prototype of Frame + Page + Navigation.
1 parent ef7c3ce commit 2c4781d

26 files changed

+520
-80
lines changed

BCL.csproj

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,18 @@
153153
<DependentUpon>text.d.ts</DependentUpon>
154154
</TypeScriptCompile>
155155
<TypeScriptCompile Include="ui\core\bindable.ts" />
156-
<TypeScriptCompile Include="ui\core\index.ts" />
157156
<TypeScriptCompile Include="ui\core\proxy.ts" />
158-
<TypeScriptCompile Include="ui\core\view.android.ts">
159-
<DependentUpon>view.d.ts</DependentUpon>
157+
<TypeScriptCompile Include="ui\frame\frame-common.ts">
158+
<DependentUpon>frame.d.ts</DependentUpon>
160159
</TypeScriptCompile>
161-
<TypeScriptCompile Include="ui\core\view.ios.ts">
162-
<DependentUpon>view.d.ts</DependentUpon>
160+
<TypeScriptCompile Include="ui\frame\frame.android.ts">
161+
<DependentUpon>frame.d.ts</DependentUpon>
163162
</TypeScriptCompile>
163+
<TypeScriptCompile Include="ui\frame\frame.d.ts" />
164+
<TypeScriptCompile Include="ui\frame\frame.ios.ts">
165+
<DependentUpon>frame.d.ts</DependentUpon>
166+
</TypeScriptCompile>
167+
<TypeScriptCompile Include="ui\frame\index.ts" />
164168
<TypeScriptCompile Include="ui\image\image.android.ts">
165169
<DependentUpon>image.d.ts</DependentUpon>
166170
</TypeScriptCompile>
@@ -177,14 +181,22 @@
177181
<TypeScriptCompile Include="ui\label\label.ios.ts">
178182
<DependentUpon>label.d.ts</DependentUpon>
179183
</TypeScriptCompile>
180-
<TypeScriptCompile Include="ui\text-input\index.ts" />
181-
<TypeScriptCompile Include="ui\text-input\text-input.android.ts">
182-
<DependentUpon>text-input.d.ts</DependentUpon>
184+
<TypeScriptCompile Include="ui\pages\index.ts" />
185+
<TypeScriptCompile Include="ui\pages\page-common.ts">
186+
<DependentUpon>page.d.ts</DependentUpon>
187+
</TypeScriptCompile>
188+
<TypeScriptCompile Include="ui\pages\page.android.ts">
189+
<DependentUpon>page.d.ts</DependentUpon>
190+
</TypeScriptCompile>
191+
<TypeScriptCompile Include="ui\pages\page.d.ts" />
192+
<TypeScriptCompile Include="ui\text-field\index.ts" />
193+
<TypeScriptCompile Include="ui\text-field\text-field.android.ts">
194+
<DependentUpon>text-field.d.ts</DependentUpon>
183195
</TypeScriptCompile>
184-
<TypeScriptCompile Include="ui\text-input\text-input.ios.ts">
185-
<DependentUpon>text-input.d.ts</DependentUpon>
196+
<TypeScriptCompile Include="ui\text-field\text-field.d.ts" />
197+
<TypeScriptCompile Include="ui\text-field\text-field.ios.ts">
198+
<DependentUpon>text-field.d.ts</DependentUpon>
186199
</TypeScriptCompile>
187-
<TypeScriptCompile Include="ui\text-input\text-input.d.ts" />
188200
<TypeScriptCompile Include="utils\module-merge.ts" />
189201
<TypeScriptCompile Include="utils\utils_android.ts" />
190202
<TypeScriptCompile Include="utils\utils_ios.ts" />
@@ -247,7 +259,7 @@
247259
<TypeScriptCompile Include="libjs.d.ts" />
248260
</ItemGroup>
249261
<ItemGroup>
250-
<TypeScriptCompile Include="ui\core\view.d.ts" />
262+
<TypeScriptCompile Include="ui\core\view.ts" />
251263
<TypeScriptCompile Include="ui\core\observable.ts" />
252264
<TypeScriptCompile Include="ui\dialogs\dialogs.android.ts">
253265
<DependentUpon>dialogs.d.ts</DependentUpon>

application/application.android.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import appModule = require("application/application-common");
22
import dts = require("application");
3+
import frame = require("ui/frame");
34

45
// merge the exports of the application_common file with the exports of this file
56
declare var exports;
@@ -112,7 +113,7 @@ class AndroidApplication implements dts.AndroidApplication {
112113
public foregroundActivity: android.app.Activity;
113114
public startActivity: android.app.Activity;
114115
public packageName: string;
115-
public getActivity: (intent: android.content.Intent) => any;
116+
// public getActivity: (intent: android.content.Intent) => any;
116117

117118
public onActivityCreated: (activity: android.app.Activity, bundle: android.os.Bundle) => void;
118119
public onActivityDestroyed: (activity: android.app.Activity) => void;
@@ -128,12 +129,23 @@ class AndroidApplication implements dts.AndroidApplication {
128129
this.nativeApp = nativeApp;
129130
this.packageName = nativeApp.getPackageName();
130131
this.context = nativeApp.getApplicationContext();
131-
this.getActivity = undefined;
132+
}
133+
134+
public getActivity(intent: android.content.Intent): any {
135+
var currentPage = rootFrame.currentPage;
136+
if (!currentPage) {
137+
throw new Error("Root frame not navigated to a page.");
138+
}
139+
140+
return currentPage.android.getActivityExtends();
132141
}
133142

134143
public init() {
135144
this._eventsToken = initEvents();
136145
this.nativeApp.registerActivityLifecycleCallbacks(this._eventsToken);
137146
this.context = this.nativeApp.getApplicationContext();
138147
}
139-
}
148+
}
149+
150+
// The root frame of the application
151+
export var rootFrame = new frame.Frame();

application/application.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

22
declare module "application" {
3+
import frame = require("ui/frame");
4+
5+
export var rootFrame: frame.Frame;
36

47
/**
5-
* The main entry point event. This method is expected to return an instance of the root UI for the application.
6-
* This will be an Activity extends for Android and a RootViewController for iOS.
8+
* The main entry point event. This method is expected to use the root frame to navigate to the main application page.
79
*/
8-
export function onLaunch(): any;
10+
export function onLaunch(): void;
911

1012
/**
1113
* This method will be called when the Application is suspended.
@@ -85,7 +87,7 @@ declare module "application" {
8587
* This method is called by the JavaScript Bridge when navigation to a new activity is triggered.
8688
* The return value of this method should be com.tns.NativeScriptActivity.extends implementation.
8789
*/
88-
getActivity: (intent: android.content.Intent) => any;
90+
getActivity(intent: android.content.Intent): any;
8991

9092
/**
9193
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityCreated method.

declarations.android.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ declare module android {
338338
}
339339
*/
340340

341+
341342
declare var app;
342343
declare var telerik;
343344
declare var gc: () => any;

ui/core/bindable.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export class Bindable extends observable.Observable {
3737
}
3838
}
3939

40+
public setPropertyCore(data: observable.PropertyChangeData) {
41+
super.setPropertyCore(data);
42+
this.updateTwoWayBinding(data.propertyName, data.value);
43+
}
44+
4045
public getBinding(propertyName: string) {
4146
return this._bindings[propertyName];
4247
}

ui/core/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

ui/core/observable.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ export class Observable {
3131
private _trackChanging = false;
3232

3333
constructor(body?: any) {
34+
if (body) {
35+
for (var key in body) {
36+
// TODO: Is this correct
37+
this[key] = body[key];
38+
}
39+
}
40+
3441
this.on = this.addEventListener = this.addObserver;
3542
this.off = this.removeEventListener = this.removeObserver;
3643
}

ui/core/proxy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import bindable = require("ui/core/bindable");
44
export class ProxyObject extends bindable.Bindable {
55
public setPropertyCore(data: observable.PropertyChangeData) {
66
this.setNativeProperty(data);
7+
this.updateTwoWayBinding(data.propertyName, data.value);
78
}
89

910
public setNativeProperty(data: observable.PropertyChangeData) {

ui/core/view.android.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

ui/core/view.d.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

ui/core/view.ios.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

ui/core/view.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import proxy = require("ui/core/proxy");
2+
import application = require("application");
3+
4+
export class View extends proxy.ProxyObject {
5+
private _parent: Panel;
6+
7+
public onInitialized(content: android.content.Context) {
8+
// TODO: This is used by Android, rethink this routine
9+
}
10+
11+
public addToParent(native: any) {
12+
// TODO: Temporary
13+
if (application.ios && this.ios) {
14+
native.addSubview(this.ios);
15+
} else if (application.android && this.android) {
16+
native.addView(this.android);
17+
}
18+
}
19+
20+
/**
21+
* Gets the Panel instance that parents this view. This property is read-only.
22+
*/
23+
get parent(): Panel {
24+
return this._parent;
25+
}
26+
27+
/**
28+
* Gets the android-specific native instance that lies behind this view. Will be available if running on an Android platform.
29+
*/
30+
get android(): any {
31+
return undefined;
32+
}
33+
34+
/**
35+
* Gets the ios-specific native instance that lies behind this view. Will be available if running on an Android platform.
36+
*/
37+
get ios(): any {
38+
return undefined;
39+
}
40+
41+
// TODO: Should these be public?
42+
public onAddedToParent(parent: Panel) {
43+
this._parent = parent;
44+
// TODO: Attach to parent - e.g. update data context, bindings, styling, etc.
45+
}
46+
47+
public onRemovedFromParent() {
48+
this._parent = null;
49+
// TODO: Detach from parent.
50+
}
51+
}
52+
53+
/**
54+
* The Panel class represents an extended View which can have other views as children.
55+
*/
56+
export class Panel extends View {
57+
private _children: Array<View>;
58+
59+
constructor() {
60+
super();
61+
62+
this._children = new Array<View>();
63+
}
64+
65+
public addChild(child: View) {
66+
// Validate child is not parented
67+
if (child.parent) {
68+
var message;
69+
if (child.parent === this) {
70+
message = "View already added to this panel.";
71+
} else {
72+
message = "View is already a child of another panel.";
73+
}
74+
75+
throw new Error(message);
76+
}
77+
78+
this._children.push(child);
79+
child.onAddedToParent(this);
80+
}
81+
82+
public removeChild(child: View) {
83+
if (!child) {
84+
return;
85+
}
86+
87+
if (child.parent !== this) {
88+
throw new Error("View is not parented by this panel.");
89+
}
90+
91+
var index = this._children.indexOf(child);
92+
if (index < 0) {
93+
throw new Error("View not found in children collection.");
94+
}
95+
96+
this._children.splice(index, 1);
97+
child.onRemovedFromParent();
98+
}
99+
}

0 commit comments

Comments
 (0)