diff --git a/src/pages/Container/Map/components/Content/index.js b/src/pages/Container/Map/components/Content/index.js index c11324e..c080ae6 100644 --- a/src/pages/Container/Map/components/Content/index.js +++ b/src/pages/Container/Map/components/Content/index.js @@ -132,6 +132,7 @@ function Content(props) { )} {isLeftVisible && ( { - // 设置元素到初始隐藏位置(侧边外部) + // 先设置到初始隐藏位置 controls.set({ x: getInitialX(), opacity: 0, }); - // 然后触发进入动画(从侧边滑入) requestAnimationFrame(() => { + // 然后执行进入动画 controls.start({ x: 0, // 移动到正常位置 opacity: 1, // 淡入 @@ -182,6 +184,9 @@ export function useContentAnimation({ } else { // ==================== 折叠逻辑 ==================== + // 标记开始手动处理折叠/展开动画(阻止 useEffect 干预) + isManualCollapseAnimating.current = true; + // 执行离开动画(滑到侧边并淡出) controls.start({ x: getInitialX(), // 移动到侧边外部 @@ -194,6 +199,9 @@ export function useContentAnimation({ // 2. 更新折叠状态为 true setCollapseState(true); + + // 3. 清除手动处理标记 + isManualCollapseAnimating.current = false; }); } }; @@ -206,6 +214,11 @@ export function useContentAnimation({ return; } + // 如果正在手动处理折叠/展开动画,不执行 useEffect 逻辑 + if (isManualCollapseAnimating.current) { + return; + } + // ==================== 场景 1:纯地图模式(最高优先级)==================== if (isPureMap) { // 如果元素当前可见,执行离开动画并隐藏 @@ -301,8 +314,9 @@ export function useContentAnimation({ }); } - // ----- 情况 C:从隐藏状态切换回来(退出纯地图模式或展开)----- - else if (!isVisible) { + // ----- 情况 C:从隐藏状态切换回来(退出纯地图模式)----- + // 注意:展开操作由 handleCollapse 处理,不在这里处理 + else if (!isVisible && !isCollapsed) { // 1. 显示元素 setIsVisible(true);