I know this is possible using Swift:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if traitCollection.userInterfaceStyle == .light {
print("Light mode")
} else {
print("Dark mode")
}
}
However, is there a way of doing this with JavaScript ?
We watch the prefers-color-scheme CSS media feature to detect dark mode on the system setting level or browser setting level: window. matchMedia('(prefers-color-scheme: dark)') . addEventListener('change', event => { const colorScheme = event.
Dark mode can be detected by using the userInterfaceStyle property on the current trait collection. When it's set to dark you know that the current appearance is set to dark.
You don't need react-native-dark-mode
since 0.62.2.
You can use
import { Appearance } from 'react-native'
...
Appearance.getColorScheme() === 'dark'
Here's a commit that adds it: https://github.com/facebook/react-native/commit/63fa3f21c5ab308def450bffb22054241a8842ef
Yes...
https://www.npmjs.com/package/react-native-dark-mode
OR
https://github.com/codemotionapps/react-native-dark-mode
import { useDarkMode } from 'react-native-dark-mode'
function Component() {
const isDarkMode = useDarkMode()
return <View style={{ backgroundColor: isDarkMode ? 'black' : 'white' }} />
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With