项目作者: nstudio

项目描述 :
Material Design Floating Action Button in NativeScript apps.
高级语言: TypeScript
项目地址: git://github.com/nstudio/nativescript-floatingactionbutton.git
创建时间: 2015-12-26T23:16:36Z
项目社区:https://github.com/nstudio/nativescript-floatingactionbutton

开源协议:Other

下载



NativeScript-FloatingActionButton


NativeScript plugin for Material Design Floating Action Button UI component.



Action Build


npm


npm

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

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

Plain NativeScript

  1. <Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded"
  2. xmlns:FAB="@nstudio/nativescript-floatingactionbutton">
  3. <ActionBar title="Native FAB" ></ActionBar>
  4. <grid-layout rows="auto, *">
  5. <list-view row="1" items="{{ users }}">
  6. <list-view.itemTemplate>
  7. <label text="{{ name }}" ></label>
  8. </list-view.itemTemplate>
  9. </list-view>
  10. <FAB:fab tap="fabTap"
  11. row="1"
  12. icon="'~/assets/ic_add_white.png'"
  13. rippleColor="#f1f1f1"
  14. class="fab-button" ></FAB:fab>
  15. </grid-layout>
  16. </Page>

NativeScript Angular

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

HTML

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

NativeScript Vue

  1. import Vue from 'nativescript-vue';
  2. Vue.registerElement(
  3. 'Fab',
  4. () => require('@nstudio/nativescript-floatingactionbutton').Fab
  5. );

Template

  1. <template>
  2. <page>
  3. <grid-layout rows="auto, *">
  4. <list-view row="1" items="{{ users }}">
  5. <list-view.itemTemplate>
  6. <label text="{{ name }}" textWrap="true" ></label>
  7. </list-view.itemTemplate>
  8. </list-view>
  9. <fab
  10. @tap="fabTap"
  11. row="1"
  12. icon="res://ic_add_white"
  13. rippleColor="#f1f1f1"
  14. class="fab-button"
  15. ></fab>
  16. </grid-layout>
  17. </page>
  18. </template>

CSS

Recommended CSS styles.

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

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:

  1. <FAB:fab text="" class="fab-button fas" ></FAB:fab>

API

Property Android iOS Description Note
backgroundColor X X Sets the background color of the button
icon X X Supports the same image source options that NativeScript images support Required on android
text X X Allows to use text instead of image Can be styled with font-* and color CSS properties
rippleColor X Ripple color on lollipop devices, it will fill the FAB on pre-lollipop devices None
hideOnSwipeOfView X X Directs the fab to animate itself in and out on scroll Pass it the name of the view to monitor for a scroll event example: hideOnSwipeOfView=”userListView”
hideAnimationDuration X X How many milliseconds it takes for the button to hide. Default if not set: 300ms
swipeAnimation X X slideDown, slideUp, slideLeft, slideRight, scale Default is slideDown
androidScaleType X center, centerCrop, centerInside, fitCenter, fitEnd, fitStart, fitXY, matrix
for more details see Android-Docs
Default is center

iOS Notes

  • We’re using MNFloatingActionButton by Matt Nydam
  • Width\Height are requried properties
  • icon is a required property, if left as empty string default will be shown

Running Demo Apps

  1. npm run demo.android
  2. // or
  3. npm run demo.ios

Changelog

Contributors


Brad Martin

Steve McNiven-Scott

Nathanael Anderson

Gabriel Marinho

Alexander Vakrilov

Lázaro Danillo Menezes

Jofferson Ramirez Tiquez

Ravi

Samuel Ikechukwu

Stanimira Vlaeva