[Themes > Background] Improve patch
This commit is contained in:
parent
20310db733
commit
ffbb507125
1 changed files with 10 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { Theme, ThemeData } from "@types";
|
import { Theme, ThemeData } from "@types";
|
||||||
import { ReactNative, chroma } from "@metro/common";
|
import { ReactNative as RN, chroma } from "@metro/common";
|
||||||
import { findByName, findByProps } from "@metro/filters";
|
import { findByName, findByProps } from "@metro/filters";
|
||||||
import { instead } from "@lib/patcher";
|
import { instead, after } from "@lib/patcher";
|
||||||
import { createFileBackend, createMMKVBackend, createStorage, wrapSync, awaitSyncWrapper } from "@lib/storage";
|
import { createFileBackend, createMMKVBackend, createStorage, wrapSync, awaitSyncWrapper } from "@lib/storage";
|
||||||
import { safeFetch } from "@utils";
|
import { safeFetch } from "@utils";
|
||||||
|
|
||||||
|
@ -20,24 +20,24 @@ async function writeTheme(theme: Theme | {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function patchChatBackground() {
|
export function patchChatBackground() {
|
||||||
const currentTheme = getCurrentTheme()?.data?.background;
|
const currentBackground = getCurrentTheme()?.data?.background;
|
||||||
if (!currentTheme) return;
|
if (!currentBackground) return;
|
||||||
|
|
||||||
const MessagesWrapperConnected = findByName("MessagesWrapperConnected", false);
|
const MessagesWrapperConnected = findByName("MessagesWrapperConnected", false);
|
||||||
if (!MessagesWrapperConnected) return;
|
if (!MessagesWrapperConnected) return;
|
||||||
|
|
||||||
return instead("default", MessagesWrapperConnected, (args, orig) => React.createElement(ReactNative.ImageBackground, {
|
return after("default", MessagesWrapperConnected, (_, ret) => React.createElement(RN.ImageBackground, {
|
||||||
style: { flex: 1, height: "100%" },
|
style: { flex: 1, height: "100%" },
|
||||||
source: { uri: currentTheme.url },
|
source: { uri: currentBackground.url },
|
||||||
blurRadius: currentTheme.blur,
|
blurRadius: currentBackground.blur,
|
||||||
children: orig(...args),
|
children: ret,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeToHex(colorString: string): string {
|
function normalizeToHex(colorString: string): string {
|
||||||
if (chroma.valid(colorString)) return chroma(colorString).hex();
|
if (chroma.valid(colorString)) return chroma(colorString).hex();
|
||||||
|
|
||||||
const color = Number(ReactNative.processColor(colorString));
|
const color = Number(RN.processColor(colorString));
|
||||||
|
|
||||||
return chroma.rgb(
|
return chroma.rgb(
|
||||||
color >> 16 & 0xff, // red
|
color >> 16 & 0xff, // red
|
||||||
|
@ -66,7 +66,7 @@ function processData(data: ThemeData) {
|
||||||
data.rawColors[key] = normalizeToHex(rawColors[key]);
|
data.rawColors[key] = normalizeToHex(rawColors[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ReactNative.Platform.OS === "android") applyAndroidAlphaKeys(rawColors);
|
if (RN.Platform.OS === "android") applyAndroidAlphaKeys(rawColors);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|
Loading…
Reference in a new issue