Skip to content

Commit 4befe9f

Browse files
authored
Merge pull request #141 from NativeScript/niliev/bottom
[DO-NOT-MERGE] BottomNavigation & Tabs Examples
2 parents 22adda3 + a4e2e2c commit 4befe9f

File tree

122 files changed

+1504
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1504
-120
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"no-multi-str": "error",
101101
"no-multiple-empty-lines": "error",
102102
"no-negated-condition": "off",
103-
"no-nested-ternary": "error",
103+
"no-nested-ternary": "off",
104104
"no-new": "error",
105105
"no-new-func": "error",
106106
"no-new-object": "error",

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ report
88

99
app/**/*.map
1010
app/**/*-ts-*.js
11+
.migration_backup/
1112

1213
.DS_Store
1314
**/*.log

.migration_backup/package.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "nativescript-sdk-examples-js",
3+
"description": "NativeScript SDK Examples",
4+
"author": "Telerik <support@telerik.com>",
5+
"version": "0.1.0",
6+
"homepage": "https://github.com/NativeScript/nativescript-sdk-examples-js",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/NativeScript/nativescript-sdk-examples-js"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/NativeScript/nativescript-sdk-examples-js/issues"
13+
},
14+
"keywords": [
15+
"NativeScript",
16+
"JavaScript",
17+
"SDK",
18+
"example",
19+
"documentation"
20+
],
21+
"license": "Apache-2.0",
22+
"nativescript": {
23+
"id": "org.nativescript.nativescriptsdkexamplesjs",
24+
"tns-android": {
25+
"version": "6.0.0"
26+
},
27+
"tns-ios": {
28+
"version": "6.0.0"
29+
}
30+
},
31+
"dependencies": {
32+
"nativescript-theme-core": "~1.0.4",
33+
"tns-core-modules": "6.0.1"
34+
},
35+
"devDependencies": {
36+
"eslint": "~5.9.0",
37+
"fs-extra": "^0.30.0",
38+
"markdown-snippet-injector": "^0.2.4",
39+
"nativescript-dev-webpack": "1.0.0",
40+
"tar.gz": "^1.0.7",
41+
"tns-platform-declarations": "6.0.1",
42+
"tslint": "5.11.0",
43+
"typescript": "3.4.1"
44+
},
45+
"scripts": {
46+
"lint": "eslint \"app/**/*.js\"",
47+
"tslint": "tslint -p tsconfig.json",
48+
"tsc": "tsc",
49+
"build": "node scripts/build.js",
50+
"archive": "node scripts/archive.js",
51+
"inject": "mdinject --root=app --docsroot=dist/cookbook --sourceext=\".js|.ts|.css|.xml\" --snippettitles=\"JavaScript|TypeScript|CSS|XML\"",
52+
"pretsc": "npm install",
53+
"pretslint": "npm run tsc",
54+
"prelint": "npm run tslint",
55+
"prebuild": "npm run lint",
56+
"postbuild": "npm run inject && npm run archive",
57+
"e2e": "mocha --opts ./e2e/config/mocha.opts",
58+
"update-webpack": "./node_modules/.bin/update-ns-webpack --deps --configs"
59+
}
60+
}

.migration_backup/tsconfig.tns.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"module": "es2015",
5+
"moduleResolution": "node"
6+
}
7+
}

app/main-page.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ const navigationLinks = [
5050
new link("ImageSource", "ns-framework-modules-category/image-source/image-source-page"),
5151
new link("File System", "ns-framework-modules-category/file-system/file-system-page"),
5252
new link("Modal view", "ns-ui-category/modal-view/modal-view-examples-page"),
53-
new link("XML Parser", "ns-framework-modules-category/xml-parser/xml-parser-page")
53+
new link("XML Parser", "ns-framework-modules-category/xml-parser/xml-parser-page"),
54+
new link("BottomNavigation", "ns-ui-widgets-category/bottom-navigation/bottom-navigation-page"),
55+
new link("Tabs", "ns-ui-widgets-category/tabs/tabs-page")
5456
];
5557

5658
function onNavigatingTo(args) {

app/ns-ui-category/icon-fonts/basics/basics-page.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
<!-- Using IcoMoon-Free.ttf -->
2424
<Label text="&#xe904;" class="ico"/>
2525
<!-- << icon-font-xml-def -->
26+
27+
<!-- Using font icons in Images requires the font:// prefix -->
28+
<Image src="font://&#xf019;" class="far"></Image>
2629
</StackLayout>
2730
</Page>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const ListViewLinksModel = require("../../links-view-model");
2+
const link = require("../../link");
3+
const navigationLinks = [
4+
new link("Usage", "ns-ui-widgets-category/bottom-navigation/usage/usage-page"),
5+
new link("Theming", "ns-ui-widgets-category/bottom-navigation/theming/theming-page"),
6+
new link("Events", "ns-ui-widgets-category/bottom-navigation/events/events-page"),
7+
new link("Properties", "ns-ui-widgets-category/bottom-navigation/properties/properties-page"),
8+
new link("Tips & Tricks", "ns-ui-widgets-category/bottom-navigation/tips-and-tricks/tips-and-tricks-page")
9+
];
10+
const navigationLinksTsc = [
11+
new link("Usage", "ns-ui-widgets-category/bottom-navigation/usage/usage-ts-page"),
12+
new link("Theming", "ns-ui-widgets-category/bottom-navigation/theming/theming-ts-page"),
13+
new link("Events", "ns-ui-widgets-category/bottom-navigation/events/events-ts-page"),
14+
new link("Properties", "ns-ui-widgets-category/bottom-navigation/properties/properties-ts-page"),
15+
new link("Tips & Tricks", "ns-ui-widgets-category/bottom-navigation/tips-and-tricks/tips-and-tricks-ts-page")
16+
];
17+
18+
function onNavigatingTo(args) {
19+
const page = args.object;
20+
21+
page.bindingContext = new ListViewLinksModel({
22+
links: navigationLinks,
23+
actionBarTitle: args.context.title,
24+
showTypeScriptExamples: false,
25+
tsclinks: navigationLinksTsc
26+
});
27+
}
28+
exports.onNavigatingTo = onNavigatingTo;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
2+
xmlns:myList="components"
3+
navigatingTo="onNavigatingTo"
4+
navigatedTo="onNavigatedTo">
5+
<Page.actionBar>
6+
<ActionBar title="{{ actionBarTitle == null ? '' : actionBarTitle }}" icon="" class="action-bar"/>
7+
</Page.actionBar>
8+
9+
<myList:list/>
10+
</Page>
Lines changed: 7 additions & 0 deletions
Lines changed: 6 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const fromObject = require("tns-core-modules/data/observable").fromObject;
2+
3+
exports.onNavigatingTo = (args) => {
4+
const page = args.object;
5+
const vm = fromObject({
6+
selectedIndex: 1
7+
});
8+
9+
page.bindingContext = vm;
10+
};
11+
12+
// >> bottom-navigation-events-js
13+
exports.onBottomNavLoaded = (args) => {
14+
// Using the loaded event to ger a reference to the BottomNavigation
15+
const bottomNavigation = args.object;
16+
17+
// Using selectedIndexChanged
18+
bottomNavigation.on("selectedIndexChanged", (args) => {
19+
// args is of type SelectedIndexChangedEventData
20+
const oldIndex = args.oldIndex;
21+
const newIndex = args.newIndex;
22+
console.log(`oldIndex: ${oldIndex}; newIndex: ${newIndex}`);
23+
24+
args.object.page.bindingContext.set("selectedIndex", newIndex);
25+
});
26+
};
27+
// << bottom-navigation-events-js
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Page navigatingTo="onNavigatingTo">
2+
<Page.actionBar>
3+
<ActionBar title="BottomNavigation - Events"/>
4+
</Page.actionBar>
5+
<!-- >> bottom-navigation-events-xml -->
6+
<BottomNavigation selectedIndex="1" loaded="onBottomNavLoaded">
7+
<!-- The bottom tab UI is created via TabStrip (the containier) and TabStripItem (for each tab)-->
8+
<TabStrip>
9+
<TabStripItem title="Home" iconSource="res://baseline_home_black_24pt"></TabStripItem>
10+
<TabStripItem title="Account" iconSource="res://baseline_account_balance_black_24pt"></TabStripItem>
11+
</TabStrip>
12+
13+
<!-- The number of TabContentItem components should corespond to the number of TabStripItem components -->
14+
<TabContentItem>
15+
<GridLayout rows="*, *">
16+
<Label row="0" text="Home Page" class="h2 text-center" color="orange"></Label>
17+
<Label row="1" text="{{ 'newIndex: ' + selectedIndex }}" class="h2 text-center"></Label>
18+
</GridLayout>
19+
</TabContentItem>
20+
<TabContentItem>
21+
<GridLayout rows="*, *">
22+
<Label row="0" text="Account Page" class="h2 text-center"></Label>
23+
<Label row="1" text="{{ 'newIndex: ' + selectedIndex }}" class="h2 text-center"></Label>
24+
</GridLayout>
25+
</TabContentItem>
26+
</BottomNavigation>
27+
<!-- << bottom-navigation-events-xml -->
28+
</Page>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// >> bottom-navigation-events-tsc
2+
import { EventData, fromObject } from "tns-core-modules/data/observable";
3+
import { BottomNavigation, SelectedIndexChangedEventData } from "tns-core-modules/ui/bottom-navigation";
4+
// >> (hide)
5+
import { Page } from "tns-core-modules/ui/page";
6+
7+
export function onNavigatingTo(args: EventData) {
8+
const page = args.object as Page;
9+
const vm = fromObject({
10+
selectedIndex: 1
11+
});
12+
13+
page.bindingContext = vm;
14+
}
15+
// << (hide)
16+
export function onBottomNavLoaded(args: EventData) {
17+
// Using the loaded event to ger a reference to the BottomNavigation
18+
const bottomNavigation = args.object as BottomNavigation;
19+
20+
// Using selectedIndexChanged
21+
bottomNavigation.on(BottomNavigation.selectedIndexChangedEvent, (data: SelectedIndexChangedEventData) => {
22+
const oldIndex: number = data.oldIndex;
23+
const newIndex: number = data.newIndex;
24+
console.log(`oldIndex: ${oldIndex}; newIndex: ${newIndex}`);
25+
26+
(<any>args.object).page.bindingContext.set("selectedIndex", newIndex);
27+
});
28+
}
29+
// << bottom-navigation-events-tsc
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Page navigatingTo="onNavigatingTo">
2+
<Page.actionBar>
3+
<ActionBar title="BottomNavigation - Events"/>
4+
</Page.actionBar>
5+
<!-- >> bottom-navigation-events-xml -->
6+
<BottomNavigation selectedIndex="1" loaded="onBottomNavLoaded">
7+
8+
<!-- The bottom tab UI is created via TabStrip (the containier) and TabStripItem (for each tab)-->
9+
<TabStrip>
10+
<TabStripItem title="Home" iconSource="res://baseline_home_black_24pt"></TabStripItem>
11+
<TabStripItem title="Account" iconSource="res://baseline_account_balance_black_24pt"></TabStripItem>
12+
</TabStrip>
13+
14+
<!-- The number of TabContentItem components should corespond to the number of TabStripItem components -->
15+
<TabContentItem>
16+
<GridLayout rows="*, *">
17+
<Label row="0" text="Home Page" class="h2 text-center" color="orangered"></Label>
18+
<Label row="1" text="{{ 'newIndex: ' + selectedIndex }}" class="h2 text-center"></Label>
19+
</GridLayout>
20+
</TabContentItem>
21+
<TabContentItem>
22+
<GridLayout rows="*, *">
23+
<Label row="0" text="Account Page" class="h2 text-center"></Label>
24+
<Label row="1" text="{{ 'selectednewIndexIndex: ' + selectedIndex }}" class="h2 text-center"></Label>
25+
</GridLayout>
26+
</TabContentItem>
27+
</BottomNavigation>
28+
<!-- << bottom-navigation-events-xml -->
29+
</Page>
Lines changed: 7 additions & 0 deletions
Lines changed: 16 additions & 0 deletions
Lines changed: 14 additions & 0 deletions

0 commit comments

Comments
 (0)