cordova-plugin-auto-theme

1.0.3 • Public • Published

cordova-plugin-auto-theme

Android only (See below for how to accomplish the same on iOS without any plugins)

A Cordova plugin for detecting if dark mode is enabled on Android, and listening for changes to device theme. Only works on Android 9+, so make sure to check the Android version in your code.

Install

cordova plugin add cordova-plugin-auto-theme

Usage

//get current device theme
AutoTheme.getTheme(function(isdark) {
     console.log("Is dark mode: "+isdark)
})

Events

//called whenever theme changes
window.onThemeChange = function(isdark) {
    console.log("Dark mode changed. Is dark mode: "+isdark)
}

How to detect dark mode on iOS

You don't need any plugins to check the current device theme and respond to changes to theme on iOS devices.

//get current device theme (ios)
var isdark = window.matchMedia('(prefers-color-scheme:dark)').matches;
//called whenever theme changes (ios)
window.matchMedia('(prefers-color-scheme:dark)').addListener(function() {
     var isdark = window.matchMedia('(prefers-color-scheme:dark)').matches;
});

Package Sidebar

Install

npm i cordova-plugin-auto-theme

Weekly Downloads

30

Version

1.0.3

License

MIT

Unpacked Size

6.41 kB

Total Files

6

Last publish

Collaborators

  • terren