Skip to content

fix(tray): use positionForAnimation to prevent layout direction abrup…#1505

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Ivy233:fix-tray-layout-transition
Mar 17, 2026
Merged

fix(tray): use positionForAnimation to prevent layout direction abrup…#1505
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Ivy233:fix-tray-layout-transition

Conversation

@Ivy233
Copy link
Contributor

@Ivy233 Ivy233 commented Mar 17, 2026

…t change

When dock position changes from bottom to right/left, the tray layout direction should transition smoothly with animation instead of changing abruptly. This fix binds useColumnLayout to positionForAnimation instead of Panel.position, ensuring the layout direction updates after the position animation completes.

修复任务栏位置切换时系统托盘布局方向突变的问题。将托盘的布局方向
绑定到 positionForAnimation,使其与 dock 主面板保持同步,在位置动画
完成后才改变布局方向,避免切换过程中的视觉突变。

PMS: BUG-353295

Summary by Sourcery

Bug Fixes:

  • Ensure the tray layout orientation updates only after the dock position animation completes to prevent sudden layout direction changes during dock relocation.

…t change

When dock position changes from bottom to right/left, the tray layout
direction should transition smoothly with animation instead of changing
abruptly. This fix binds useColumnLayout to positionForAnimation instead
of Panel.position, ensuring the layout direction updates after the
position animation completes.

修复任务栏位置切换时系统托盘布局方向突变的问题。将托盘的布局方向
绑定到 positionForAnimation,使其与 dock 主面板保持同步,在位置动画
完成后才改变布局方向,避免切换过程中的视觉突变。

PMS: BUG-353295
@Ivy233 Ivy233 requested review from 18202781743 and BLumia March 17, 2026 06:06
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Binds the tray’s column/row layout decision to the animated dock position (positionForAnimation) instead of the raw Panel.position so the tray layout direction flips only after the dock position animation completes, avoiding abrupt layout changes when moving the dock between edges.

Sequence diagram for tray layout update using positionForAnimation

sequenceDiagram
    actor User
    participant DockUI
    participant Panel
    participant RootObject
    participant TrayApplet

    User->>DockUI: Change dock position (bottom -> left/right)
    DockUI->>Panel: Update position
    Panel->>RootObject: Start positionForAnimation transition
    loop During animation
        RootObject-->>TrayApplet: positionForAnimation changes gradually
        TrayApplet-->>TrayApplet: useColumnLayout = positionForAnimation % 2
        Note over TrayApplet: Layout direction kept consistent until edge flip
    end
    RootObject->>TrayApplet: Final positionForAnimation value
    TrayApplet-->>TrayApplet: useColumnLayout updates after animation completes
Loading

Class diagram for tray.qml layout direction binding change

classDiagram
    class Panel {
        int position
    }

    class RootObject {
        int positionForAnimation
    }

    class TrayApplet {
        int nextAppletSpacing
        bool useColumnLayout
        int dockOrder
        string quickpanelTrayItemPluginId
        var filterTrayPlugins
    }

    Panel o-- RootObject : rootObject
    RootObject o-- TrayApplet : controlsLayout

    class TrayApplet {
        +bool getUseColumnLayout()
    }

    TrayApplet : +getUseColumnLayout() = RootObject.positionForAnimation % 2
Loading

File-Level Changes

Change Details Files
Make tray layout orientation depend on the dock’s animated position state to avoid abrupt direction changes during dock repositioning.
  • Replaced the useColumnLayout binding source from Panel.position to Panel.rootObject.positionForAnimation.
  • Kept the modulo-based logic (using % 2) so the layout orientation still derives from the dock edge but now respects animation timing.
panels/dock/tray/package/tray.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

@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 left some high level feedback:

  • Using Panel.rootObject.positionForAnimation assumes rootObject is always available when this QML is instantiated; consider guarding against a null rootObject or documenting the expected initialization order to avoid potential runtime errors.
  • If positionForAnimation can take intermediate values during animation (e.g., non-integers), confirm that using % 2 still yields the intended boolean layout state, or consider normalizing/rounding the value before applying the modulo.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `Panel.rootObject.positionForAnimation` assumes `rootObject` is always available when this QML is instantiated; consider guarding against a null `rootObject` or documenting the expected initialization order to avoid potential runtime errors.
- If `positionForAnimation` can take intermediate values during animation (e.g., non-integers), confirm that using `% 2` still yields the intended boolean layout state, or consider normalizing/rounding the value before applying the modulo.

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.

@deepin-ci-robot
Copy link

deepin pr auto review

这份代码修改涉及 QML 文件 tray.qml,主要更改了 useColumnLayout 属性的取值逻辑。以下是对该 diff 的详细审查和改进建议:

1. 语法逻辑审查

  • 当前逻辑
    • 修改前property bool useColumnLayout: Panel.position % 2
      • 这里的逻辑是直接读取 Panel 的静态位置属性。通常在 Dock 栏中,位置可能被定义为 0(左), 1(上), 2(右), 3(下) 等。% 2(取模)操作意味着当位置为 1 或 3(奇数)时,useColumnLayout 为真;当位置为 0 或 2(偶数)时,为假。
    • 修改后property bool useColumnLayout: Panel.rootObject.positionForAnimation % 2
      • 这里改为读取 Panel.rootObject 下的 positionForAnimation 属性。
  • 潜在问题
    • 属性来源变更:从 Panel 变更为 Panel.rootObject。这意味着代码现在依赖于 Panel 内部的一个对象 (rootObject)。如果 rootObject 未正确初始化、被销毁或重构,此属性绑定将失效,可能导致运行时错误或布局错误。
    • 属性含义差异position 通常代表当前的物理位置(如底部、左侧),而 positionForAnimation 听起来更像是一个用于动画过渡的临时状态或目标位置。如果动画正在进行中,positionForAnimation 可能与 Panel 的实际物理位置不一致,导致布局逻辑在动画过程中发生意外的翻转(例如从横排瞬间变成竖排),造成 UI 闪烁或错位。
    • 耦合度增加:直接访问 Panel.rootObject 破坏了封装性,使得 tray.qmlPanel 的内部实现细节紧密耦合。

2. 代码质量审查

  • 可读性
    • Panel.position % 2 是一种简写,虽然紧凑,但如果不清楚 position 的枚举定义,很难一眼看出是判断“水平”还是“垂直”。
    • Panel.rootObject.positionForAnimation % 2 更长且引入了动画相关的上下文,增加了理解难度。
  • 维护性
    • 如果 Panel 的内部结构发生变化(例如 rootObject 重命名),这行代码需要同步修改。
    • 如果 positionForAnimation 的逻辑发生变化(例如不再遵循 0-3 的奇偶规律),这里的逻辑也会失效。

3. 代码性能审查

  • 属性绑定开销
    • QML 的属性绑定机制会在依赖项变化时重新求值。
    • 如果 positionForAnimation 在动画过程中频繁变化(例如每一帧都在变),那么 useColumnLayout 也会频繁重新求值。这会触发 Tray 容器及其子元素的重新布局。
    • 性能风险:在动画期间频繁触发布局计算是非常昂贵的操作,可能导致动画掉帧。
    • 对比Panel.position 通常只在 Dock 位置改变(如用户从底部拖到左侧)时变化一次,开销极小。

4. 代码安全审查

  • 空指针风险Panel.rootObject 可能为 nullundefined,特别是在组件初始化阶段或销毁阶段。访问其属性会导致程序崩溃或报错。
  • 类型安全:没有检查 positionForAnimation 是否确实是整数类型。

5. 改进建议

建议 1:明确意图并解耦(推荐)
如果目的是根据 Dock 的实际物理位置来决定布局,应该继续使用代表实际状态的属性,而不是动画状态。建议在 Panel 中提供一个明确的、类型安全的 API,而不是让子组件去猜测内部属性。

// 假设 Panel 暴露了更清晰的接口
property bool useColumnLayout: Panel.isVertical

或者如果必须使用奇偶判断:

property bool useColumnLayout: Panel.dockPosition === Dock.Left || Panel.dockPosition === Dock.Right

建议 2:防御性编程(如果必须使用当前逻辑)
如果必须使用 positionForAnimation(例如为了在动画过程中实时更新布局),请务必增加安全检查,并考虑添加注释说明原因。

// 注意:使用 positionForAnimation 可能导致动画期间频繁触发布局更新
property bool useColumnLayout: Panel.rootObject ? (Panel.rootObject.positionForAnimation % 2 !== 0) : false

建议 3:性能优化
如果是为了解决动画过程中的布局同步问题,且发现性能有问题,可以考虑以下方案:

  1. 节流:不要在每一帧都更新布局。
  2. 动画结束后更新:仅在动画开始前和结束后更新布局,动画过程中保持布局状态不变(除非这是特定的 UI 效果需求)。

总结

不建议直接合并当前的修改。
原因:将布局逻辑绑定到 positionForAnimation 极有可能引入性能问题(动画卡顿)和逻辑错误(动画过程中的 UI 闪烁),同时增加了组件间的耦合度。

建议方案:除非有特殊的动画效果需求(即布局需要随着位置动画实时变化),否则应回退到使用 Panel.position 或更明确的 Panel.isVertical 属性,以保证性能和逻辑的稳定性。如果确实需要跟随动画,请务必添加空值检查并评估性能影响。

@Ivy233
Copy link
Contributor Author

Ivy233 commented Mar 17, 2026

/forcemerge

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia, Ivy233

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

@deepin-bot
Copy link

deepin-bot bot commented Mar 17, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 5c6828b into linuxdeepin:master Mar 17, 2026
9 of 12 checks passed
@Ivy233 Ivy233 deleted the fix-tray-layout-transition branch March 17, 2026 06:09
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.

4 participants