NativeScript plugin to add a bottom navigation component for Android & iOS
npm install nativescript-bottom-navigationNativescript plugin for Android & iOS to have the Bottom Navigation Bar following the Material Design Guidelines.
  
> IMPORTANT: This package will be deprecated, this is the last release on this repository, the component will be moved to nativescript-material-components

1. Installation
2. Usage with Javascript
3. Usage with Angular
4. Usage with Vue
5. Css Styling
6. API
You need the version of NS6 or later to use this plugin.
``javascript`
tns plugin add nativescript-bottom-navigation
if you want to use the plugin with NS5 and above use the version 1.5.1
`javascript`
tns plugin add nativescript-bottom-navigation@1.5.1
- BottomNavigation class now is BottomNavigationBarNativescriptBottomNavigationModule
- now is NativeScriptBottomNavigationBarModuleres://
- should be used to reference icons in the tabsOn
- The prefix of the Event interfaces was removed:OnTabPressedEventData
- Example: now is TabPressedEventDatatab
- The prefix of Css properties was removed:tab-active-color
- Example: now is active-color
- The documentation was updated review it :D
- Badge now are supported using the method: showBadge(index, value)
- NOTE: if you want to show a badge as a red dot no value should be passed to the function.
Before start using the plugin you need to add the icons for android & iOS in your App_Resources directory.
#### XML
You can set the tabs using the tabs property
`xml`
loaded="pageLoaded"
class="page">
activeColor="green"
inactiveColor="red"
backgroundColor="black"
tabSelected="tabSelected"
row="1"
>
`typescript
import { EventData } from 'tns-core-modules/data/observable';
import { Page } from 'tns-core-modules/ui/page';
import {
BottomNavigationTab,
TabSelectedEventData,
} from 'nativescript-bottom-navigation';
// Event handler for Page 'loaded' event attached in main-page.xml
export function pageLoaded(args: EventData) {
// Get the event sender
let page =
page.bindingContext = {
tabs: [
new BottomNavigationTab({ title: 'First', icon: 'res://ic_home' }),
new BottomNavigationTab({
title: 'Second',
icon: 'res://ic_view_list',
isSelectable: false,
}),
new BottomNavigationTab({ title: 'Third', icon: 'res://ic_menu' }),
],
};
}
export function tabSelected(args: TabSelectedEventData) {
console.log('tab selected ' + args.newIndex);
}
`
or you can add the tabs directly in your xml view
`xml`
loaded="pageLoaded"
class="page">
inactiveColor="red"
backgroundColor="black"
tabSelected="tabSelected"
row="1"
>
#### Angular
First you need to include the NativeScriptBottomNavigationBarModule in your app.module.ts
``typescript
import { NativeScriptBottomNavigationBarModule} from "nativescript-bottom-navigation/angular";
@NgModule({
imports: [
NativeScriptBottomNavigationBarModule
],
...
})
`
`html`
activeColor="red"
inactiveColor="yellow"
backgroundColor="black"
(tabSelected)="onBottomNavigationTabSelected($event)"
(tabPressed)="onBottomNavigationTabPressed($event)"
row="1"
>
or you can declare the BottomNavigationTab in your html directly
`html`
inactiveColor="yellow"
backgroundColor="black"
(tabSelected)="onBottomNavigationTabSelected($event)"
(tabPressed)="onBottomNavigationTabPressed($event)"
row="1"
>
icon="res://ic_home"
>
icon="res://ic_view_list"
[isSelectable]="false"
>
icon="res://ic_menu"
>
#### Vue
If you want to use this plugin with Vue, do this in your app.js or main.js:
`javascript
import BottomNavigationBar from 'nativescript-bottom-navigation/vue';
Vue.use(BottomNavigationBar);
`
This will install and register BottomNavigationBar and BottomNavigationTab components to your Vue instance and now you can use the plugin as follows:
`html`
inactiveColor="yellow"
backgroundColor="black"
@tabSelected="onBottomNavigationTabSelected"
row="1"
>
icon="ic_view_list"
isSelectable="false"
/>
You can find more information of how to use nativescript plugins with Vue Here!
#### CSS Styling
You can also use your css file to set or change the activeColor, inactiveColor & backgroundColor of the Bottom Navigation Bar.
`css`
.botom-nav {
active-color: green;
inactive-color: black;
background-color: blue;
}
1. BottomNavigationBar
2. BottomNavigationTab
- Properties (bindable): Properties settable through XML/HTML
- Properties (internal): Properties accessible through JS/TS instance
- Events: Event properties settable thew XML/HTML
#### Properties (bindable)
| Property | Required | Default | Type | Description |
| --------------- | -------- | --------------------------- | ---------------------------- | ------------------------------------------------------- |
| tabs | true | [] | Array | Array containing the tabs for the BottomNavigationBar |TitleVisibility.Selected
| titleVisibility | false | | TitleVisibility | Title Visibility for each BottomNavigationTab |String
| activeColor | false | "black" | | Color of the BottomNavigationTab when it's selected |String
| inactiveColor | false | "gray" | | Color of the BottomNavigationTab when it's not selected |String
| backgroundColor | false | "white" | | Color of the BottomNavigation background |
#### Properties (internal)
| Property | Default | Type | Description |
| ---------------- | --------------------------- | ----------------- | ------------------------------------------------------- |
| selectedTabIndex | 0 | Number | Index of the selected tab |TitleVisibility.Selected
| titleVisibility | | TitleVisibility | Title Visibility for each BottomNavigationTab |String
| activeColor | "black" | | Color of the BottomNavigationTab when it's selected |String
| inactiveColor | "gray" | | Color of the BottomNavigationTab when it's not selected |String
| backgroundColor | "white" | | Color of the BottomNavigation background |
#### Events
| Name | Type | Description |
| ------------- | -------------------------------------- | ------------------------------------------------------------------------ |
| tabPressed | (args: TabPressedEventData): void | Function fired every time the user tap a tab with isSelectable: false |(args: TabSelectedEventData): void
| tabSelected | | Function fired every time the user select a new tab |(args: TabReselectedEventData): void
| tabReselected | | Function fired every time the user select a tab that is already selected |
#### Methods
| Property | Type | Description |
| ------------------------------------------ | ------ | -------------------------------- |
| selectTab(index: number) | void | Select a tab programmatically |showBadge(index: number, value?: number)
| | void | Show a badge for an specific tab |
#### Properties (bindable)
| Property | Required | Default | Type | Description |
| ------------ | -------- | ------- | --------- | ------------------------------------------- |
| title | true | null | string | Title of the tab |string
| icon | true | null | | Icon of the tab |boolean` | Determine if the tab can be selected or not |
| isSelectable | false | true |