简体   繁体   English

如何在 iOS 的原生反应中动态地将亮模式更改为暗模式?

[英]how do I dynamically change light mode to dark mode in react native in iOS?

So I have a react native in iOS, and I have implemented dark and light mode in that.所以我在 iOS 中有一个原生的反应,我已经实现了暗和亮模式。 I need that theme to change based on the light or dark mode in my iPhone.我需要根据 iPhone 中的明暗模式更改该主题。 It should change dynamically.它应该动态变化。 Any idea how I should go about this?知道我应该怎么做吗?

Use Context API or Redux Library for them in react native app.在 react native 应用程序中为它们使用 Context API 或 Redux 库。 create a global object having colors, background colors for theme, then use throghtout the app.创建一个具有颜色、主题背景颜色的全局对象,然后使用 throghtout 应用程序。

import { Appearance } from 'react-native';

const colorScheme = Appearance.getColorScheme();
if (colorScheme === 'dark') {
  // Use dark color scheme
} else {
  // Use light color scheme
}

Appearance provide information about the user's appearance preferences, such as their preferred color scheme (light or dark).外观提供有关用户外观偏好的信息,例如他们的首选配色方案(浅色或深色)。 You can use it to change app color scheme.您可以使用它来更改应用程序配色方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM