-
-
Save iSnakeBuzz/2bc36a650e2e8c4318bfb8497734003c 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment