Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RodolfoSilva/946feed97bdc595d92cb9ebd4a88455b to your computer and use it in GitHub Desktop.
Save RodolfoSilva/946feed97bdc595d92cb9ebd4a88455b to your computer and use it in GitHub Desktop.
Expo Config Plugin to disable forced Dark mode.
// disable forced dark mode to prevent weird color changes
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createRunOncePlugin, withAndroidStyles, AndroidConfig } = require('expo/config-plugins')
function setForceDarkModeToFalse(styles) {
const newStyles = AndroidConfig.Styles.assignStylesValue(styles, {
add: true,
// ############# FOLLOW IF YOU'RE ON SDK 52 #############
// TODO: AndroidConfig.Styles.getAppThemeGroup() will be available in SDK 52 (or expo/config-plugins 9+), for now I just hardcoded AppTheme
// parent: AndroidConfig.Styles.getAppThemeGroup(),
parent: { name: 'AppTheme' },
name: `android:forceDarkAllowed`,
value: 'false',
})
return newStyles
}
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