Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
terreng authored Aug 5, 2021
1 parent 1fd1235 commit 4a4d5fa
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cordova-plugin-auto-theme

**Android only**
**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.

Expand All @@ -22,3 +22,19 @@ 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.

```js
//get current device theme (ios)
var isdark = window.matchMedia('(prefers-color-scheme:dark)').matches;
```

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

0 comments on commit 4a4d5fa

Please sign in to comment.