Skip to content

Commit 6bb4668

Browse files
committed
docs: Tabs examples
1 parent c983195 commit 6bb4668

22 files changed

+429
-4
lines changed

app/app.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { DeepLinkData } from "./shared/deep-link-data";
66
@Component({
77
moduleId: module.id,
88
selector: "sdk-app",
9-
template: `
10-
<page-router-outlet></page-router-outlet>
11-
`
9+
template: `<page-router-outlet></page-router-outlet>`
1210
})
1311

1412
export class AppComponent implements AfterViewInit {

app/app.routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ export const routes = [
125125
loadChildren: "./ng-ui-widgets-category/bottom-navigation/bottom-navigation-examples.module#BottomNavigationExamplesModule",
126126
data: { title: "Bottom Navigation" }
127127
},
128+
{
129+
path: "tabs",
130+
loadChildren: "./ng-ui-widgets-category/tabs/tabs-examples.module#TabsExamplesModule",
131+
data: { title: "Tabs" }
132+
},
128133
{
129134
path: "text-field",
130135
loadChildren: "./ng-ui-widgets-category/text-field/text-field-examples.module#TextFieldExamplesModule",

app/examples-list.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let mainMenuLinks = [
1818
new Link("Switch", "/switch"),
1919
new Link("TabView", "/tab-view"),
2020
new Link("BottomNavigation", "/bottom-navigation"),
21+
new Link("Tabs", "/tabs"),
2122
new Link("TextField", "/text-field"),
2223
new Link("TextView", "/text-view"),
2324
new Link("WebView", "/web-view"),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: BottomNavigation
33
description: The NativeScript's BottomNavigation component provides a simple way to navigate between different views while providing common UI for both iOS and Android platforms. The recommended scenario suitable for BottomNavigation is a high level navigaiton with 3 to 5 tabs each with separate function.
4-
position: 44
4+
position: 42
55
slug: bottom-navigation-ng
66
---
77
example-order: usage, theming, properties, events, tips-and-tricks
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**API Reference for the** [Tabs Class](https://docs.nativescript.org/api-reference/classes/_ui_tab_view_.tabs)
2+
3+
**Native Component**
4+
5+
| Android | iOS |
6+
|:----------------------|:---------|
7+
| [ViewPager](https://developer.android.com/reference/android/support/v4/view/ViewPager) | [UIPageViewController](https://developer.apple.com/documentation/uikit/uipageviewcontroller?language=objc) |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- `selectedIndexChanged` - Event used to track the tabs interaction though the change of `selectedIndex` property of `Tabs` component. The event data is of type `SelectedIndexChangedEventData` extends `EventData` with two new properties:
2+
- `oldIndex` - Provides the old selected index.
3+
- `newIndwex` - Provides the new selected index.
4+
5+
<snippet id='tabs-events-ng'/>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Tabs [selectedIndex]="selectedIndex" (loaded)="onTabsLoaded($event)">
2+
3+
<!-- The Tabs tab UI is created via TabStrip (the containier) and TabStripItem (for each tab)-->
4+
<TabStrip>
5+
<TabStripItem title="Home" iconSource="res://baseline_home_black_24pt"></TabStripItem>
6+
<TabStripItem title="Account" iconSource="res://baseline_account_balance_black_24pt"></TabStripItem>
7+
</TabStrip>
8+
9+
<!-- The number of TabContentItem components should corespond to the number of TabStripItem components -->
10+
<TabContentItem>
11+
<GridLayout rows="*, *">
12+
<Label row="0" text="Home Page" class="h2 text-center" color="orangered"></Label>
13+
<Label row="1" [text]="selectedIndex" class="h2 text-center"></Label>
14+
</GridLayout>
15+
</TabContentItem>
16+
<TabContentItem>
17+
<GridLayout rows="*, *">
18+
<Label row="0" text="Account Page" class="h2 text-center"></Label>
19+
<Label row="1" [text]="selectedIndex" class="h2 text-center"></Label>
20+
</GridLayout>
21+
</TabContentItem>
22+
</Tabs>
23+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// >> bottom-navigation-events-ng
2+
import { Component, NgZone } from "@angular/core";
3+
import { EventData } from "tns-core-modules/data/observable";
4+
import { Tabs, SelectedIndexChangedEventData } from "tns-core-modules/ui/tabs";
5+
6+
@Component({
7+
moduleId: module.id,
8+
templateUrl: "./events.component.html"
9+
})
10+
export class EventsComponent {
11+
selectedIndex: number = 1;
12+
13+
constructor(private _zone: NgZone) { }
14+
15+
onTabsLoaded(args: EventData) {
16+
// Using the loaded event to ger a reference to the Tabs
17+
const tabs = args.object as Tabs;
18+
19+
// Using selectedIndexChanged
20+
tabs.on(Tabs.selectedIndexChangedEvent, (data: SelectedIndexChangedEventData) => {
21+
const oldIndex: number = data.oldIndex;
22+
const newIndex: number = data.newIndex;
23+
console.log(`oldIndex: ${oldIndex}; newIndex: ${newIndex}`);
24+
25+
this._zone.run(() => {
26+
this.selectedIndex = newIndex;
27+
})
28+
});
29+
}
30+
}
31+
// << bottom-navigation-events-ng
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Tabs
3+
description: The NativeScript's Tabs component provides a simple way to navigate between different views while providing common UI for both iOS and Android platforms. The recommended scenario suitable for BottomNavigation is a mid level navigaiton with unlimited tabs and common functions.The component supports swipe gestures and preloading.
4+
position: 42
5+
slug: tabs-ng
6+
---
7+
example-order: usage, theming, properties, events
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
> **Disclaimer:** The `Tabs` component is currently in **Beta** version. The component is being actively developed - use [the tracking issue](https://github.com/NativeScript/NativeScript/issues/6967) for details about the ongoing implementation.
2+
3+
The `Tabs` component provides a simple way to navigate between different views while providing common UI for both iOS and Android platforms. The recommended scenario suitable for `Tabs` is a mid level navigation. For additional information and details about bottom navigation refer to [the Material Design guidelines](https://material.io/design/components/tabs.html#usage).
4+
5+
> **Note:** NativeScript 6 introduced two new UI components called `BottomNavigation` and `Tabs`. The idea behind them is to provide more control when building tab based UI, while powering the CSS styling, the icon font support and other specific functionalities. Prior to NativeScript 6, we had the `TabView` component which had top and bottom implementations with different behavoirs for the different platofrms and some styling limitations. With `BottomNavigaiton` and `Tabs` coomponents available, the `TabView` can be considered obsolete.
6+
7+
The `Tabs` component roundup
8+
9+
- Semantic: Mid Level Navigation
10+
- Usage: Unlimited Tabs with common function
11+
- Transitions: Slide Transition indicating the relative position to each other
12+
- Gestures: Swipe Gesture
13+
- Preloading: At least 1 to the sides (because of the swipe gesture)

0 commit comments

Comments
 (0)