Last active
December 1, 2021 14:47
-
-
Save hamzabasrai/8407cc03c9ae0b358957a7cb5b45ea16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const matchDarkMode = window.matchMedia("(prefers-color-scheme: dark)"); | |
// event listener | |
matchDarkMode.addListener(() => { | |
const isDark = matchDarkMode.matches; | |
}); | |
// one time check | |
const isDark = matchDarkMode.matches; | |
// If you have a page that needs to render in light theme you can override the statusBar for that page. | |
// run in iOS app context only | |
StatusBar.setStyle({ style: StatusBarStyle.Light }); | |
// WARNING | |
// If on Capacitor <3.0 you can't reset the StatusBarStyle to Auto | |
// You'll need to manually handle the events and keep it up to date. | |
if (isDark) { | |
statusBarStyle = StatusBarStyle.Dark; | |
} else { | |
statusBarStyle = StatusBarStyle.Light; | |
} | |
if (isiOSApp) { | |
// TODO: Once we update to capacitor 3.0 we should have this clear the status bar style instead of setting it. | |
StatusBar.setStyle({ style: statusBarStyle }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment