Last active
May 15, 2024 00:00
-
-
Save hirbod/d6bb5d0fc946a12ba9e3cf01120c604a to your computer and use it in GitHub Desktop.
Expo Config Plugin to disable forced Dark mode.
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
// disable forced dark mode to prevent weird color changes on | |
// certain android devices (Xiaomi MIUI and others enforcing dark mode with view analyzing) | |
// create a file like "plugins/withDisableForcedDarkModeAndroid.js". Insert this content and edit your app.config.js/app.json | |
/* | |
"expo": { | |
... | |
... | |
... | |
"plugins": [ | |
..., | |
..., | |
'./plugins/withDisableForcedDarkModeAndroid.js' | |
] | |
*/ | |
const { | |
createRunOncePlugin, | |
withAndroidStyles, | |
AndroidConfig | |
} = require('@expo/config-plugins'); | |
function setForceDarkModeToFalse(styles) { | |
styles = AndroidConfig.Styles.assignStylesValue(styles, { | |
add: true, | |
parent: AndroidConfig.Styles.getAppThemeLightNoActionBarGroup(), | |
name: `android:forceDarkAllowed`, | |
value: "false", | |
}); | |
return styles; | |
} | |
const withDisableForcedDarkModeAndroid = (config) => { | |
return withAndroidStyles(config, (config) => { | |
config.modResults = setForceDarkModeToFalse(config.modResults); | |
return config; | |
}); | |
}; | |
module.exports = createRunOncePlugin(withDisableForcedDarkModeAndroid, 'disable-forced-dark-mode', '1.0.0'); |
Awesome
It work for me
Worked for me too.
Worked here, thanks for this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to remind you that plugin mods only run in the
expo prebuild
process, that is, for the changes to take effect it is necessary to generate an .APK (for testing) or .AAB (for playstore).I don't know why this setting doesn't apply to the expo client, I believe it's possible to generate the
.android
folder with thenpx expo prebuild
command and run it on any android emulator (without expo client), that might solve the problem :)Tested on Xiomi Redmi 9 it worked after building an
.apk
References:
How to works plugins and mods
React Native Expo Android Dark Mode issue
Problem when trying to disable dark mode on Android
How to disable night mode in my application even if night mode is enable in android 9.0 (pie)?