From 0fd85aa5319db04c43ff9998a38f7945960609ae Mon Sep 17 00:00:00 2001 From: kmmiio99o <164557248+kmmiio99o@users.noreply.github.com> Date: Sat, 1 Nov 2025 22:02:35 +0100 Subject: [PATCH] feat: Fix keyboard and status bar color on iOS This commit adds a fix for the keyboard and status bar color on iOS. It also renames fix.ts to statusbar.ts and updates the version string. --- scripts/build.mjs | 2 +- src/lib/addons/themes/colors/index.ts | 4 +- src/lib/addons/themes/colors/keyboard.ts | 64 +++++++++++++++++++ .../themes/colors/{fix.ts => statusbar.ts} | 33 ++++++++-- 4 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 src/lib/addons/themes/colors/keyboard.ts rename src/lib/addons/themes/colors/{fix.ts => statusbar.ts} (55%) diff --git a/scripts/build.mjs b/scripts/build.mjs index 1a7dda3..6bcdb6d 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -77,7 +77,7 @@ const config = { constModules: { globals: { "bunny-build-info": { - version: `"1.1.8"`, + version: `"1.1.8-1"`, }, }, }, diff --git a/src/lib/addons/themes/colors/index.ts b/src/lib/addons/themes/colors/index.ts index 9e49a89..8085e87 100644 --- a/src/lib/addons/themes/colors/index.ts +++ b/src/lib/addons/themes/colors/index.ts @@ -1,4 +1,5 @@ -import fixStatusBar from "./fix"; +import fixStatusBar from "./statusbar"; +import fixKeyboard from "./keyboard"; import patchChatBackground from "./patches/background"; import patchDefinitionAndResolver from "./patches/resolver"; import patchStorage from "./patches/storage"; @@ -14,6 +15,7 @@ export default function initColors(manifest: ColorManifest | null) { ]; fixStatusBar(); + fixKeyboard(); if (manifest) updateBunnyColor(manifest, { update: false }); diff --git a/src/lib/addons/themes/colors/keyboard.ts b/src/lib/addons/themes/colors/keyboard.ts new file mode 100644 index 0000000..d3e4987 --- /dev/null +++ b/src/lib/addons/themes/colors/keyboard.ts @@ -0,0 +1,64 @@ +import { TextInput, Platform, NativeModules } from "react-native"; +import { findByStoreNameLazy } from "@metro/wrappers"; +import { _colorRef } from "./updater"; + +const ThemeStore = findByStoreNameLazy("ThemeStore"); + +function getKeyboardAppearance() { + // Check for custom theme + const custom = _colorRef.current; + if (custom) { + // Bunny theme (spec 3) + if (custom.spec === 3 && custom.reference) { + return custom.reference === "light" ? "light" : "dark"; + } + // Vendetta theme (spec 2) + if (custom.spec === 2 && custom.reference) { + return custom.reference === "light" ? "light" : "dark"; + } + } + + // Fallback to Discord theme string + const theme = ThemeStore?.theme; + if (typeof theme === "string") { + const lowerTheme = theme.toLowerCase(); + return (lowerTheme.includes("dark") || lowerTheme.includes("midnight")) + ? "dark" + : "light"; + } + + return "dark"; +} + +export default function fixKeyboard() { + if (Platform.OS !== "ios") return; + + const UIManager = NativeModules.UIManager; + + const origUpdateView = UIManager?.updateView; + const origCreateView = UIManager?.createView; + + if (origUpdateView) { + UIManager.updateView = function(viewTag: number, viewName: string, props: any) { + if (props && typeof props === 'object') { + if (viewName.toLowerCase().includes('text') || viewName.toLowerCase().includes('input')) { + props.keyboardAppearance = getKeyboardAppearance(); + } + } + return origUpdateView.call(this, viewTag, viewName, props); + }; + } + + if (origCreateView) { + UIManager.createView = function(reactTag: number, viewName: string, rootTag: number, props: any) { + if (props && typeof props === 'object') { + if (viewName.toLowerCase().includes('text') || viewName.toLowerCase().includes('input')) { + props.keyboardAppearance = getKeyboardAppearance(); + } + } + return origCreateView.call(this, reactTag, viewName, rootTag, props); + }; + } + + return ThemeStore?.addChangeListener?.(() => {}); +} diff --git a/src/lib/addons/themes/colors/fix.ts b/src/lib/addons/themes/colors/statusbar.ts similarity index 55% rename from src/lib/addons/themes/colors/fix.ts rename to src/lib/addons/themes/colors/statusbar.ts index 9099c07..22f0f38 100644 --- a/src/lib/addons/themes/colors/fix.ts +++ b/src/lib/addons/themes/colors/statusbar.ts @@ -1,4 +1,4 @@ -import { StatusBar } from "react-native"; +import { StatusBar, TextInput, Platform } from "react-native"; import { findByStoreNameLazy } from "@metro/wrappers"; import { _colorRef } from "./updater"; @@ -29,10 +29,29 @@ function getBarStyle() { } export default function fixStatusBar() { - const origSetBarStyle = StatusBar.setBarStyle; - StatusBar.setBarStyle = function (_style: any, ...args: any[]) { - return origSetBarStyle.call(this, getBarStyle(), ...args); - }; - StatusBar.setBarStyle(getBarStyle()); -} \ No newline at end of file + if (Platform.OS == "android") { + const origSetBarStyle = StatusBar.setBarStyle; + StatusBar.setBarStyle = function (_style: any, ...args: any[]) { + return origSetBarStyle.call(this, getBarStyle(), ...args); + }; + } + + if (Platform.OS == "ios") { + function applyStatusBar() { + const style = getBarStyle(); + StatusBar.setBarStyle(style, true); + } + + const unsubscribe = ThemeStore?.addChangeListener?.(applyStatusBar); + + StatusBar.setBarStyle(getBarStyle()); + + let delay = 200; + for (let i = 0; i < 5; i++, delay *= 2) { + setTimeout(applyStatusBar, delay); + } + + return unsubscribe; + } +}