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];
|
||||
}
|
||||
|
||||
if (ChatInputActions) {
|
||||
const target = ChatInputActions.type || ChatInputActions;
|
||||
const actionsTarget = ChatInputActions?.type || ChatInputActions;
|
||||
const sendTarget = ChatInputSendButton?.type || ChatInputSendButton;
|
||||
|
||||
if (actionsTarget && actionsTarget !== sendTarget) {
|
||||
patches.push(
|
||||
after("render", target, (args, ret) => {
|
||||
after("render", actionsTarget, (args, ret) => {
|
||||
const position = getSetting("position", "after_actions");
|
||||
if (position === "near_send") return ret;
|
||||
return (
|
||||
|
|
@ -123,10 +125,9 @@ export default {
|
|||
);
|
||||
}
|
||||
|
||||
if (ChatInputSendButton) {
|
||||
const target = ChatInputSendButton.type || ChatInputSendButton;
|
||||
if (sendTarget && sendTarget !== actionsTarget) {
|
||||
patches.push(
|
||||
after("render", target, (args, ret) => {
|
||||
after("render", sendTarget, (args, ret) => {
|
||||
const position = getSetting("position", "after_actions");
|
||||
if (position !== "near_send") return ret;
|
||||
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() {
|
||||
for (const unpatch of patches) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue