fix: exit animation target on ListView (#210)

This commit is contained in:
Chrys
2026-01-04 16:33:35 +08:00
committed by GitHub
parent 17216b7f1f
commit cbbdfc3087
2 changed files with 11 additions and 2 deletions

View File

@@ -193,6 +193,7 @@ const PhotoCard = ({ photo }: { photo: PhotoManifest }) => {
className="relative w-full shrink-0 cursor-pointer overflow-hidden lg:h-full lg:w-56"
role="button"
tabIndex={0}
data-photo-id={photo.id}
style={
// 移动端:根据宽高比计算高度
{

View File

@@ -69,7 +69,11 @@ export const usePhotoViewerTransitions = ({
const resolveTriggerElement = useCallback((): HTMLElement | null => {
if (!currentPhoto) return null
if (triggerElement && triggerElement.isConnected) {
const isElementForCurrentPhoto = (el: HTMLElement) => {
return el.dataset.photoId === currentPhoto.id
}
if (triggerElement && triggerElement.isConnected && isElementForCurrentPhoto(triggerElement)) {
cachedTriggerRef.current = triggerElement
return triggerElement
}
@@ -82,7 +86,11 @@ export const usePhotoViewerTransitions = ({
return liveTriggerEl
}
if (cachedTriggerRef.current && cachedTriggerRef.current.isConnected) {
if (
cachedTriggerRef.current &&
cachedTriggerRef.current.isConnected &&
isElementForCurrentPhoto(cachedTriggerRef.current)
) {
return cachedTriggerRef.current
}