npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nativescript-dark-mode

v1.0.0

Published

Dark Mode

Downloads

4

Readme

Dark Mode / Night Mode

⚠️️ This NativeScript plugin may become obsolete in the near future, because the awesome NativeScript team is working on built-in support for Dark Mode (and much more). If you're interested, subscribe to this issue.

Build Status Twitter Follow

What's this all about?

With iOS 13 comes a new Dark Mode which Apple would like you (as a developer) to adopt. Even more, iOS will actively alter the appearance of your app's native UI components, so you will be affected by this change.

So to be able to load different CSS, images, or other assets when Dark Mode is enabled, you need some sort of property you can check and a notification when Dark Mode is enabled/disabled by the user in the phone's settings.

That's where this plugin comes in.

Note that as long as you don't build with Xcode 11, even devices running iOS 13 will not be affected.

By the way, Android has had "Night Mode" support since API level 8, but it's up to the vendors to expose it properly to users. NativeScript-Android apps are not affected by this setting, but you might as well apply the same logic to Android's Night Mode as you do to iOS' Dark Mode, so this plugin unifies those APIs.

Installation

tns plugin add nativescript-dark-mode

Demo app

If you're stuck or want a quick demo of how this works, check out the demo app:

git clone https://github.com/EddyVerbruggen/nativescript-dark-mode
cd nativescript-dark-mode/src
npm run demo.ios # or demo.android

API

isDarkModeSupported

Dark Mode was added in iOS 13, so you could check this function. It's not required as the plugin will take care of this check internally when the other API functions are called.

import { isDarkModeSupported } from "nativescript-dark-mode";

const supported: boolean = isDarkModeSupported();

isDarkModeEnabled

If at any moment you want to check for Dark Mode being enabled, you can do:

import { isDarkModeEnabled } from "nativescript-dark-mode";

const darkModeEnabled: boolean = isDarkModeEnabled();

addOnDarkModeChangedListener

To get a notification while your app is running, you can register a listener with the plugin.

If you want to get notified on app launch as well, make sure to do this before the app starts. As an example, see app.ts in the demo folder in this repo.

import { addOnDarkModeChangedListener } from "nativescript-dark-mode";

addOnDarkModeChangedListener((isDarkMode: boolean) => {
  console.log("Now on dark mode? " + isDarkMode);
});

setDarkModeStyleSheet (unstable)

⚠️ This feature will probably be removed in an upcoming version, because we'll likely have a better (built-in) way soon.

If you want to load a different stylesheet when Dark Mode is enabled, then look no further. There is one caveat though: currently, the stylesheet is only applied on a cold start, so if the user switched to Dark Mode while the app is running, your app won't be affected until the next restart.

import { setDarkModeStyleSheet } from "nativescript-dark-mode";

setDarkModeStyleSheet("./app-dark.css");

TIP: you can extract all theme-independent CSS in app.css to app-common.css and add an app-dark.css that (just like app.css) extends app-common.css. Check the demo folder in this repo for an example.