From 9648adb63c1cb89b28619abb86f319630a8fdef2 Mon Sep 17 00:00:00 2001 From: Whitewater Date: Thu, 24 Apr 2025 16:44:48 +0800 Subject: [PATCH] fix(mobile): add day/night theme plugin for Android styling (#3572) --- apps/mobile/app.config.ts | 1 + .../with-android-day-night-theme-plugin.js | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 apps/mobile/plugins/with-android-day-night-theme-plugin.js diff --git a/apps/mobile/app.config.ts b/apps/mobile/app.config.ts index 1a2bc44f0..b5aba3954 100644 --- a/apps/mobile/app.config.ts +++ b/apps/mobile/app.config.ts @@ -148,6 +148,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({ ], require("./plugins/with-follow-app-delegate.js"), require("./plugins/with-gradle-jvm-heap-size-increase.js"), + require("./plugins/with-android-day-night-theme-plugin.js"), "expo-secure-store", "@react-native-firebase/app", "@react-native-firebase/crashlytics", diff --git a/apps/mobile/plugins/with-android-day-night-theme-plugin.js b/apps/mobile/plugins/with-android-day-night-theme-plugin.js new file mode 100644 index 000000000..200bc50da --- /dev/null +++ b/apps/mobile/plugins/with-android-day-night-theme-plugin.js @@ -0,0 +1,30 @@ +// Ported from https://github.com/bluesky-social/social-app/blob/a770f5635b549f2a87ffeaedd031dfe8e37b58c8/plugins/withAndroidDayNightThemePlugin.js +// Licensed under the MIT License + +// Based on https://github.com/expo/expo/pull/33957 +// Could be removed once the app has been updated to Expo 53 +const { withAndroidStyles } = require("@expo/config-plugins") + +module.exports = function withAndroidDayNightThemePlugin(appConfig) { + const cleanupList = new Set([ + "colorPrimary", + "android:editTextBackground", + "android:textColor", + "android:editTextStyle", + ]) + + return withAndroidStyles(appConfig, (config) => { + config.modResults.resources.style = config.modResults.resources.style + ?.map((style) => { + if (style.$.name === "AppTheme" && style.item != null) { + style.item = style.item.filter((item) => !cleanupList.has(item.$.name)) + } + return style + }) + .filter((style) => { + return style.$.name !== "ResetEditText" + }) + + return config + }) +}