Если вы хотите быть в dark mode
в evening
и light
в morning
, в зависимости от местного времени, вы можете:
var themColor = ""
var hours = new Date().getHours();
if (hours >20 || hours < 5) {
themColor = "dark"
} else {
themColor = "light"
}
const bannerContainerStyle = themColor === "dark" ? styles.mainContainerViewDark : styles.mainContainerViewLight;
Существуют способы получения иобрабатывать информацию о текущем местоположении через GPS, но я представлю простой метод. Получение и обработка информации о языке использования устройства.
Вы можете запустить
$ npm install --save react-native-localize
# --- or ---
$ yarn add react-native-localize
//Don't forget to run pod install after that !
Использование
import * as RNLocalize from "react-native-localize";
const localCode = RNLocalize.getLocales()
const countryCode = localCode.countryCode
if (countryCode === "IN" && hours >17 || countryCode === "IN" && hours < 5) {
themColor = "dark"
} else if (countryCode === "AU" && hours > 19 || countryCode === "AU" && hours < 5) {
themColor = "dark"
} else {
themColor = "light"
}