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

@micahlt/capacitor-dark-mode

v1.0.4

Published

Handle dark mode changes on android and iOS

Downloads

247

Readme

Ionic Capacitor Dark Mode

For detailed tutorial on how to enable dark mode using this plugin visit: https://medium.com/@hinddeep.purohit007/supporting-dark-mode-in-ionic-capacitor-8e57fe9dbd47

Platforms Supported: Android, iOS, Electron and Web/PWA

This plugin can be used to monitor the changes made to system's dark mode.

Installation

npm install capacitor-dark-mode

Android Configuration:

  1. Open AndroidManifest.xml and find the activity tag.
  2. Inspect android:configChanges="..."
  3. If you find uiMode, please remove it. If it isn't present you can move on safely without doing anything.

Open MainActivity.java and add the following code inside this.init() registerPlugin(DarkMode.class); Adding the above mentioned line will add the following import statement: import com.bkon.capacitor.DarkMode.DarkMode; If you encounter errors, please add both the lines manually to MainActivity.java

iOS Configuration:

In the native ios project you will find two modules namely, 'App' and 'Pods'

  1. Select Pods
  2. Expand 'Development Pods'
  3. Expand 'Capacitor' and open 'CAPBridgeViewController.swift'
  4. Scroll to the very end of the file and paste the following method public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { if #available(iOS 13.0, *) { if self.traitCollection.userInterfaceStyle.rawValue != previousTraitCollection?.userInterfaceStyle.rawValue { var darkmode = ["isDarkModeOn":false] if self.traitCollection.userInterfaceStyle.rawValue == 2 { darkmode = ["isDarkModeOn":true] } else { darkmode = ["isDarkModeOn":false] } NotificationCenter.default.post(name: NSNotification.Name(rawValue: "CAPDarkModeDidChange"), object: self, userInfo: darkmode ) } else { // No Change } } else { // Fallback on earlier versions } }

Web Configuration

import { Plugins } from '@capacitor/core'; const { DarkMode } = Plugins import 'capacitor-dark-mode'

SPECIAL NOTE: Remove the import " import 'capacitor-dark-mode' " when building the app for Android and iOS. THe native plugin will not be invoked if you forget to remove the import statement before building for Android and iOS Platform.

If you wish to listen to system wide dark mode chamges on the web/PWA, add the following line to enable the listener: if(!(platform.is("android") || platform.is("ios"))) { DarkMode.registerDarkModeChangeListener() }

Listen for changes to Dark Mode:

The event listener might run outside the zone of angular so we might have to trigger change detection ourselves. That is why changedetectorref.detectChanges() has been used. DarkMode.addListener("darkModeStateChanged", (state: any) => { if(state.isDarkModeOn) { // Dark mode is on. Apply dark theme to your app changedetectorref.detectChanges() } else { // Dark mode is off. Apply light theme to your app changedetectorref.detectChanges() } if(state.supported == false) { // Dark mode is not supported by the platform
changedetectorref.detectChanges() }
});

Check if dark mode is enabled or not:

let darkmode = await DarkMode.isDarkModeOn(); console.log(darkmode.isDarkModeOn);