Skip to content

Instantly share code, notes, and snippets.

@hirbod
Last active April 7, 2026 03:06
Show Gist options
  • Select an option

  • Save hirbod/d6bb5d0fc946a12ba9e3cf01120c604a to your computer and use it in GitHub Desktop.

Select an option

Save hirbod/d6bb5d0fc946a12ba9e3cf01120c604a 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'
)
@hirbod

hirbod commented Mar 18, 2023

Copy link
Copy Markdown
Author

A simple

"./plugins/withDisableForcedDarkModeAndroid.js"

is enough. No need to put inside an array. Just tested today on a new project of mine.

@P0sseid0n

P0sseid0n commented Apr 8, 2023

Copy link
Copy Markdown

I have tried on the Poco F3 (SDK 47), but it does not work. This issue started before I updated to MIUI 14 - Android 13.

@chulanovskyi-bs

Copy link
Copy Markdown

Completely insane issue, makes me really mad that at the very start of the new project Expo forces you to eject to solve this 😡. Xiaomi Mi9T Pro, thanks for asking...

@hirbod

hirbod commented Apr 27, 2023

Copy link
Copy Markdown
Author

You don't need to eject, just use a custom dev-client!

@cecarmona

Copy link
Copy Markdown

This code works great! the perfect solution for my app. (using SDK 48)

@iSnakeBuzz

Copy link
Copy Markdown

it doesn't work for me :(

@HallexCosta

HallexCosta commented Jul 1, 2023

Copy link
Copy Markdown

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 the npx 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)?

@danbeo95

danbeo95 commented Jan 8, 2024

Copy link
Copy Markdown

Awesome
It work for me

@artkrv

artkrv commented May 2, 2024

Copy link
Copy Markdown

Worked for me too.

@willpower18

Copy link
Copy Markdown

Worked here, thanks for this.

@jimmi-joensson

Copy link
Copy Markdown

Worked, thanks!

@felippewick

felippewick commented Jan 22, 2025

Copy link
Copy Markdown

I'm using react-native-edge-to-edge in my app

changed the plugin accordingly

function setForceDarkModeToFalse(styles) {
  styles = AndroidConfig.Styles.assignStylesValue(styles, {
    add: true,
    parent: {
      name: 'AppTheme',
      parent: 'Theme.EdgeToEdge',
    },
    name: `android:forceDarkAllowed`,
    value: 'false',
  });

My styles.xml looks like this but forceDarkAllowed: false is not applied.

<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.EdgeToEdge">
  <item name="android:textColor">@android:color/black</item>
  <item name="android:editTextStyle">@style/ResetEditText</item>
  <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
  <item name="colorPrimary">@color/colorPrimary</item>
  <item name="android:windowLightStatusBar">true</item>
  <item name="android:forceDarkAllowed">false</item>
</style>
<style name="ResetEditText" parent="@android:style/Widget.EditText">
  <item name="android:padding">0dp</item>
  <item name="android:textColorHint">#c8c8c8</item>
  <item name="android:textColor">@android:color/black</item>
</style>
<style name="Theme.App.SplashScreen" parent="AppTheme">
  <item name="android:windowBackground">@drawable/splashscreen</item>
</style>
<style name="BootTheme" parent="Theme.BootSplash">
  <item name="postBootSplashTheme">@style/AppTheme</item>
  <item name="bootSplashBackground">@color/bootsplash_background</item>
  <item name="bootSplashLogo">@drawable/bootsplash_logo</item>
</style>
</resources>

@hirbod

hirbod commented Jan 22, 2025

Copy link
Copy Markdown
Author

Sorry, here is the updated file which works with EdgeToEdge @felippewick

// 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,
    // 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'
)

If you're on SDK52, you can change the TODO

@hirbod

hirbod commented Jan 22, 2025

Copy link
Copy Markdown
Author

Updated the gist

@Hosam-hsm

Hosam-hsm commented Mar 10, 2025

Copy link
Copy Markdown
<resources xmlns:tools="http://schemas.android.com/tools">
  <style name="AppTheme" parent="Theme.EdgeToEdge">
    <item name="android:textColor">@android:color/black</item>
    <item name="android:editTextStyle">@style/ResetEditText</item>
    <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="android:forceDarkAllowed">false</item>
    <item name="android:windowLightStatusBar">true</item>
    <item name="android:windowLightNavigationBar">false</item>
    <item name="enforceNavigationBarContrast">false</item>
  </style>
  <style name="ResetEditText" parent="@android:style/Widget.EditText">
    <item name="android:padding">0dp</item>
    <item name="android:textColorHint">#c8c8c8</item>
    <item name="android:textColor">@android:color/black</item>
  </style>
  <style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/splashscreen_background</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/splashscreen_logo</item>
    <item name="postSplashScreenTheme">@style/AppTheme</item>
  </style>
</resources>

@hirbod forceDarkAllowed is being copied to the styles.xml file. But it is not being applied in the build. Using expo android release build.
Splash screen (background color given as white using expo-splash-screen plugin) is still showing a black background when in dark mode.

I have given userInterfaceStyle: light in app.config.ts

I tried applying false under Theme.App.SplashScreen, still same result. I am testing in a Redmi phone. Any help?

@artkrv

artkrv commented May 21, 2025

Copy link
Copy Markdown

Same issues with 53 splash screen. Does any one prevented dark mode for splash screen.

@danielshin

Copy link
Copy Markdown

Try installing "expo-system-ui" if you haven't, apparently it's required to enable "userInterfaceStyle". https://docs.expo.dev/develop/user-interface/color-themes/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment