Home

Awesome

<a align="center" href="https://www.npmjs.com/package/nativescript-floatingactionbutton"> <h3 align="center">NativeScript-FloatingActionButton</h3> </a> <h4 align="center">NativeScript plugin for Material Design Floating Action Button UI component.</h4> <p align="center"> <a href="https://www.npmjs.com/package/@nstudio/nativescript-floatingactionbutton"> <img src="https://github.com/nstudio/nativescript-floatingactionbutton/workflows/Build%20CI/badge.svg" alt="Action Build"> </a> <a href="https://www.npmjs.com/package/@nstudio/nativescript-floatingactionbutton"> <img src="https://img.shields.io/npm/v/@nstudio/nativescript-floatingactionbutton.svg" alt="npm"> </a> <a href="https://www.npmjs.com/package/@nstudio/nativescript-floatingactionbutton"> <img src="https://img.shields.io/npm/dt/@nstudio/nativescript-floatingactionbutton.svg?label=npm%20downloads" alt="npm"> </a> </p>

Installation

Nativescript 7+:

ns plugin add @nstudio/nativescript-floatingactionbutton

NativeScript lower than 7:

tns plugin add @nstudio/nativescript-floatingactionbutton@2.1.0

Screenshot


FAB Android Screenshot FAB iOS Screenshot

Multiple FAB/Swipe Animation Support

FAB Animations

Usage

<h4>The icon for the FAB can be a local image in your app or an image/icon from the App_Resources.</h4>

Plain NativeScript

<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded"
      xmlns:FAB="@nstudio/nativescript-floatingactionbutton">
    <ActionBar title="Native FAB" />
    <grid-layout rows="auto, *">
        <list-view row="1" items="{{ users }}">
            <list-view.itemTemplate>
                <label text="{{ name }}" />
            </list-view.itemTemplate>
        </list-view>
            <FAB:fab tap="fabTap"
                     row="1"
                     icon="'~/assets/ic_add_white.png'"
                     rippleColor="#f1f1f1"
                     class="fab-button" />
    </grid-layout>
</Page>

NativeScript Angular

import { registerElement } from 'nativescript-angular/element-registry';
registerElement(
  'Fab',
  () => require('@nstudio/nativescript-floatingactionbutton').Fab
);

HTML

<StackLayout>
    <FAB (tap)="fabTap()" icon="~/assets/ic_add_white.png" rippleColor="#f1f1f1" class="fab-button"></FAB>
</StackLayout>

NativeScript Vue

import Vue from 'nativescript-vue';

Vue.registerElement(
  'Fab',
  () => require('@nstudio/nativescript-floatingactionbutton').Fab
);

Template

<template>
  <page>
    <grid-layout rows="auto, *">
      <list-view row="1" items="{{ users }}">
        <list-view.itemTemplate>
          <label text="{{ name }}" textWrap="true" />
        </list-view.itemTemplate>
      </list-view>
      <fab
        @tap="fabTap"
        row="1"
        icon="res://ic_add_white"
        rippleColor="#f1f1f1"
        class="fab-button"
      ></fab>
    </grid-layout>
  </page>
</template>

CSS

Recommended CSS styles.

.fab-button {
  height: 70;
  width: 70; /// this is required on iOS - Android does not require width so you might need to adjust styles
  margin: 15;
  background-color: #ff4081;
  horizontal-align: right;
  vertical-align: bottom;
}

Use Icon Fonts

First you need to setup icon fonts as described in NativeScript documentation.

After this, you can use icon fonts on FAB by specifiying the unicode as text and add the fas/far class:

<FAB:fab text="&#xf02a;" class="fab-button fas" />

API

PropertyAndroidiOSDescriptionNote
backgroundColorXXSets the background color of the button
iconXXSupports the same image source options that NativeScript images supportRequired on android
textXXAllows to use text instead of imageCan be styled with font-* and color CSS properties
rippleColorXRipple color on lollipop devices, it will fill the FAB on pre-lollipop devicesNone
hideOnSwipeOfViewXXDirects the fab to animate itself in and out on scrollPass it the name of the view to monitor for a scroll event example: hideOnSwipeOfView="userListView"
hideAnimationDurationXXHow many milliseconds it takes for the button to hide.Default if not set: 300ms
swipeAnimationXXslideDown, slideUp, slideLeft, slideRight, scaleDefault is slideDown
androidScaleTypeXcenter, centerCrop, centerInside, fitCenter, fitEnd, fitStart, fitXY, matrix<br> for more details see Android-DocsDefault is center

iOS Notes

Running Demo Apps

npm run demo.android

// or

npm run demo.ios

Changelog

Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<img src="https://avatars1.githubusercontent.com/u/6006148?s=100&v=4" width="100px;"/><br /><sub>Brad Martin</sub><img src="https://avatars1.githubusercontent.com/u/1542376?s=100&v=4" width="100px;"/><br /><sub>Steve McNiven-Scott</sub><img src="https://avatars3.githubusercontent.com/u/850871?s=100&v=4" width="100px;"/><br /><sub>Nathanael Anderson</sub><img src="https://avatars3.githubusercontent.com/u/1100522?s=100&v=4" width="100px;"/><br /><sub>Gabriel Marinho</sub>
<img src="https://avatars1.githubusercontent.com/u/4092076?s=100&v=4" width="100px;"/><br /><sub>Alexander Vakrilov</sub><img src="https://avatars1.githubusercontent.com/u/8123916?s=100&v=4" width="100px;"/><br /><sub>Lázaro Danillo Menezes</sub><img src="https://avatars0.githubusercontent.com/u/8638243?s=100&v=4" width="100px;"/><br /><sub>Jofferson Ramirez Tiquez</sub><img src="https://avatars3.githubusercontent.com/u/9256365?s=100&v=4" width="100px;"/><br /><sub>Ravi</sub>
<img src="https://avatars3.githubusercontent.com/u/13824510?s=100&v=4" width="100px;"/><br /><sub>Samuel Ikechukwu</sub><img src="https://avatars2.githubusercontent.com/u/7893485?s=100&v=4" width="100px;"/><br /><sub>Stanimira Vlaeva</sub>
<!-- ALL-CONTRIBUTORS-LIST:END -->