Giter Site home page Giter Site logo

nativescript-themes's Introduction

npm npm npm

nativescript-themes

A NativeScript plugin to deal with dynamically loading UI Themes

Installation

NativeScript 2.x

tns plugin add [email protected]

NativeScript 5.x

tns plugin add nativescript-themes

Status:

This plugin works in NativeScript 2.x and 5.x. It does NOT work in v3 or v4.

License

This is released under the MIT License, meaning you are free to include this in any type of program

Sample Snapshot

Sample1

Usage

To use the module you just require() it:

var themes = require('nativescript-themes');

Setup in App

Modify your startup app.js

var themes = require('nativescript-themes');
themes.applyTheme(themes.getAppliedTheme('red-theme.css'));

This will automatically apply the "red-theme.css" theme if no other theme has ever been chosen as the default theme.

You can also load a theme bundled by webpack using applyThemeCss:

var themes = require('nativescript-themes');
var cssText = require('~/assets/themes/dark.scss');
themes.applyThemeCss(cssText, 'dark.scss');

You ask, how exactly does this help?

This allows you to dynamically theme an application just by calling the theme system. Your master app.css file is applied first, then the theme file and finally your page.css

red-theme.css

button {
    background-color: red;
}

green-theme.css

button {
    background-color: green;
}

Demo

Demo shows three sample themes, and shows how to load the last chosen theme at startup.

Why use this?

This allows you to apply a specific theme file globally so all pages get it.

themes.applyTheme('cssFile', options);

options.noSave = true, this will cause it not to save this info for the getAppliedTheme to retrieve, this would typically used if you needed temporarily apply a theme.

var themes = require('nativescript-themes');
themes.applyTheme('red-theme.css');

theme.getAppliedTheme(<default_theme>);

This returns the last theme applied; if no theme has been applied it will use the default_theme.

var themes = require('nativescript-themes');
var currentTheme = themes.getAppliedTheme('red-theme.css');
if (currentTheme === 'red-theme.css') {
    console.log('We are using the default red-theme!');
} else {
    console.log('We are using', currentTheme);
}

themes.applyThemeCss('textCss', 'filename');

This function receives a string containing CSS and applies it. The filename is only for reference (no file will be actually loaded).

var themes = require('nativescript-themes');
themes.applyThemeCss('page {background-color: black;}', 'default-theme.css');

Tutorials

Need some extra help getting started? Check out these tutorials for dealing with NativeScript UI themes in an iOS and Android application.

Contributors:

  • Brad Martin
  • Tiago Alves

nativescript-themes's People

Contributors

bundyo avatar farfromrefug avatar nathanaela avatar nraboy avatar tralves avatar

Watchers

 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.