Giter Club home page Giter Club logo

nativescript-ng-shadow's Introduction

NativeScript Angular Shadow Directive Plugin apple android

Build Status NPM version Downloads Twitter Follow

Installation

From the command prompt go to your app's root folder and execute:

tns plugin add nativescript-ng-shadow

Demo

If you want a quickstart, check out the demo app.

N|Solid N|Solid

How to use it

This is an Angular directive to make your life easier when it comes to native shadows.

Shadows are a very important part of Material design specification. It brings up the concept of elevation, which implies in the natural human way of perceiving objects raising up from the surface.

With this directive, you won't have to worry about all the aspects regarding shadowing on Android and on iOS. On the other hand, if you care about any details, just provide extra attributes and they will superseed the default ones.

Import the NgShadowModule

// ...
import { NgShadowModule } from 'nativescript-ng-shadow';

@NgModule({
    imports: [
        NgShadowModule,
        // ...
    ],
    // ...
})
export class MyModule { }

Just use in your templates

Simple attribute shadow:

<Label shadow="2"></Label>

Of course you can property bind it:

<Label [shadow]="myCustomShadow"></Label>

shadow is the directive itself and it doesn't reflect changes after the object is rendered. If you intend to change the elevation based on any event, you should use the elevation attribute:

<Label shadow [elevation]="myPotentiallyVolatileElevation"></Label>

There are a couple of platform specific attributes you might want to use to customize your view. Bare in mind some of them clash with CSS styles applied to the same views. When it happens, the default behaviour on Android is the original HTML/CSS styles are lost in favor of the ones provided by this directive. On iOS, on the other hand, HTML/CSS pre-existent styles are regarded, consequently the shadow might not be applied.

The tip is, avoid applying things like background color and border radius to the same view you intend to apply this directive. You are always able to nest views and get what you want. If not, please leave a message so we can try to help.

List of attributes

The table below list and describes all possible attributes as well as show which platform supports each one of them:

Attribute Type Platform Description
shadow string | number | AndroidData | IOSData both Directive attribute. Providing null or empty string with no elevation attribute, will switch off the shadow
elevation number | string both Determines the elevation of the view from the surface. It does all shadow related calculations. You might want to have a look at this enum of standard material design elevations.
shape string => 'RECTANGLE' | 'OVAL' | 'RING' | 'LINE' Android Determines the shape of the view and overrides its format styles.
bgcolor string => color #RGB Android Determines view's background color and overrides its previous background.
cornerRadius number Android Determines view's corner radius (CSS border-radius) and overrides its previous style.
maskToBounds boolean => default: false iOS Determines whether the shadow will be limited to the view margins.
shadowColor string => color #RGB iOS Determines shadow color. Shadow won't be applied if the view already has background.
shadowOffset number iOS Determines the distance (only on Y axis) of the shadow. Negative value shows the shadow above the view.
shadowOpacity number iOS From 0 to 1. Determines the opacity level of the shadow.
shadowRadius number iOS Determines the blurring effect of the shadow. The higher the more blurred.

AndroidData and IOSData

As you might have noticed the main shadow attribute accepts object as argument. You'll be able to assign it in a property bind and it will override any possible separate attribute you might have defined:

Component

import { AndroidData, ShapeEnum } from 'nativescript-ng-shadow';
// ...
export class MyComponent {
  fabShadow: AndroidData = {
    elevation: 6,
    bgcolor: '#ff1744',
    shape: ShapeEnum.OVAL,
  };
  // ...
}

In the template you can do:

<Label [shadow]="fabShadow" width="56" height="56"></Label>

Pre-defined elevations

If you want to be consistent with the Material Design specification but you're sick trying to memorize which elevation your view should have. We put together a list of pre-defined elevations:

  • SWITCH: 1
  • CARD_RESTING: 2
  • RAISED_BUTTON_RESTING: 2
  • SEARCH_BAR_RESTING: 2
  • REFRESH_INDICADOR: 3
  • SEARCH_BAR_SCROLLED: 3
  • APPBAR: 4
  • FAB_RESTING: 6
  • SNACKBAR: 6
  • BOTTOM_NAVIGATION_BAR: 8
  • MENU: 8
  • CARD_PICKED_UP: 8,
  • RAISED_BUTTON_PRESSED: 8
  • SUBMENU_LEVEL1: 9
  • SUBMENU_LEVEL2: 10
  • SUBMENU_LEVEL3: 11
  • SUBMENU_LEVEL4: 12
  • SUBMENU_LEVEL5: 13
  • FAB_PRESSED: 12
  • NAV_DRAWER: 16
  • RIGHT_DRAWER: 16
  • MODAL_BOTTOM_SHEET: 16
  • DIALOG: 24
  • PICKER: 24

If you don't even want to check it out every time you have to shadow a view, just import the Elevation enum and enjoy :)

Component

import { Elevation } from 'nativescript-ng-shadow';
class MyComponent {
  // ...
  ngOnInit(): init {
    this.mySnackBar.elevation = Elevation.SNACKBAR;
  }
  // ...
}

Changelog

  • 1.1.0 Support for iOS custom attributes
  • 1.0.0 Initial implementation

License

Apache License Version 2.0, January 2004

nativescript-ng-shadow's People

Contributors

berardo avatar

Watchers

James Cloos avatar Sharique Hasan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.