nativescript-bottombar
TypeScript icon, indicating that this package has built-in type declarations

3.0.8 • Public • Published

npm npm twitter: @_rhanb

NPM

NativeScript BottomBar 🍻🔥🇫🇷

NativeScript plugin for AHBottomNavigation and MiniTabBar.

Checkout demo.

Installation

  • 2.x: tns plugin add nativescript-bottombar@2.1.4

  • 3.x: tns plugin add nativescript-bottombar

Usage

API documentation

Angular NativeScript

XML

<GridLayout rows="*, auto">
    <StackLayout row="0" orientation="vertical">
       <Label text="demo"></Label>
    </StackLayout>
    <BottomBar row="1" [items]="items" [hide]="hidden" [titleState]="titleState" (loaded)="tabLoaded($event)" (tabSelected)="tabSelected($event)" [inactiveColor]="inactiveColor" [accentColor]="accentColor" colored="true"></BottomBar>
</GridLayout>

Component

import { Component } from "@angular/core";
import { registerElement } from 'nativescript-angular';
import { BottomBar, BottomBarItem, TITLE_STATE, SelectedIndexChangedEventData, Notification } from 'nativescript-bottombar';
 
registerElement('BottomBar', () => BottomBar);
 
@Component({
    selector: "nsapp",
    templateUrl: "app.component.html",
})
 
export class AppComponent {
    public hidden: boolean;
    public titleState: TITLE_STATE;
    public _bar: BottomBar;
    public inactiveColor: string;
    public accentColor: string;
 
    public items: Array<BottomBarItem> = [
        new BottomBarItem(0, "Home", "ic_home_black_24dp", "black", new Notification("blue", "white", "1")),
        new BottomBarItem(1, "Calendar", "ic_calendar", "#1083BF", new Notification("green", "blue", "1")),
        new BottomBarItem(2, "Profile", "ic_collaborator", "pink", new Notification("pink", "yellow", "1")),
        new BottomBarItem(3, "Message", "ic_paperplane", "green", new Notification("green", "red", "1"))
    ];
 
    tabLoaded(event) {
        this._bar = <BottomBar>event.object;
        this.hidden = false;
        this.titleState = TITLE_STATE.SHOW_WHEN_ACTIVE;
        this.inactiveColor = "white";
        this.accentColor = "blue";
    }
    
     tabSelected(args: SelectedIndexChangedEventData) {
         // only triggered when a different tab is tapped
         console.log(args.newIndex);
     }
}

TypeScript NativeScript

XML

<Page class="page"
    navigatingTo="onNavigatingTo" 
    xmlns="http://www.nativescript.org/tns.xsd"
    xmlns:btb="nativescript-bottombar">
    
    <ActionBar class="action-bar">
        <Label class="action-bar-title" text="Home"></Label>
    </ActionBar>
 
    <GridLayout rows="*, auto">
        <Label row="0" text="row 1"/>
        <btb:BottomBar row="1" items="{{ items }}" loaded="{{ tabLoaded($event) }}" hide="{{ hidden }}" titleState="{{ titleState }}" tabSelected="{{ tabSelected($event) }}" inactiveColor="{{ inactiveColor }}" accentColor="{{ accentColor }}" colored="true"> 
        </btb:BottomBar>
    </GridLayout>
</Page>

Model

import { Observable } from 'data/observable';
import { BottomBar, BottomBarItem, TITLE_STATE, SelectedIndexChangedEventData, Notification } from 'nativescript-bottombar';
 
export class HomeViewModel extends Observable {
    public hidden: boolean;
    public titleState: TITLE_STATE;
    public _bar: BottomBar;
    public inactiveColor: string;
    public accentColor: string;
 
    public items: Array<BottomBarItem> = [
        new BottomBarItem(0, "Home", "ic_home_black_24dp", "black", new Notification("blue", "white", "1")),
        new BottomBarItem(1, "Calendar", "ic_calendar", "#1083BF", new Notification("green", "blue", "1")),
        new BottomBarItem(2, "Profile", "ic_collaborator", "pink", new Notification("pink", "yellow", "1")),
        new BottomBarItem(3, "Message", "ic_paperplane", "green", new Notification("green", "red", "1"))
    ];
 
    constructor() {
        super();
    }
    tabLoaded(event) {
        console.log("barLoaded");
        this._bar = <BottomBar>event.object;
        this.hidden = false;
        this.titleState = TITLE_STATE.SHOW_WHEN_ACTIVE;
        this.inactiveColor = "white";
        this.accentColor = "blue";
    }
 
    tabSelected(args: SelectedIndexChangedEventData) {
        // only triggered when a different tab is tapped
        console.log(args.newIndex);
    }
}

Ressources

Don't forget that you need your icons files to be in your ressources folder as follow:

iOS Android
iOS Android

API documentation

Package Sidebar

Install

npm i nativescript-bottombar

Weekly Downloads

2

Version

3.0.8

License

none

Last publish

Collaborators

  • rhanb