fix(ChatboxAvatar): deduplicate patches, add live position switching
- Guard against double-patching when ChatInputActions and ChatInputSendButton resolve to the same component - Always patch both targets but conditionally render avatar based on position setting, so changes apply without restart
This commit is contained in:
parent
7b0e6d68f6
commit
b2233e9bcf
1 changed files with 22 additions and 6 deletions
|
|
@ -106,10 +106,12 @@ export default {
|
||||||
plugin.storage[key] = plugin.storage[key] ?? defaults[key];
|
plugin.storage[key] = plugin.storage[key] ?? defaults[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChatInputActions) {
|
const actionsTarget = ChatInputActions?.type || ChatInputActions;
|
||||||
const target = ChatInputActions.type || ChatInputActions;
|
const sendTarget = ChatInputSendButton?.type || ChatInputSendButton;
|
||||||
|
|
||||||
|
if (actionsTarget && actionsTarget !== sendTarget) {
|
||||||
patches.push(
|
patches.push(
|
||||||
after("render", target, (args, ret) => {
|
after("render", actionsTarget, (args, ret) => {
|
||||||
const position = getSetting("position", "after_actions");
|
const position = getSetting("position", "after_actions");
|
||||||
if (position === "near_send") return ret;
|
if (position === "near_send") return ret;
|
||||||
return (
|
return (
|
||||||
|
|
@ -123,10 +125,9 @@ export default {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChatInputSendButton) {
|
if (sendTarget && sendTarget !== actionsTarget) {
|
||||||
const target = ChatInputSendButton.type || ChatInputSendButton;
|
|
||||||
patches.push(
|
patches.push(
|
||||||
after("render", target, (args, ret) => {
|
after("render", sendTarget, (args, ret) => {
|
||||||
const position = getSetting("position", "after_actions");
|
const position = getSetting("position", "after_actions");
|
||||||
if (position !== "near_send") return ret;
|
if (position !== "near_send") return ret;
|
||||||
return (
|
return (
|
||||||
|
|
@ -138,6 +139,21 @@ export default {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actionsTarget && actionsTarget === sendTarget) {
|
||||||
|
patches.push(
|
||||||
|
after("render", actionsTarget, (args, ret) => {
|
||||||
|
const position = getSetting("position", "after_actions");
|
||||||
|
return (
|
||||||
|
<View style={{ flexDirection: "row", alignItems: "center" }}>
|
||||||
|
{position === "before_actions" && <AvatarAction />}
|
||||||
|
{ret}
|
||||||
|
{(position === "after_actions" || position === "near_send") && <AvatarAction />}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
for (const unpatch of patches) {
|
for (const unpatch of patches) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue