Skip to content

fix: fix icon scale reset during attention animation#1588

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-shuibowen
May 7, 2026
Merged

fix: fix icon scale reset during attention animation#1588
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-shuibowen

Conversation

@wjyrich
Copy link
Copy Markdown
Contributor

@wjyrich wjyrich commented May 7, 2026

Use Qt.callLater to safely reset icon scale when attention animation deactivates. This prevents potential race conditions or binding loops that could occur when directly resetting the scale property in the onActiveChanged handler.

Log: Fixed icon scale reset behavior during attention animation

Influence:

  1. Test attention animation activation and deactivation sequence
  2. Verify icon scale correctly resets to 1.0 after animation ends
  3. Ensure no visual glitches or delayed scale updates
  4. Test dragging behavior does not interfere with scale reset

fix: 修复注意动画期间图标缩放重置问题

在注意动画停用时使用 Qt.callLater 安全地重置图标缩放。避免在
onActiveChanged 处理器中直接重置 scale 属性时可能出现的竞态条件或绑定循
环问题。

Log: 修复注意动画过程中的图标缩放重置逻辑

Influence:

  1. 测试注意动画的激活和停用序列
  2. 验证动画结束后图标缩放正确重置为 1.0
  3. 确保没有视觉异常或缩放更新延迟
  4. 测试拖动行为不影响缩放重置

PMS: TASK-389209

Summary by Sourcery

Bug Fixes:

  • Fix icon scale not reliably resetting to 1.0 when the attention animation deactivates, especially during interactions like dragging.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR adjusts the attention animation behavior for dock taskmanager app items by deferring the reset of the icon’s scale until after the attention animation deactivates, using Qt.callLater to avoid race conditions or binding loops.

Sequence diagram for attention animation icon scale reset

sequenceDiagram
    actor User
    participant DockPanel
    participant AppItem
    participant AttentionAnimation
    participant Icon
    participant Qt

    User->>DockPanel: click or event triggers attention
    DockPanel->>AppItem: set attention = true
    AppItem->>AttentionAnimation: active = true
    AttentionAnimation-->>Icon: animate scale > 1.0

    User->>DockPanel: condition cleared
    DockPanel->>AppItem: set attention = false
    AppItem->>AttentionAnimation: active = false
    AttentionAnimation->>AppItem: onActiveChanged(active = false)

    AppItem->>Qt: callLater(resetIconScale)
    Qt-->>AppItem: invoke resetIconScale()
    AppItem->>Icon: set scale = 1.0
Loading

Class diagram for AppItem attention animation and icon scale reset

classDiagram
    class AppItem {
        bool attention
        bool isDragging
        void onAttentionAnimationActiveChanged(bool active)
    }

    class AttentionAnimation {
        bool active
        void onActiveChanged(bool active)
    }

    class Icon {
        float scale
    }

    class QtHelper {
        void callLater(function callback)
    }

    AppItem --> AttentionAnimation : controls active
    AttentionAnimation --> Icon : animates scale
    AppItem --> Icon : resets scale to 1_0
    AppItem --> QtHelper : uses callLater

    %% Implementation detail
    AppItem : onAttentionAnimationActiveChanged(active)
    AppItem :  if active == false
    AppItem :    Qt.callLater(resetIconScale)
    AppItem : resetIconScale()
    AppItem :  icon.scale = 1_0
Loading

File-Level Changes

Change Details Files
Defer icon scale reset until after attention animation deactivation using Qt.callLater to avoid race conditions.
  • Wrap the icon.scale reset logic inside Qt.callLater in the attention animation’s onActiveChanged handler
  • Ensure the icon scale is reset to 1.0 only when the attention animation becomes inactive, avoiding direct property changes during signal handling
panels/dock/taskmanager/package/AppItem.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Using Qt.callLater here avoids the immediate binding issue, but it also introduces a window where the animation could become active again before the callback runs; consider re-checking active (or root.attention && ...) inside the callback before resetting icon.scale to avoid resetting while the animation is active again.
  • To make the intent clearer for future maintainers, consider adding a brief comment above this Qt.callLater usage explaining that it is specifically to avoid binding loops/ordering issues when mutating icon.scale from onActiveChanged.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using Qt.callLater here avoids the immediate binding issue, but it also introduces a window where the animation could become active again before the callback runs; consider re-checking `active` (or `root.attention && ...`) inside the callback before resetting `icon.scale` to avoid resetting while the animation is active again.
- To make the intent clearer for future maintainers, consider adding a brief comment above this Qt.callLater usage explaining that it is specifically to avoid binding loops/ordering issues when mutating `icon.scale` from `onActiveChanged`.

## Individual Comments

### Comment 1
<location path="panels/dock/taskmanager/package/AppItem.qml" line_range="308" />
<code_context>
             onActiveChanged: {
                 if (!active) {
-                    icon.scale = 1.0
+                    Qt.callLater(function() {
+                        icon.scale = 1.0
+                    })
                 }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Guard against `icon` being invalid when the deferred callback runs

Because `Qt.callLater` runs asynchronously, `icon` may no longer exist by the time the callback executes (e.g., if the item is removed or the component is reloaded). Add a null check inside the callback (e.g., `if (icon)`) before accessing `icon.scale` to avoid runtime errors.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread panels/dock/taskmanager/package/AppItem.qml
Use Qt.callLater to safely reset icon scale when attention animation
deactivates. This prevents potential race conditions or binding loops
that could occur when directly resetting the scale property in the
onActiveChanged handler.

Log: Fixed icon scale reset behavior during attention animation

Influence:
1. Test attention animation activation and deactivation sequence
2. Verify icon scale correctly resets to 1.0 after animation ends
3. Ensure no visual glitches or delayed scale updates
4. Test dragging behavior does not interfere with scale reset

fix: 修复注意动画期间图标缩放重置问题

在注意动画停用时使用 Qt.callLater 安全地重置图标缩放。避免在
onActiveChanged 处理器中直接重置 scale 属性时可能出现的竞态条件或绑定循
环问题。

Log: 修复注意动画过程中的图标缩放重置逻辑

Influence:
1. 测试注意动画的激活和停用序列
2. 验证动画结束后图标缩放正确重置为 1.0
3. 确保没有视觉异常或缩放更新延迟
4. 测试拖动行为不影响缩放重置

PMS: TASK-389209
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段,针对这段 git diff 的代码审查如下:

1. 代码逻辑与语法分析

修改内容:
BehavioronActiveChanged 事件处理中,将直接赋值 icon.scale = 1.0 修改为通过 Qt.callLater 异步调用。

逻辑分析:

  • 原代码问题:当 active 变为 false 时,代码立即将 icon.scale 重置为 1.0。在 QML 的属性绑定机制中,如果 Behavior 正在处理动画(即 scale 属性正在被动画驱动),直接在 onActiveChanged 中立即修改目标属性可能会导致冲突。具体来说,动画可能尚未完全结束或清理,此时强制重置属性值可能会打断动画流,或者在某些边缘情况下(如快速切换状态)导致属性绑定循环或状态不一致。
  • 修改后逻辑:使用 Qt.callLater 将重置操作推迟到当前事件循环处理完毕后执行。这确保了当 active 状态改变时,任何正在进行的动画或属性更新逻辑有机会先完成清理工作,然后再应用 scale = 1.0。这是一种避免状态竞争的有效手段。

2. 代码质量

  • 优点:修改非常简洁,使用了 QML 提供的标准 API Qt.callLater 来解决时序问题,提高了代码的健壮性。这种“异步重置”的模式在处理 UI 状态恢复时是很好的实践。
  • 建议:虽然代码很短,但建议添加注释解释为什么需要在这里使用 Qt.callLater,以便后续维护者理解这是为了解决动画冲突或时序问题,而非随意添加的延迟。

3. 代码性能

  • 影响Qt.callLater 的开销极小,它只是将函数加入事件队列等待下一次循环处理。相比于直接赋值,它不会造成明显的性能损耗。
  • 收益:避免了潜在的属性强制更新导致的动画重新计算或渲染抖动,从视觉流畅度的角度看,这实际上是提升了性能表现。

4. 代码安全

  • 稳定性:该修改显著提高了 UI 状态的稳定性。在原代码中,如果 Behavior 依赖于 active 属性来驱动动画,直接修改 scale 可能会导致动画系统内部状态异常(例如,动画未停止就被覆盖)。使用 Qt.callLater 隔离了状态变更和属性重置,降低了崩溃或 UI 卡死的概率。

总结与改进建议

这段代码修改是正确且必要的,它解决了 QML 动画属性绑定中常见的时序冲突问题。

改进建议:

为了提高代码的可读性和可维护性,建议添加简短的注释说明原因。

onActiveChanged: {
    if (!active) {
        // 使用 Qt.callLater 延迟执行,避免与正在进行的动画产生冲突
        Qt.callLater(function() {
            icon.scale = 1.0
        })
    }
}

或者,如果项目风格允许,可以使用箭头函数(如果 QML 环境支持 ES6+ 语法)使代码更紧凑:

onActiveChanged: {
    if (!active) {
        // 延迟重置缩放,确保动画流程结束
        Qt.callLater(() => icon.scale = 1.0)
    }
}

总体而言,这是一个高质量的 Bug 修复或优化提交。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wjyrich

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wjyrich
Copy link
Copy Markdown
Contributor Author

wjyrich commented May 7, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented May 7, 2026

This pr force merged! (status: behind)

@deepin-bot deepin-bot Bot merged commit c5c3749 into linuxdeepin:master May 7, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants