Skip to content

Commit c967a69

Browse files
author
Elmi Ahmadov
committed
Router: add example
1 parent 02d9318 commit c967a69

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

examples/router/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Example "router"
2+
3+
[![GitPod Logo](../../doc/run-in-gitpod.png)](https://gitpod.io/#example=listview-cells/https://github.com/eclipsesource/tabris-decorators/tree/gplink/examples/router)
4+
5+
## Description
6+
7+
Demonstrates the usage of the router API.

examples/router/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "router",
3+
"version": "3.3.0",
4+
"dependencies": {
5+
"reflect-metadata": "^0.1.13"
6+
},
7+
"optionalDependencies": {
8+
"tabris": "^3.3.0",
9+
"tabris-decorators": "3.3.0"
10+
},
11+
"devDependencies": {
12+
"typescript": "3.3.x"
13+
},
14+
"main": "dist/app.js",
15+
"scripts": {
16+
"start": "tabris serve -w -a",
17+
"build": "tsc -p .",
18+
"watch": "tsc -p . -w --preserveWatchOutput --inlineSourceMap",
19+
"gitpod": "tabris serve -a -w --no-intro --port 8080 --external $(gp url 8080):443"
20+
}
21+
}

examples/router/src/app.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {NavigationView, contentView, Button, TextView, TextInput, Stack} from 'tabris';
2+
import {Router, Route, RoutePage} from 'tabris-decorators';
3+
4+
const navigationView = new NavigationView({
5+
layoutData: 'stretch'
6+
}).appendTo(contentView);
7+
8+
class MyPage1 extends RoutePage {
9+
constructor(properties?: any) {
10+
super(properties);
11+
this.append(
12+
<Stack stretch alignment="stretchX" padding={[0, 4]}>
13+
<TextInput/>
14+
<Button top="prev()" text="Open" onSelect={() =>
15+
router.goTo({
16+
route: 'my-route-2',
17+
payload: {
18+
text: this.find(TextInput).only().text
19+
}
20+
})}
21+
/>
22+
</Stack>
23+
);
24+
}
25+
}
26+
27+
class MyPage2 extends RoutePage {
28+
constructor(properties?: any) {
29+
super(properties);
30+
this.append(
31+
<Stack stretch alignment="stretchX" padding={[0, 4]}>
32+
<TextView alignment="centerX" height={32}/>
33+
<Button text="Go back" onSelect={() => router.back()}/>
34+
</Stack>
35+
);
36+
}
37+
38+
public onPayload(payload?: any) {
39+
this.find(TextView).only().text = payload && payload.text ? payload.text : 'no data';
40+
}
41+
}
42+
43+
class MyRoute1 extends Route {
44+
page = new MyPage1({title: 'foo'});
45+
};
46+
47+
class MyRoute2 extends Route {
48+
page = new MyPage2({title: 'bar'});
49+
};
50+
51+
const router = new Router({
52+
navigationView,
53+
routers: [
54+
{
55+
name: 'my-route-1',
56+
route: MyRoute1
57+
},
58+
{
59+
name: 'my-route-2',
60+
route: MyRoute2
61+
}
62+
],
63+
defaultRoute: { route: 'my-route-1' }
64+
});

examples/router/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"lib": ["es6" ],
6+
"jsx": "react",
7+
"jsxFactory": "JSX.createElement",
8+
"outDir": "dist",
9+
"experimentalDecorators": true,
10+
"emitDecoratorMetadata": true,
11+
"typeRoots": ["./node_modules/@types"]
12+
},
13+
"include": [
14+
"./src/*.ts",
15+
"./src/*.tsx"
16+
]
17+
}

0 commit comments

Comments
 (0)