fix(avocet): reset card element state when new item loads to clear previous animation inline styles
This commit is contained in:
parent
e01f743c39
commit
fb1ce89244
3 changed files with 24 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ vi.mock('../composables/useCardAnimation', () => ({
|
||||||
snapBack: vi.fn(),
|
snapBack: vi.fn(),
|
||||||
animateDismiss: vi.fn(),
|
animateDismiss: vi.fn(),
|
||||||
updateAura: vi.fn(),
|
updateAura: vi.fn(),
|
||||||
|
reset: vi.fn(),
|
||||||
})),
|
})),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,12 +54,18 @@ const motion = useMotion()
|
||||||
const cardEl = ref<HTMLElement | null>(null)
|
const cardEl = ref<HTMLElement | null>(null)
|
||||||
const isExpanded = ref(false)
|
const isExpanded = ref(false)
|
||||||
|
|
||||||
const { pickup, setDragPosition, snapBack, animateDismiss, updateAura } = useCardAnimation(cardEl, motion)
|
const { pickup, setDragPosition, snapBack, animateDismiss, updateAura, reset } = useCardAnimation(cardEl, motion)
|
||||||
|
|
||||||
watch(() => props.dismissType, (type) => {
|
watch(() => props.dismissType, (type) => {
|
||||||
if (type) animateDismiss(type)
|
if (type) animateDismiss(type)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// When a new card loads into the same element, clear any inline styles left by the previous animation
|
||||||
|
watch(() => props.item.id, () => {
|
||||||
|
reset()
|
||||||
|
isExpanded.value = false
|
||||||
|
})
|
||||||
|
|
||||||
// Toss gesture state
|
// Toss gesture state
|
||||||
const isHeld = ref(false)
|
const isHeld = ref(false)
|
||||||
const pickupX = ref(0)
|
const pickupX = ref(0)
|
||||||
|
|
|
||||||
|
|
@ -80,5 +80,20 @@ export function useCardAnimation(
|
||||||
utils.set(cardEl.value, { background: color })
|
utils.set(cardEl.value, { background: color })
|
||||||
}
|
}
|
||||||
|
|
||||||
return { pickup, setDragPosition, snapBack, animateDismiss, updateAura }
|
function reset() {
|
||||||
|
if (!cardEl.value) return
|
||||||
|
// Instantly restore initial card state — called when a new item loads into the same element
|
||||||
|
utils.set(cardEl.value, {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
scale: 1,
|
||||||
|
opacity: 1,
|
||||||
|
rotate: 0,
|
||||||
|
borderRadius: CARD_RADIUS,
|
||||||
|
background: 'transparent',
|
||||||
|
filter: 'none',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return { pickup, setDragPosition, snapBack, animateDismiss, updateAura, reset }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue