From e992612de644665382feda9fbba682e5b9e95b95 Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 1 Sep 2025 18:02:28 +0800 Subject: [PATCH] fix: present modal in modal exit animation will stuck - Updated modal animation styles to include perspective and z-index adjustments for improved depth perception. - Refactored modal component to apply 3D transform styles and ensure consistent animation behavior. - Modified MCPPresetCard and MCPPresetSelectionModal components to use new background styles for better visual consistency. Signed-off-by: Innei --- .../src/components/ui/modal/stacked/bus.ts | 8 +++-- .../components/ui/modal/stacked/constants.ts | 7 +++-- .../src/components/ui/modal/stacked/hooks.tsx | 3 +- .../ui/modal/stacked/internal/use-animate.ts | 31 +++++++++++++------ .../modal/stacked/internal/use-subscriber.ts | 2 +- .../src/components/ui/modal/stacked/modal.tsx | 11 +++++-- .../components/ui/modal/stacked/provider.tsx | 2 ++ .../settings/tabs/ai/mcp/MCPPresetCard.tsx | 2 +- .../tabs/ai/mcp/MCPPresetSelectionModal.tsx | 2 +- 9 files changed, 46 insertions(+), 22 deletions(-) diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/bus.ts b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/bus.ts index 72979102e..4c412a4f0 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/bus.ts +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/bus.ts @@ -1,10 +1,14 @@ import { createEventBus } from "@follow/utils/event-bus" export const ModalEventBus = createEventBus<{ - MODAL_DISPATCH: ModalDisposeEvent + DISMISS: ModalDisposeEvent + RE_PRESENT: ModalRePresentEvent }>() export type ModalDisposeEvent = { - type: "dismiss" + id: string +} + +export type ModalRePresentEvent = { id: string } diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/constants.ts b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/constants.ts index 9bf96f465..1cf899753 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/constants.ts +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/constants.ts @@ -2,12 +2,15 @@ import { Spring } from "@follow/components/constants/spring.js" import type { MotionProps, TargetAndTransition } from "motion/react" const enterStyle: TargetAndTransition = { - scale: 1, opacity: 1, + // Draw the modal towards the viewer from depth + transformPerspective: 1200, + z: 0, } const initialStyle: TargetAndTransition = { - scale: 0.96, opacity: 0, + transformPerspective: 1200, + z: -48, } export const modalMontionConfig = { diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/hooks.tsx b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/hooks.tsx index 4af26e5bd..d7172f0c5 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/hooks.tsx +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/hooks.tsx @@ -36,8 +36,7 @@ const actions = { return jotaiStore.get(modalStackAtom).find((item) => item.id === id) }, dismiss(id: string) { - ModalEventBus.dispatch("MODAL_DISPATCH", { - type: "dismiss", + ModalEventBus.dispatch("DISMISS", { id, }) }, diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/internal/use-animate.ts b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/internal/use-animate.ts index 719ff2cf5..734f131fd 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/internal/use-animate.ts +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/internal/use-animate.ts @@ -4,14 +4,12 @@ import { useAnimationControls } from "motion/react" import { useCallback, useEffect, useLayoutEffect } from "react" import { useEventCallback } from "usehooks-ts" +import { ModalEventBus } from "../bus" import { modalMontionConfig } from "../constants" export interface ModalAnimateControls { - /** Controller for modal animations */ animateController: ReturnType - /** Play notice animation when modal can't be dismissed */ playNoticeAnimation: () => void - /** Play exit animation and return promise that resolves when complete */ playExitAnimation: () => Promise } @@ -19,26 +17,37 @@ export interface ModalAnimateControls { * @internal * Hook for managing modal animations including enter, notice, and exit animations */ -export const useModalAnimate = (isTop: boolean): ModalAnimateControls => { +export const useModalAnimate = ( + isTop: boolean, + modalId: string, + setIsClosing: (isClosing: boolean) => void, +): ModalAnimateControls => { const animateController = useAnimationControls() // Initial enter animation useEffect(() => { + ModalEventBus.subscribe("RE_PRESENT", (data) => { + if (data.id !== modalId) { + return + } + setIsClosing(false) + animateController.start(modalMontionConfig.animate) + }) nextFrame(() => { animateController.start(modalMontionConfig.animate) }) - }, [animateController]) + }, [animateController, modalId, setIsClosing]) // Notice animation for when modal can't be dismissed const playNoticeAnimation = useCallback(() => { animateController .start({ - scale: 1.01, + z: 6, transition: Spring.snappy(0.06), }) .then(() => { animateController.start({ - scale: 1, + z: 0, }) }) }, [animateController]) @@ -47,14 +56,16 @@ export const useModalAnimate = (isTop: boolean): ModalAnimateControls => { useLayoutEffect(() => { if (isTop) return animateController.start({ - scale: 0.96, - y: 10, + z: -64, + rotateX: 2.5, + y: 8, }) return () => { try { animateController.stop() animateController.start({ - scale: 1, + z: 0, + rotateX: 0, y: 0, }) } catch { diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/internal/use-subscriber.ts b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/internal/use-subscriber.ts index f74625aa1..9d0c508f0 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/internal/use-subscriber.ts +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/internal/use-subscriber.ts @@ -6,7 +6,7 @@ import type { ModalActionsInternal } from "../context" /** @internal */ export const useModalSubscriber = (id: string, ctx: ModalActionsInternal) => { useEffect(() => { - return ModalEventBus.subscribe("MODAL_DISPATCH", (data) => { + return ModalEventBus.subscribe("DISMISS", (data) => { if (data.id === id) { ctx.dismiss() } diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx index 325043048..2ed04c361 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx @@ -91,7 +91,11 @@ export const ModalInternal = memo(function Modal({ const [isClosing, setIsClosing] = useState(false) // Animation controls - const { animateController, playNoticeAnimation, playExitAnimation } = useModalAnimate(!!isTop) + const { animateController, playNoticeAnimation, playExitAnimation } = useModalAnimate( + !!isTop, + item.id, + setIsClosing, + ) // Simple dismiss logic const close = useEventCallback(async (forceClose = false) => { @@ -105,7 +109,7 @@ export const ModalInternal = memo(function Modal({ // Custom modals handle their own animation setStack((p) => p.filter((modal) => modal.id !== item.id)) } else { - // Play exit animation then remove from stack + // Play exit animation then remove from stack\ await playExitAnimation() setStack((p) => p.filter((modal) => modal.id !== item.id)) } @@ -332,6 +336,7 @@ export const ModalInternal = memo(function Modal({ onClick={handleClickOutsideToDismiss} style={{ zIndex: currentModalZIndex, + perspective: 1200, }} tabIndex={-1} > @@ -339,7 +344,7 @@ export const ModalInternal = memo(function Modal({ = ({ children }) => { const index = p.indexOf(existingModal) return [...p.slice(0, index), ...p.slice(index + 1), existingModal] }) + ModalEventBus.dispatch("RE_PRESENT", { id: modalId }) } else { // NOTE: The props of the Command Modal are immutable, so we'll just take the store value and inject it. // There is no need to inject `overlay` props, this is rendered responsively based on ui changes. diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPPresetCard.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPPresetCard.tsx index 94275fc9a..7ccd20377 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPPresetCard.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPPresetCard.tsx @@ -9,7 +9,7 @@ interface MCPPresetCardProps { export const MCPPresetCard = ({ preset, onSelect }: MCPPresetCardProps) => { return ( -
+
{/* Icon */}
diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPPresetSelectionModal.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPPresetSelectionModal.tsx index ad41d7990..c4209dfcd 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPPresetSelectionModal.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPPresetSelectionModal.tsx @@ -22,7 +22,7 @@ export const MCPPresetSelectionModal = ({ ))} {/* Custom/Manual Configuration Card */} -
+