Forked from hirbod/withDisableForcedDarkModeAndroid.js
Created
February 19, 2025 09:24
-
-
Save RodolfoSilva/946feed97bdc595d92cb9ebd4a88455b to your computer and use it in GitHub Desktop.
Expo Config Plugin to disable forced Dark mode.
This file contains hidden or 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 | |
// 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