Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export function generateTimelineObj(
}
const container = target?.pixiContainer;
let animateInstance: ReturnType<typeof popmotion.animate> | null = null;
// 只有有 duration 的时候才有动画
if (duration > 0) {
// 只有有 duration 且 timeline 长度大于 1 的时候才有动画
if (duration > 0 && timeline.length > 1) {

Choose a reason for hiding this comment

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

medium

这个条件很好地解决了只有一个关键帧时创建动画的问题。然而,我注意到一个相关的边界情况:当 timeline 数组为空时,此函数将在第 64 行因试图解构 undefined 而崩溃。虽然这可能超出了本次修复的范围,但为了增强函数的健壮性,建议在函数开头添加一个检查来处理空时间轴的情况,例如:

if (timeline.length === 0) {
  // 返回一个无操作的动画对象或直接返回
  return {
    setStartState: () => {},
    setEndState: () => {},
    tickerFunc: () => {},
    getEndStateEffect: () => ({}),
    forceStopWithoutSetEndState: () => {},
  };
}

animateInstance = popmotion.animate({
to: values,
offset: times,
Expand Down