我知道使用Swift可以做到这一点:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if traitCollection.userInterfaceStyle == .light {
print("Light mode")
} else {
print("Dark mode")
}
}
但是,有没有办法用JavaScript做到这一点?
最佳答案
从0.62.2开始,您就不需要react-native-dark-mode
了。
您可以使用
import { Appearance } from 'react-native'
...
Appearance.getColorScheme() === 'dark'
这是添加的提交:https://github.com/facebook/react-native/commit/63fa3f21c5ab308def450bffb22054241a8842ef
关于react-native - 使用React Native检测iPhone iOS暗模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56821513/