Fix background patching for chat messages component

This commit is contained in:
OTKUSteyler 2026-01-02 09:41:02 +00:00 • committed by GitHub
parent 262562f050
commit a7844b86e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,16 +8,16 @@ import chroma from "chroma-js";
import { ImageBackground, StyleSheet } from "react-native";
import { logger } from "@lib/utils/logger";
const Messages = findByFilePathLazy("components_native/chat/Messages.tsx", true);
const Messages = findByFilePathLazy("modules/messages/native/Messages.tsx", true);
function ThemeBackground({ children }: { children: React.ReactNode }) {
function ThemeBackground({ children }: { children: React.ReactNode; }) {
useObservable([colorsPref]);
if (!_colorRef.current
|| colorsPref.customBackground === "hidden"
|| !_colorRef.current.background?.url
|| _colorRef.current.background?.blur && (typeof _colorRef.current.background?.blur !== "number")
){
) {
return children;
}
@ -31,30 +31,35 @@ function ThemeBackground({ children }: { children: React.ReactNode }) {
}
export default function patchChatBackground() {
try {
const patches = [
after("render", Messages, (_, ret) => {
if (!_colorRef.current || !_colorRef.current.background?.url) return;
const messagesComponent = findInReactTree(
ret,
x => x && "HACK_fixModalInteraction" in x.props && x?.props?.style
);
after("render", Messages, (_, ret) => {
if (!_colorRef.current || !_colorRef.current.background?.url) return;
if (messagesComponent) {
const flattened = StyleSheet.flatten(messagesComponent.props.style);
const backgroundColor = chroma(
flattened.backgroundColor || "black"
).alpha(
1 - (_colorRef.current.background?.opacity ?? 1)
).hex();
const messagesComponent = findInReactTree(
ret,
x => x && "HACK_fixModalInteraction" in x.props && x?.props?.style
);
messagesComponent.props.style = StyleSheet.flatten([
messagesComponent.props.style,
{ backgroundColor }
]);
}
if (messagesComponent) {
const flattened = StyleSheet.flatten(messagesComponent.props.style);
const backgroundColor = chroma(
flattened.backgroundColor || "black"
).alpha(
1 - (_colorRef.current.background?.opacity ?? 1)
).hex();
return <ThemeBackground>{ret}</ThemeBackground>;
})
messagesComponent.props.style = StyleSheet.flatten([
messagesComponent.props.style,
{ backgroundColor }
]);
}
return <ThemeBackground>{ret}</ThemeBackground>;
})
];
return () => patches.forEach(x => x());
} catch (e) {
}
}