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.
This commit is contained in:
parent
8dcf5f2f34
commit
0fd85aa531
4 changed files with 94 additions and 9 deletions
|
|
@ -77,7 +77,7 @@ const config = {
|
|||
constModules: {
|
||||
globals: {
|
||||
"bunny-build-info": {
|
||||
version: `"1.1.8"`,
|
||||
version: `"1.1.8-1"`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
||||
|
|
|
|||
64
src/lib/addons/themes/colors/keyboard.ts
Normal file
64
src/lib/addons/themes/colors/keyboard.ts
Normal file
|
|
@ -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?.(() => {});
|
||||
}
|
||||
|
|
@ -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() {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue