Skip to content

fix: 弹出窗口因为浏览器窗口变化从bottomLeft对齐到topRight对齐时,箭头对齐错误 #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/hooks/useAlign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ export default function useAlign(
const [popupPoint, targetPoint] = placementInfo.points || [];
const targetPoints = splitPoints(targetPoint);
const popupPoints = splitPoints(popupPoint);
let tmpTargetPoints = targetPoints;
let tmpPopupPoints = popupPoints;

const targetAlignPoint = getAlignPoint(targetRect, targetPoints);
const popupAlignPoint = getAlignPoint(popupRect, popupPoints);
Expand Down Expand Up @@ -399,6 +401,11 @@ export default function useAlign(
}
syncNextPopupPosition();

function updateTmpPopupPointsAndTmpTargetPoints() {
tmpPopupPoints = splitPoints(nextAlignInfo.points[0]);
tmpTargetPoints = splitPoints(nextAlignInfo.points[1]);
}

Comment on lines +404 to +408
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

将更新临时对齐点的逻辑封装成函数,减少代码重复

新增的 updateTmpPopupPointsAndTmpTargetPoints() 函数封装了更新临时对齐点的逻辑,避免了重复代码,提高了代码的复用性和可读性。

// >>>>>>>>>> Top & Bottom
const needAdjustY = supportAdjust(adjustY);

Expand Down Expand Up @@ -443,9 +450,10 @@ export default function useAlign(
popupOffsetY = -popupOffsetY;

nextAlignInfo.points = [
reversePoints(popupPoints, 0),
reversePoints(targetPoints, 0),
reversePoints(tmpPopupPoints, 0),
reversePoints(tmpTargetPoints, 0),
];
updateTmpPopupPointsAndTmpTargetPoints();
} else {
prevFlipRef.current.bt = false;
}
Expand Down Expand Up @@ -489,9 +497,10 @@ export default function useAlign(
popupOffsetY = -popupOffsetY;

nextAlignInfo.points = [
reversePoints(popupPoints, 0),
reversePoints(targetPoints, 0),
reversePoints(tmpPopupPoints, 0),
reversePoints(tmpTargetPoints, 0),
];
updateTmpPopupPointsAndTmpTargetPoints();
} else {
prevFlipRef.current.tb = false;
}
Expand Down Expand Up @@ -542,9 +551,10 @@ export default function useAlign(
popupOffsetX = -popupOffsetX;

nextAlignInfo.points = [
reversePoints(popupPoints, 1),
reversePoints(targetPoints, 1),
reversePoints(tmpPopupPoints, 1),
reversePoints(tmpTargetPoints, 1),
];
updateTmpPopupPointsAndTmpTargetPoints();
} else {
prevFlipRef.current.rl = false;
}
Expand Down Expand Up @@ -588,9 +598,10 @@ export default function useAlign(
popupOffsetX = -popupOffsetX;

nextAlignInfo.points = [
reversePoints(popupPoints, 1),
reversePoints(targetPoints, 1),
reversePoints(tmpPopupPoints, 1),
reversePoints(tmpTargetPoints, 1),
];
updateTmpPopupPointsAndTmpTargetPoints();
} else {
prevFlipRef.current.lr = false;
}
Expand Down