⚠️ ️ 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.
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 ofproperty 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.
tns plugin add nativescript-dark-mode
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
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
toapp-common.css
and add anapp-dark.css
that (just likeapp.css
) extendsapp-common.css
. Check the demo folder in this repo for an example.
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en
概览 自动更新原生界面 "本地界面"包括文件选择器、窗口边框、对话框、上下文 菜单等 - 任何UI来自操作系统而非应用的界面。 默认行为是从操作系统选择自动主题。 自动更新您自己的界面 如果您的应用有自己的黑暗模式,您应该在与系统黑暗模式设置同步时切换。 您可以通过使用[prefer-color-scheme] CSS 媒体查询来做到这一点。 手动更新您自己的界面 If you want to m
dark-mode Control the macOS dark mode from the command-line Requires macOS 10.10 or later. macOS 10.13 or earlier needs to download the Swift runtime support libraries. Install Homebrew $ brew install
Dark Oberon《黑暗奥伯龙》是一个类似“魔兽争霸 2”(Warcraft II) 的开源即时战略游戏。憨厚的画面和经典的玩法可以让你重温当初玩同类游戏的感受,游戏在PC平台和linux平台都有相应的版本,精细的制作使这款休闲小 游戏值得一玩。 画 面: 游戏的画面风格独特,胶泥风格的游戏画面十分形象逼真,角色的动画也很流畅,对系统配置的要求也很低。各种鲜明的颜色和独特的风格会给你留下深刻的印 象...
Dark Exchange 是一个分布式的比特币的 P2P 交换项目,使用 Dart 语言编写。
Code in the Dark 是一个前端 (HTML, CSS) 竞赛编辑器,给出一个网站设计截图,选手根据这个截图来编写代码,没有预览功能,没有度量工具,最后的作品让观众决定谁是胜利者。 在线演示:http://codeinthedark.com/editor/
Dark Reader 是一个开源的浏览器扩展,旨在分析网页。根据其分析,Dark Reader 将生成一种旨在减少用户眼睛疲劳的黑暗模式。Dark Reader 功能丰富,可以在整个 UI 中以多种方式进行配置。 构建使用 安装 Node.js LTS,下载源代码(或从 git 中 check out)。 在根文件夹中打开终端并运行: npm install npm run build 这将生成